feature: added ability to render includes
This commit is contained in:
@@ -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")
|
||||
|
||||
+11
-1
@@ -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(
|
||||
|
||||
@@ -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.
|
||||
</indepth>
|
||||
|
||||
[include:test]
|
||||
|
||||
<webmargin>
|
||||
| c: | l: | c: | l: | c: | l: |
|
||||
| | | | | | |
|
||||
|
||||
+8
-1
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user