From 411b50e7930e98d0351c0d5f524b977cea0f4535 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 24 Nov 2021 19:43:59 -0500 Subject: [PATCH] [+] Process @include --- src/report.py | 17 +++++++++++++++-- src/report_document.md | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/report.py b/src/report.py index 80680de..1fc4681 100644 --- a/src/report.py +++ b/src/report.py @@ -1,6 +1,8 @@ +import os.path + import markdown -from constants import SRC_DIR +from constants import SRC_DIR, REPORT_DIR from utils import read @@ -10,7 +12,18 @@ def generate_report() -> str: :return: HTML """ - return markdown.markdown(read(f'{SRC_DIR}/report_document.md')) + # Load markdown + md = read(f'{SRC_DIR}/report_document.md').replace('\r\n', '\n').split('\n') + + # Process @include statements + for i in range(len(md)): + line = md[i] + if line.startswith('@include'): + line = line[line.index('`') + 1:] + line = line[:line.index('`')] + md[i] = read(os.path.join(REPORT_DIR, line)) + + return markdown.markdown('\n'.join(md)) if __name__ == '__main__': diff --git a/src/report_document.md b/src/report_document.md index 94074c5..43b7619 100644 --- a/src/report_document.md +++ b/src/report_document.md @@ -1,4 +1,10 @@ # H1 -Test +Test Image: + +![](../report/1-covid-tweet-frequency/500-pop.png) + +Test Include: + +@include `../report/1-covid-tweet-frequency/500-pop.md`