[O] Use json enoding

This commit is contained in:
Hykilpikonna
2021-11-27 21:11:16 -05:00
parent 3519fb015e
commit 647c59f13f
2 changed files with 7 additions and 7 deletions
+4 -3
View File
@@ -1,4 +1,5 @@
import base64 import base64
import json
import os.path import os.path
import webbrowser import webbrowser
from pathlib import Path from pathlib import Path
@@ -68,11 +69,11 @@ def serve_report() -> None:
:return: HTML report :return: HTML report
""" """
# Generate markdown report and b64 encode it (this is to prevent interpretation by JS code) # Generate markdown report and JSON encode it (which works as JS code! amazing
md_b64 = base64.b64encode(generate_report().encode('utf-8')).decode('utf-8') md_json = json.dumps({'content': generate_report()})
# Inject into HTML # Inject into HTML
html = read(str(src_dir.joinpath('report_page.html'))) \ html = read(str(src_dir.joinpath('report_page.html'))) \
.replace('{{markdown}}', md_b64) .replace('`{{markdown}}`', md_json)
# Return # Return
return html return html
+3 -4
View File
@@ -17,11 +17,10 @@
<script> <script>
// Python will inject the markdown code here. // Python will inject the markdown code here.
markdown = ` markdown = `{{markdown}}`
{{markdown}}
`
document.getElementById('content').innerHTML = document.getElementById('content').innerHTML =
marked.parse(atob(markdown)); marked.parse(markdown.content);
// Make images clickable // Make images clickable
// Improved from: https://stackoverflow.com/a/50430187/7346633 // Improved from: https://stackoverflow.com/a/50430187/7346633