[O] Catch errors in markdown formatting
This commit is contained in:
+30
-20
@@ -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,33 +23,42 @@ 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
|
||||||
|
|
||||||
path = line[line.index('`') + 1:]
|
# Process @include statements
|
||||||
path = path[:path.index('`')]
|
try:
|
||||||
md[i] = read(REPORT_DIR + path)
|
path = line[line.index('`') + 1:]
|
||||||
|
path = path[:path.index('`')]
|
||||||
|
md[i] = read(REPORT_DIR + path)
|
||||||
|
|
||||||
# Cut lines
|
# Cut lines
|
||||||
# Format: @include-cut `path` <start, inclusive> [end, not inclusive]
|
# Format: @include-cut `path` <start, inclusive> [end, not inclusive]
|
||||||
if line.startswith('@include-cut'):
|
if line.startswith('@include-cut'):
|
||||||
args = [int(i) for i in line.split()[2:]]
|
args = [int(i) for i in line.split()[2:]]
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
md[i] = '\n'.join(md[i].split('\n')[args[0]:])
|
md[i] = '\n'.join(md[i].split('\n')[args[0]:])
|
||||||
if len(args) == 2:
|
if len(args) == 2:
|
||||||
md[i] = '\n'.join(md[i].split('\n')[args[0]:args[1]])
|
md[i] = '\n'.join(md[i].split('\n')[args[0]:args[1]])
|
||||||
|
|
||||||
# Specific lines
|
# Specific lines
|
||||||
# Format: @include-lines `path` <...lines>
|
# Format: @include-lines `path` <...lines>
|
||||||
# Example: @include-lines `path` 1 2 5
|
# Example: @include-lines `path` 1 2 5
|
||||||
if line.startswith('@include-lines'):
|
if line.startswith('@include-lines'):
|
||||||
args = [int(i) for i in line.split()[2:]]
|
args = [int(i) for i in line.split()[2:]]
|
||||||
lines = md[i].split('\n')
|
lines = md[i].split('\n')
|
||||||
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)
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user