Fri, 11 Aug 2017 19:50:06 +0200
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
--- a/Documentation/Help/source.qhp Fri Aug 11 17:50:49 2017 +0200 +++ b/Documentation/Help/source.qhp Fri Aug 11 19:50:06 2017 +0200 @@ -11020,6 +11020,7 @@ <keyword name="PreviewProcessingThread.__convertReSTDocutils" id="PreviewProcessingThread.__convertReSTDocutils" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.__convertReSTDocutils" /> <keyword name="PreviewProcessingThread.__convertReSTSphinx" id="PreviewProcessingThread.__convertReSTSphinx" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.__convertReSTSphinx" /> <keyword name="PreviewProcessingThread.__getHtml" id="PreviewProcessingThread.__getHtml" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.__getHtml" /> + <keyword name="PreviewProcessingThread.__processRootPath" id="PreviewProcessingThread.__processRootPath" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.__processRootPath" /> <keyword name="PreviewProcessingThread.__processSSI" id="PreviewProcessingThread.__processSSI" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.__processSSI" /> <keyword name="PreviewProcessingThread.process" id="PreviewProcessingThread.process" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.process" /> <keyword name="PreviewProcessingThread.run" id="PreviewProcessingThread.run" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewProcessingThread.run" />
--- a/Documentation/Source/eric6.UI.Previewers.PreviewerHTML.html Fri Aug 11 17:50:49 2017 +0200 +++ b/Documentation/Source/eric6.UI.Previewers.PreviewerHTML.html Fri Aug 11 19:50:06 2017 +0200 @@ -90,6 +90,9 @@ <td><a href="#PreviewProcessingThread.__getHtml">__getHtml</a></td> <td>Private method to process the given text depending upon the given language.</td> </tr><tr> +<td><a href="#PreviewProcessingThread.__processRootPath">__processRootPath</a></td> +<td>Private method to adjust absolute references to the given root path.</td> +</tr><tr> <td><a href="#PreviewProcessingThread.__processSSI">__processSSI</a></td> <td>Private method to process the given text for SSI statements.</td> </tr><tr> @@ -237,6 +240,29 @@ <dd> processed HTML text (string) </dd> +</dl><a NAME="PreviewProcessingThread.__processRootPath" ID="PreviewProcessingThread.__processRootPath"></a> +<h4>PreviewProcessingThread.__processRootPath</h4> +<b>__processRootPath</b>(<i>txt, root</i>) +<p> + Private method to adjust absolute references to the given root path. +</p><dl> +<dt><i>txt</i> (str)</dt> +<dd> +text to be processed +</dd><dt><i>root</i> (str)</dt> +<dd> +directory of the document root +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +processed HTML +</dd> +</dl><dl> +<dt>Return Type:</dt> +<dd> +str +</dd> </dl><a NAME="PreviewProcessingThread.__processSSI" ID="PreviewProcessingThread.__processSSI"></a> <h4>PreviewProcessingThread.__processSSI</h4> <b>__processSSI</b>(<i>txt, filename, root</i>)
--- 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.