Commit 0d0fe794 authored by GN's avatar GN Committed by Christian Hergert

Markdown preview: HTML-escape inline Markdown source and move to (hidden) DOM...

Markdown preview: HTML-escape inline Markdown source and move to (hidden) DOM element to properly encapsulate.
parent 4e82af94
......@@ -955,3 +955,7 @@
.markdown-body .pl-12 {
padding-left: 128px!important;
}
.markdown-source {
display: none;
}
......@@ -21,8 +21,8 @@
import builtins
import gi
import html
import io
import json
import locale
import os
import shutil
......@@ -434,25 +434,28 @@ class HtmlPreviewPage(Ide.Page):
self.webview = None
def get_markdown(self, text):
params = (HtmlPreviewData.MARKDOWN_CSS.get_data().decode('UTF-8'),
json.dumps(text),
HtmlPreviewData.MARKED_JS.get_data().decode('UTF-8'),
HtmlPreviewData.MARKDOWN_VIEW_JS.get_data().decode('UTF-8'))
return """
markdown_css = HtmlPreviewData.MARKDOWN_CSS.get_data().decode('UTF-8')
escaped_markdown = html.escape(text)
marked_js = HtmlPreviewData.MARKED_JS.get_data().decode('UTF-8')
markdown_view_js = HtmlPreviewData.MARKDOWN_VIEW_JS.get_data().decode('UTF-8')
template = """
<html>
<head>
<style>%s</style>
<script>var str=%s;</script>
<script>%s</script>
<script>%s</script>
<style>{markdown_css}</style>
<script>{marked_js}</script>
<script>{markdown_view_js}</script>
</head>
<body onload="preview()">
<div class="markdown-body" id="preview">
<div id="markdown-source">{escaped_markdown}</div>
</div>
</body>
</html>
""" % params
"""
return template.format(markdown_css=markdown_css,
escaped_markdown=escaped_markdown,
marked_js=marked_js,
markdown_view_js=markdown_view_js)
def get_rst(self, text, path):
return publish_string(text,
......
......@@ -10,5 +10,5 @@ marked.setOptions({
});
function preview(){
document.getElementById('preview').innerHTML = marked(str);
document.getElementById('preview').innerHTML = marked(document.getElementById('markdown-source').childNodes[0].nodeValue);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment