diff --git a/build.py b/build.py index ee88e46..435fa6c 100644 --- a/build.py +++ b/build.py @@ -15,6 +15,7 @@ dl.download_edition("N") dl.download_question_metadata() dl.download_pictures() dl.download_photos() +dl.download_includes() # Build edition: bd.build_edition("N") diff --git a/src/build.py b/src/build.py index f5aa932..a6f8ebc 100644 --- a/src/build.py +++ b/src/build.py @@ -128,6 +128,11 @@ class Build: result = BeautifulSoup(result, "html.parser").prettify() file.write(result) + def __include_handler(self, include): + with open("data/includes.json") as file: + includes = json.load(file) + return includes.get(include) + # cached def __build_section(self, edition, edition_name, section, chapter, next_section=None, next_chapter=None): section_template = self.env.get_template("section.html") @@ -135,7 +140,12 @@ class Build: next_chapter_template = self.env.get_template("next_chapter.html") with open(f'build/{edition}_{section["ident"]}.html', 'w') as file: - with FiftyOhmHtmlRenderer(self.__build_question, self.__picture_handler, self.__photo_handler) as renderer: + with FiftyOhmHtmlRenderer( + self.__build_question, + self.__picture_handler, + self.__photo_handler, + self.__include_handler + ) as renderer: section["content"] = renderer.render(Document(section["content"])) result = section_template.render( diff --git a/test/acceptanceTest.md b/test/acceptanceTest.md index 24f9f58..0fb2698 100644 --- a/test/acceptanceTest.md +++ b/test/acceptanceTest.md @@ -1,5 +1,7 @@ % Kommentar: DARC-DOWN-TEST +[include:test] + Das ist eine Item-Liste: * Erster Eintrag @@ -78,8 +80,6 @@ CQ CQ hier ist DL1PZ mit einem allgemeinen Anruf, hier ist DL1PZ und hört. *QSO* ist eine Abkürzung, die ursprünglich aus der Morsetelegrafie stammt und "ich habe direkten Kontakt zu Station X" bedeutet. Daran angelehnt, sprechen Funkamateure oftmals von einem QSO, wenn sie eine erfolgreiche Funkverbindung meinen. -[include:test] - | c: | l: | c: | l: | c: | l: | | | | | | | | diff --git a/test/test_html.py b/test/test_html.py index 2d3844c..05b8964 100644 --- a/test/test_html.py +++ b/test/test_html.py @@ -69,12 +69,19 @@ def question_stub(input): answer_pictures=answer_pictures, ) +def include_stub(include): + with open("data/includes.json") as file: + includes = json.load(file) + return includes.get(include) def test_html(capsys): with capsys.disabled(): with open("test/acceptanceTest.md") as file: content = file.read() - with FiftyOhmHtmlRenderer(question_stub) as renderer: + with FiftyOhmHtmlRenderer( + question_renderer=question_stub, + include_handler=include_stub, + ) as renderer: output = renderer.render(Document(content)) with open("test/acceptanceTest.html", "w") as output_file: pretty = BeautifulSoup(output, "html.parser").prettify()