[O] Catch errors in markdown formatting

This commit is contained in:
Hykilpikonna
2021-11-27 21:39:44 -05:00
parent 647c59f13f
commit ecfe76a231
2 changed files with 55 additions and 20 deletions
+11 -1
View File
@@ -1,6 +1,7 @@
import base64 import base64
import json import json
import os.path import os.path
import traceback
import webbrowser import webbrowser
from pathlib import Path from pathlib import Path
@@ -22,12 +23,14 @@ def generate_report() -> str:
# Load markdown # Load markdown
md = read(str(src_dir.joinpath('report_document.md'))).replace('\r\n', '\n').split('\n') md = read(str(src_dir.joinpath('report_document.md'))).replace('\r\n', '\n').split('\n')
# Process @include statements # Process line by line
for i in range(len(md)): for i in range(len(md)):
line = md[i] line = md[i]
if not line.startswith('@include'): if not line.startswith('@include'):
continue continue
# Process @include statements
try:
path = line[line.index('`') + 1:] path = line[line.index('`') + 1:]
path = path[:path.index('`')] path = path[:path.index('`')]
md[i] = read(REPORT_DIR + path) md[i] = read(REPORT_DIR + path)
@@ -50,6 +53,13 @@ def generate_report() -> str:
lines = [lines[ln] for ln in range(len(lines)) if ln in args] lines = [lines[ln] for ln in range(len(lines)) if ln in args]
md[i] = '\n'.join(lines) md[i] = '\n'.join(lines)
# Handle errors. (It prompts "too broad an exception clause" but I actually need to catch
# every possible exception.)
except Exception as e:
md[i] = f"<pre class=\"error\">" \
f"\nInvalid @include statement. \n{traceback.format_exc()}" \
f"</pre>"
return '\n'.join(md) return '\n'.join(md)
+25
View File
@@ -42,6 +42,31 @@ span.highlight {
background-color: beige; background-color: beige;
} }
pre.error {
background-color: #ffeef2;
color: #ff5b74;
padding: 0.8em 0.8em 0.8em 1em;
}
/*blockquote {*/
/* position: relative;*/
/* margin: 0 0 1.1em 0;*/
/* padding: 0.8em 0.8em 0.8em 1em;*/
/* color: gray;*/
/*}*/
/*blockquote:before {*/
/* content: "";*/
/* display: block;*/
/* position: absolute;*/
/* top: 0;*/
/* bottom: 0;*/
/* left: 0;*/
/* width: 4px;*/
/* border-radius: 8px;*/
/* background: gray;*/
/*}*/
table { table {
border-collapse: collapse; border-collapse: collapse;
border: 2px solid #5b3300; border: 2px solid #5b3300;