From 077d78c3a94185450c5505d49bbdb5712fef080f Mon Sep 17 00:00:00 2001 From: Jason Fox Date: Sun, 13 Oct 2019 22:32:03 +0200 Subject: [PATCH] Improve image file path processing Amend relative URLs for PDF processing --- resource/amend-uri.js | 36 ++++++++++++++++++++++ resource/antlib.xml | 29 ++++++++++++----- resource/{relative.js => relative-path.js} | 0 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 resource/amend-uri.js rename resource/{relative.js => relative-path.js} (100%) diff --git a/resource/amend-uri.js b/resource/amend-uri.js new file mode 100644 index 0000000..3cd6c83 --- /dev/null +++ b/resource/amend-uri.js @@ -0,0 +1,36 @@ +/* + * This file is part of the DITA Passthrough Plug-in project. + * See the accompanying LICENSE file for applicable licenses. + */ + +// +// Converts a value to relative path +// +// @param path - The relative path of the file +// @param href - The relative path of the image +// + +var path = attributes.get("path"); +var href = attributes.get("href"); + +var hrefElements = href.split('/'); +var pathElements = path.split('/'); +var fullPath = []; + +for each (var elem in pathElements) { + if (elem !== ''){ + fullPath.push(elem) + } +} + + +for each (var elem in hrefElements) { + if (elem === ''){ + } else if (elem === '..'){ + fullPath.pop() + } else { + fullPath.push(elem) + } +} + +project.setProperty(attributes.get("to"), fullPath.join('/')); \ No newline at end of file diff --git a/resource/antlib.xml b/resource/antlib.xml index 28af128..b1886f8 100644 --- a/resource/antlib.xml +++ b/resource/antlib.xml @@ -6,16 +6,28 @@ - + + + + + + + +