[O] Catch errors in markdown formatting
This commit is contained in:
+11
-1
@@ -1,6 +1,7 @@
|
||||
import base64
|
||||
import json
|
||||
import os.path
|
||||
import traceback
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
|
||||
@@ -22,12 +23,14 @@ def generate_report() -> str:
|
||||
# Load markdown
|
||||
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)):
|
||||
line = md[i]
|
||||
if not line.startswith('@include'):
|
||||
continue
|
||||
|
||||
# Process @include statements
|
||||
try:
|
||||
path = line[line.index('`') + 1:]
|
||||
path = path[:path.index('`')]
|
||||
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]
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,31 @@ span.highlight {
|
||||
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 {
|
||||
border-collapse: collapse;
|
||||
border: 2px solid #5b3300;
|
||||
|
||||
Reference in New Issue
Block a user