From a1c439c32e66cbbcf9892050a4c1f9899670494d Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Wed, 21 Feb 2024 23:34:23 +0100 Subject: [PATCH] Minor fixes, typos, generating of MetaValues, fixed error where KeyErrors from the inside of the tree would get eaten. --- src/formatitko/html_generator.py | 2 +- src/formatitko/nop_processor.py | 4 +++- src/formatitko/output_generator.py | 25 +++++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index 28f49de..4089a69 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -328,7 +328,7 @@ class StandaloneHTMLGenerator(HTMLGenerator): self.indent_more() self.writeln(self.single_tag("meta", attributes={"charset": "utf-8"})) self.writeln(self.single_tag("meta", attributes={"viewport": "width=device-width, initial-scale=1.0"})) - self.writeln(self.single_tag("link", attributes={"href": "https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css", "integrity":"sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0", "crossorigin":"anonymous"})) + self.writeln(self.single_tag("link", attributes={"rel": "stylesheet", "href": "https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css", "integrity":"sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0", "crossorigin":"anonymous"})) if "title" in e.metadata: self.write(self.start_tag("title")) self.generate(e.metadata["title"]) diff --git a/src/formatitko/nop_processor.py b/src/formatitko/nop_processor.py index f20ff1b..8218b2e 100644 --- a/src/formatitko/nop_processor.py +++ b/src/formatitko/nop_processor.py @@ -111,10 +111,12 @@ class NOPProcessor: e = transformer(e) try: - e = self.TYPE_DICT[type(e)](e) + method = self.TYPE_DICT[type(e)] except KeyError: raise self.UnknownElementError(type(e)) + e = method(e) + for transformer in self.get_posttransformers(): e = transformer(e) diff --git a/src/formatitko/output_generator.py b/src/formatitko/output_generator.py index 71dbebf..f2e0853 100644 --- a/src/formatitko/output_generator.py +++ b/src/formatitko/output_generator.py @@ -157,9 +157,10 @@ class OutputGenerator: self.generate_MetaList(e) else: try: - self.TYPE_DICT_MISC[type(e)](e) + method = self.TYPE_DICT_MISC[type(e)] except KeyError as err: raise UnknownElementError(type(e)) from err + method(e) if isinstance(e, Group): self.context = old_context except FormatitkoRecursiveError as err: @@ -292,9 +293,10 @@ class OutputGenerator: def generate_MetaValue(self, e: MetaValue): try: - self.TYPE_DICT_META[type(e)](e) + method = self.TYPE_DICT_META[type(e)] except KeyError: self.generate(e.content) + method(e) def generate_MetaBlocks(self, e: MetaBlocks): self.generate(e.content) @@ -303,16 +305,23 @@ class OutputGenerator: self.generate(e.content) def generate_MetaBool(self, e: MetaBool): - self.generate_simple_tag(e) + if e.boolean: + self.write("True") + else: + self.write("False") def generate_MetaMap(self, e: MetaMap): self.generate_simple_tag(e) def generate_MetaString(self, e: MetaString): - self.generate_simple_tag(e) + self.write(e.text) def generate_Inline(self, e: Inline): - self.TYPE_DICT_INLINE[type(e)](e) + try: + method = self.TYPE_DICT_INLINE[type(e)] + except KeyError as err: + raise UnknownElementError(type(e)) from err + method(e) def generate_Str(self, e: Str): self.write(self.escape_special_chars(e.text)) @@ -413,7 +422,11 @@ class OutputGenerator: def generate_Block(self, e: Block): - self.TYPE_DICT_BLOCK[type(e)](e) + try: + method = self.TYPE_DICT_BLOCK[type(e)] + except KeyError as err: + raise UnknownElementError(type(e)) from err + method(e) # Block elements