diff -r f3d2172d663e -r b3cc692e3bfe UI/Previewers/PreviewerHTML.py --- a/UI/Previewers/PreviewerHTML.py Fri Aug 11 17:50:49 2017 +0200 +++ b/UI/Previewers/PreviewerHTML.py Fri Aug 11 19:50:06 2017 +0200 @@ -468,9 +468,10 @@ """ if language == "HTML": if ssiEnabled: - return self.__processSSI(text, filePath, rootPath) + html = self.__processSSI(text, filePath, rootPath) else: - return text + html = text + return self.__processRootPath(html, rootPath) elif language == "Markdown": return self.__convertMarkdown(text, convertNewLineToBreak, markdownHtmlFormat) @@ -527,6 +528,40 @@ return txt + def __processRootPath(self, txt, root): + """ + Private method to adjust absolute references to the given root path. + + @param txt text to be processed + @type str + @param root directory of the document root + @type str + @return processed HTML + @rtype str + """ + if not root: + return txt + + root = Utilities.fromNativeSeparators(root) + if not root.endswith("/"): + root += "/" + rootLen = len(root) + + refRe = re.compile( + r"""(href|src)=[\\"']/([^\\"']+)[\\"']""", + re.IGNORECASE) + pos = 0 + while True: + refMatch = refRe.search(txt, pos) + if refMatch is None: + break + + txt = (txt[:refMatch.start(0)] + refMatch.group(1) + '="' + root + + refMatch.group(2) + '"' + txt[refMatch.end(0):]) + pos = refMatch.end(0) + rootLen + + return txt + def __convertReST(self, text, useSphinx, restDocutilsHtmlFormat): """ Private method to convert ReST text into HTML.