Browse Source

Minor fixes, typos, generating of MetaValues, fixed error where KeyErrors from the inside of the tree would get eaten.

master
Jan Černohorský 9 months ago
parent
commit
a1c439c32e
  1. 2
      src/formatitko/html_generator.py
  2. 4
      src/formatitko/nop_processor.py
  3. 25
      src/formatitko/output_generator.py

2
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"])

4
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)

25
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

Loading…
Cancel
Save