Browse Source

Partial rewrite of error handling

Now the error doesn't handle itself, but offers a helper function to do
it.
error-handling
Jan Černohorský 10 months ago
parent
commit
42a63b3163
  1. 33
      src/formatitko/formatitko.py
  2. 16
      src/formatitko/html_generator.py
  3. 10
      src/formatitko/latex_generator.py
  4. 40
      src/formatitko/nop_processor.py
  5. 77
      src/formatitko/output_generator.py
  6. 56
      src/formatitko/tex_generator.py

33
src/formatitko/formatitko.py

@ -14,7 +14,7 @@ from .katex import KatexClient
from .html import html from .html import html
from .tex import tex from .tex import tex
from .images import ImageProcessor from .images import ImageProcessor
from .output_generator import OutputGenerator from .output_generator import OutputGenerator, FormatitkoRecursiveError
from .html_generator import HTMLGenerator from .html_generator import HTMLGenerator
from .transform_processor import TransformProcessor from .transform_processor import TransformProcessor
from .pandoc_processor import PandocProcessor from .pandoc_processor import PandocProcessor
@ -54,9 +54,15 @@ def main():
doc = import_md(open(args.input_filename, "r").read()) doc = import_md(open(args.input_filename, "r").read())
if args.debug: if args.debug:
OutputGenerator(sys.stdout).generate(doc) try:
OutputGenerator(sys.stdout).generate(doc)
except FormatitkoRecursiveError as e:
e.pretty_print()
doc = TransformProcessor(args.input_filename).transform(doc) try:
doc = TransformProcessor(args.input_filename).transform(doc)
except FormatitkoRecursiveError as e:
e.pretty_print()
# Initialize the image processor (this just keeps some basic state) # Initialize the image processor (this just keeps some basic state)
imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, args.img_cache_dir, *args.img_lookup_dirs) imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, args.img_cache_dir, *args.img_lookup_dirs)
@ -65,11 +71,18 @@ def main():
# Initialize KaTeX client (this runs the node app and connects to a unix socket) # Initialize KaTeX client (this runs the node app and connects to a unix socket)
with KatexClient(socket=args.katex_socket) as katexClient: with KatexClient(socket=args.katex_socket) as katexClient:
with open(args.output_html, "w") as file: with open(args.output_html, "w") as file:
HTMLGenerator(file, katexClient, imageProcessor).generate(doc) try:
HTMLGenerator(file, katexClient, imageProcessor).generate(doc)
except FormatitkoRecursiveError as e:
e.pretty_print()
if args.output_tex is not None: if args.output_tex is not None:
with open(args.output_tex, "w") as file: with open(args.output_tex, "w") as file:
UCWTexGenerator(file, imageProcessor).generate(doc) try:
UCWTexGenerator(file, imageProcessor).generate(doc)
except FormatitkoRecursiveError as e:
e.pretty_print()
if args.output_md is not None: if args.output_md is not None:
with open(args.output_md, "w") as file: with open(args.output_md, "w") as file:
@ -83,7 +96,10 @@ def main():
if args.output_tex is None: if args.output_tex is None:
fd = tempfile.NamedTemporaryFile(dir=".", suffix=".tex") fd = tempfile.NamedTemporaryFile(dir=".", suffix=".tex")
with open(fd.name, "w") as file: with open(fd.name, "w") as file:
UCWTexGenerator(file, imageProcessor).generate(doc) try:
UCWTexGenerator(file, imageProcessor).generate(doc)
except FormatitkoRecursiveError as e:
e.pretty_print()
filename = fd.name filename = fd.name
else: else:
filename = args.output_tex filename = args.output_tex
@ -93,7 +109,10 @@ def main():
if args.debug: if args.debug:
print("-----------------------------------") print("-----------------------------------")
OutputGenerator(sys.stdout).generate(doc) try:
OutputGenerator(sys.stdout).generate(doc)
except FormatitkoRecursiveError as e:
e.pretty_print()
if __name__ == "__main__": if __name__ == "__main__":

16
src/formatitko/html_generator.py

@ -29,10 +29,10 @@ class HTMLGenerator(OutputGenerator):
self.imageProcessor = imageProcessor self.imageProcessor = imageProcessor
super().__init__(output_file, *args, **kwargs) super().__init__(output_file, *args, **kwargs)
def _generate(self, e: Union[Element, ListContainer]): def generate(self, e: Union[Element, ListContainer]):
if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "html": if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "html":
return return
super()._generate(e) super().generate(e)
def escape_special_chars(self, text: str) -> str: def escape_special_chars(self, text: str) -> str:
text = text.replace("&", "&") text = text.replace("&", "&")
@ -190,7 +190,7 @@ class HTMLGenerator(OutputGenerator):
attributes["alt"] = e.title attributes["alt"] = e.title
else: else:
fake_out = io.StringIO() fake_out = io.StringIO()
HTMLGenerator(fake_out, self.katexClient, self.imageProcessor)._generate(e.content) HTMLGenerator(fake_out, self.katexClient, self.imageProcessor).generate(e.content)
attributes["alt"] = fake_out.getvalue() attributes["alt"] = fake_out.getvalue()
if len(srcset) != 0: if len(srcset) != 0:
@ -202,7 +202,7 @@ class HTMLGenerator(OutputGenerator):
img = RawInline(self.single_tag("img", attributes)) img = RawInline(self.single_tag("img", attributes))
link = Link(img, url=url) link = Link(img, url=url)
self._generate(link) self.generate(link)
def generate_InlineGroup(self, e: InlineGroup): def generate_InlineGroup(self, e: InlineGroup):
self.generate_Group(e) self.generate_Group(e)
@ -216,10 +216,10 @@ class HTMLGenerator(OutputGenerator):
self.katexClient.endgroup() self.katexClient.endgroup()
def generate_Plain(self, e: Plain): def generate_Plain(self, e: Plain):
self._generate(e.content) self.generate(e.content)
def generate_LineItem(self, e: LineItem): def generate_LineItem(self, e: LineItem):
self._generate(e.content) self.generate(e.content)
self.write("<br>") self.write("<br>")
self.endln() self.endln()
@ -229,12 +229,12 @@ class HTMLGenerator(OutputGenerator):
tag = self.tagname(e) tag = self.tagname(e)
if inline is not None: if inline is not None:
self.write(self.start_tag(tag)+" (") self.write(self.start_tag(tag)+" (")
self._generate(inline) self.generate(inline)
self.write(") "+self.end_tag(tag)) self.write(") "+self.end_tag(tag))
else: else:
self.writeln(self.start_tag(tag) + "(") self.writeln(self.start_tag(tag) + "(")
self.indent_more() self.indent_more()
self._generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.writeln(self.end_tag(tag) + ")") self.writeln(self.end_tag(tag) + ")")

10
src/formatitko/latex_generator.py

@ -17,10 +17,10 @@ class LaTeXGenerator(OutputGenerator):
self.imageProcessor = imageProcessor self.imageProcessor = imageProcessor
super().__init__(output_file, *args, **kwargs) super().__init__(output_file, *args, **kwargs)
def _generate(self, e: Union[Element, ListContainer]): def generate(self, e: Union[Element, ListContainer]):
if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex": if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex":
return return
super()._generate(e) super().generate(e)
def escape_special_chars(self, text: str) -> str: def escape_special_chars(self, text: str) -> str:
text = text.replace("&", "\\&") text = text.replace("&", "\\&")
@ -58,14 +58,14 @@ class LaTeXGenerator(OutputGenerator):
self.endln() self.endln()
def generate_Para(self, e: Para): def generate_Para(self, e: Para):
self._generate(e.content) self.generate(e.content)
self.writeln("") # This ensures an empty line self.writeln("") # This ensures an empty line
def generate_Plain(self, e: Plain): def generate_Plain(self, e: Plain):
self._generate(e.content) self.generate(e.content)
def generate_Span(self, e: Plain): def generate_Span(self, e: Plain):
self._generate(e.content) self.generate(e.content)
def generate_Header(self, e: Header): def generate_Header(self, e: Header):
tag = { tag = {

40
src/formatitko/nop_processor.py

@ -10,6 +10,7 @@ from .elements import FQuoted
from .context import Group, InlineGroup, BlockGroup from .context import Group, InlineGroup, BlockGroup
from .whitespace import Whitespace from .whitespace import Whitespace
from .command import BlockCommand, InlineCommand, CodeCommand, Command from .command import BlockCommand, InlineCommand, CodeCommand, Command
from .output_generator import FormatitkoRecursiveError
ELCl = Union[Element, ListContainer, list[Union[Element, ListContainer]]] ELCl = Union[Element, ListContainer, list[Union[Element, ListContainer]]]
@ -96,23 +97,30 @@ class NOPProcessor:
return [] return []
def transform(self, e: ELCl) -> ELCl: def transform(self, e: ELCl) -> ELCl:
if isinstance(e, list):
return self.transform_list(e)
elif isinstance(e, ListContainer):
return self.transform_ListContainer(e)
for transformer in self.get_pretransformers():
e = transformer(e)
try: try:
e = self.TYPE_DICT[type(e)](e) if isinstance(e, list):
except KeyError: return self.transform_list(e)
raise self.UnknownElementError(type(e)) elif isinstance(e, ListContainer):
return self.transform_ListContainer(e)
for transformer in self.get_posttransformers():
e = transformer(e) for transformer in self.get_pretransformers():
e = transformer(e)
return e
try:
e = self.TYPE_DICT[type(e)](e)
except KeyError:
raise self.UnknownElementError(type(e))
for transformer in self.get_posttransformers():
e = transformer(e)
return e
except FormatitkoRecursiveError as err:
if not isinstance(e, ListContainer):
err.add_element(e)
raise err
except Exception as err:
raise FormatitkoRecursiveError(e) from err
def transform_list(self, e: list[Union[Element, ListContainer]]) -> list[Union[Element, ListContainer]]: def transform_list(self, e: list[Union[Element, ListContainer]]) -> list[Union[Element, ListContainer]]:
for i in range(len(e)): for i in range(len(e)):

77
src/formatitko/output_generator.py

@ -10,14 +10,15 @@ from .whitespace import NBSP
from .elements import FQuoted from .elements import FQuoted
from .context import Group, InlineGroup, BlockGroup, Context from .context import Group, InlineGroup, BlockGroup, Context
import re, sys
import sys
class UnknownElementError(Exception): class UnknownElementError(Exception):
"An unknown Element has been passed to the OutputGenerator, probably because panflute introduced a new one." "An unknown Element has been passed to the OutputGenerator, probably because panflute introduced a new one."
pass pass
class OutputGeneratorError(Exception): class FormatitkoRecursiveError(Exception):
"A generic exception which wraps other exceptions and adds element-based traceback" "A generic exception which wraps other exceptions and adds element-based traceback"
elements: list[Union[Element, ListContainer, list[Union[Element, ListContainer]]]] elements: list[Union[Element, ListContainer, list[Union[Element, ListContainer]]]]
@ -28,6 +29,22 @@ class OutputGeneratorError(Exception):
def add_element(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]): def add_element(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
self.elements.append(e) self.elements.append(e)
def pretty_print(self):
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
eprint("Error occured in ", end="")
for i in range(len(self.elements)-1, 0, -1):
if hasattr(self.elements[i], "content") and isinstance(self.elements[i].content[0], Inline):
eprint()
eprint('on line: "' + stringify(self.elements[i]) + '"', end="")
break
eprint(type(self.elements[i]).__name__ + "[" + str(self.elements[i-1].index) + "]", end=": ")
eprint()
eprint("in element: " + str(self.elements[0]))
sys.tracebacklimit = 0
raise self.__cause__ from None
class OutputGenerator: class OutputGenerator:
_empty_lines: int _empty_lines: int
context: Union[Context, None] context: Union[Context, None]
@ -114,24 +131,6 @@ class OutputGenerator:
} }
def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]): def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
try:
self._generate(e)
except OutputGeneratorError as err:
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
eprint("Error occured in ", end="")
for i in range(len(err.elements)-1, 0, -1):
if hasattr(err.elements[i], "content") and isinstance(err.elements[i].content[0], Inline):
eprint()
eprint('on line: "' + stringify(err.elements[i]) + '"', end="")
break
eprint(type(err.elements[i]).__name__ + "[" + str(err.elements[i-1].index) + "]", end=": ")
eprint()
eprint("in element: " + str(err.elements[0]))
sys.tracebacklimit = 0
raise err.__cause__ from None
def _generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
try: try:
if isinstance(e, Group): if isinstance(e, Group):
old_context = self.context old_context = self.context
@ -155,12 +154,12 @@ class OutputGenerator:
raise UnknownElementError(type(e)) from err raise UnknownElementError(type(e)) from err
if isinstance(e, Group): if isinstance(e, Group):
self.context = old_context self.context = old_context
except OutputGeneratorError as err: except FormatitkoRecursiveError as err:
if not isinstance(e, ListContainer): if not isinstance(e, ListContainer):
err.add_element(e) err.add_element(e)
raise err raise err
except Exception as err: except Exception as err:
raise OutputGeneratorError(e) from err raise FormatitkoRecursiveError(e) from err
def escape_special_chars(self, text: str) -> str: def escape_special_chars(self, text: str) -> str:
return text return text
@ -248,13 +247,13 @@ class OutputGenerator:
def generate_simple_inline_tag(self, tag: str, content: Union[ListContainer, Element, list[Union[Element, ListContainer]]], attributes: dict[str,str]={}): def generate_simple_inline_tag(self, tag: str, content: Union[ListContainer, Element, list[Union[Element, ListContainer]]], attributes: dict[str,str]={}):
self.write(self.start_tag(tag, attributes)) self.write(self.start_tag(tag, attributes))
self._generate(content) self.generate(content)
self.write(self.end_tag(tag)) self.write(self.end_tag(tag))
def generate_simple_block_tag(self, tag: str, content: Union[ListContainer, Element, list[Union[Element, ListContainer]]], attributes: dict[str,str]={}): def generate_simple_block_tag(self, tag: str, content: Union[ListContainer, Element, list[Union[Element, ListContainer]]], attributes: dict[str,str]={}):
self.writeln(self.start_tag(tag, attributes)) self.writeln(self.start_tag(tag, attributes))
self.indent_more() self.indent_more()
self._generate(content) self.generate(content)
self.indent_less() self.indent_less()
self.writeln(self.end_tag(tag)) self.writeln(self.end_tag(tag))
@ -273,27 +272,27 @@ class OutputGenerator:
def generate_ListContainer(self, e: ListContainer): def generate_ListContainer(self, e: ListContainer):
for child in e: for child in e:
self._generate(child) self.generate(child)
def generate_list(self, e: list): def generate_list(self, e: list):
for el in e: for el in e:
self._generate(el) self.generate(el)
def generate_MetaList(self, e: MetaList): def generate_MetaList(self, e: MetaList):
for child in e: for child in e:
self._generate(child) self.generate(child)
def generate_MetaValue(self, e: MetaValue): def generate_MetaValue(self, e: MetaValue):
try: try:
self.TYPE_DICT_META[type(e)](e) self.TYPE_DICT_META[type(e)](e)
except KeyError: except KeyError:
self._generate(e.content) self.generate(e.content)
def generate_MetaBlocks(self, e: MetaBlocks): def generate_MetaBlocks(self, e: MetaBlocks):
self._generate(e.content) self.generate(e.content)
def generate_MetaInlines(self, e: MetaInlines): def generate_MetaInlines(self, e: MetaInlines):
self._generate(e.content) self.generate(e.content)
def generate_MetaBool(self, e: MetaBool): def generate_MetaBool(self, e: MetaBool):
self.generate_simple_tag(e) self.generate_simple_tag(e)
@ -323,33 +322,33 @@ class OutputGenerator:
if e.style == "cs": if e.style == "cs":
if e.quote_type == "SingleQuote": if e.quote_type == "SingleQuote":
self.write("") self.write("")
self._generate(e.content) self.generate(e.content)
self.write("") self.write("")
elif e.quote_type == "DoubleQuote": elif e.quote_type == "DoubleQuote":
self.write("") self.write("")
self._generate(e.content) self.generate(e.content)
self.write("") self.write("")
elif e.style == "en": elif e.style == "en":
if e.quote_type == "SingleQuote": if e.quote_type == "SingleQuote":
self.write("") self.write("")
self._generate(e.content) self.generate(e.content)
self.write("") self.write("")
elif e.quote_type == "DoubleQuote": elif e.quote_type == "DoubleQuote":
self.write("") self.write("")
self._generate(e.content) self.generate(e.content)
self.write("") self.write("")
else: else:
if e.quote_type == "SingleQuote": if e.quote_type == "SingleQuote":
self.write("'") self.write("'")
self._generate(e.content) self.generate(e.content)
self.write("'") self.write("'")
elif e.quote_type == "DoubleQuote": elif e.quote_type == "DoubleQuote":
self.write("\"") self.write("\"")
self._generate(e.content) self.generate(e.content)
self.write("\"") self.write("\"")
else: else:
self.write("\"") self.write("\"")
self._generate(e.content) self.generate(e.content)
self.write("\"") self.write("\"")
@ -472,10 +471,10 @@ class OutputGenerator:
def generate_Doc(self, e: Doc): def generate_Doc(self, e: Doc):
if "header_content" in e.metadata: if "header_content" in e.metadata:
self._generate(e.metadata["header_content"]) self.generate(e.metadata["header_content"])
self.generate_simple_tag(e) self.generate_simple_tag(e)
if "footer_content" in e.metadata: if "footer_content" in e.metadata:
self._generate(e.metadata["footer_content"]) self.generate(e.metadata["footer_content"])
def generate_BlockGroup(self, e: BlockGroup): def generate_BlockGroup(self, e: BlockGroup):
self.generate_simple_tag(e) self.generate_simple_tag(e)

56
src/formatitko/tex_generator.py

@ -41,10 +41,10 @@ class UCWTexGenerator(OutputGenerator):
text = text.replace("", "") text = text.replace("", "")
return text return text
def _generate(self, e: Union[Element, ListContainer]): def generate(self, e: Union[Element, ListContainer]):
if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex": if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex":
return return
super()._generate(e) super().generate(e)
def writepar(self, text: str): def writepar(self, text: str):
self.ensure_empty(2) self.ensure_empty(2)
@ -60,7 +60,7 @@ class UCWTexGenerator(OutputGenerator):
def generate_Para(self, e: Para): def generate_Para(self, e: Para):
self.ensure_empty(2) self.ensure_empty(2)
self._generate(e.content) self.generate(e.content)
self.ensure_empty(2) self.ensure_empty(2)
def generate_HorizontalRule(self, e: HorizontalRule): def generate_HorizontalRule(self, e: HorizontalRule):
@ -72,7 +72,7 @@ class UCWTexGenerator(OutputGenerator):
self.writeln(r"\ucwmodule{verb}") self.writeln(r"\ucwmodule{verb}")
self.writeln(r"\ucwmodule{link}") self.writeln(r"\ucwmodule{link}")
self.writeln(r"\input formatitko.tex") self.writeln(r"\input formatitko.tex")
self._generate(e.content) self.generate(e.content)
self.writeln(r"\bye") self.writeln(r"\bye")
def get_language_macro(self, lang: str): def get_language_macro(self, lang: str):
@ -88,21 +88,21 @@ class UCWTexGenerator(OutputGenerator):
def generate_InlineGroup(self, e: InlineGroup): def generate_InlineGroup(self, e: InlineGroup):
self.write(r"{") self.write(r"{")
self.write(self.get_language_macro(self.context.get_metadata("lang"))) self.write(self.get_language_macro(self.context.get_metadata("lang")))
self._generate(e.content) self.generate(e.content)
self.write(r"}") self.write(r"}")
def generate_BlockGroup(self, e: BlockGroup): def generate_BlockGroup(self, e: BlockGroup):
self.writeln(r"\begingroup") self.writeln(r"\begingroup")
self.indent_more() self.indent_more()
self.writeln(self.get_language_macro(self.context.get_metadata("lang"))) self.writeln(self.get_language_macro(self.context.get_metadata("lang")))
self._generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.writeln(r"\endgroup") self.writeln(r"\endgroup")
def generate_Header(self, e: Header): def generate_Header(self, e: Header):
self.ensure_empty(2) self.ensure_empty(2)
self.write("\\"+"sub"*(e.level-1)+"section{") self.write("\\"+"sub"*(e.level-1)+"section{")
self._generate(e.content) self.generate(e.content)
self.write(r"}") self.write(r"}")
self.ensure_empty(2) self.ensure_empty(2)
@ -156,12 +156,12 @@ class UCWTexGenerator(OutputGenerator):
self.writeln(r"\vskip5pt") self.writeln(r"\vskip5pt")
self.writeln(r"\centerline{") self.writeln(r"\centerline{")
self.indent_more() self.indent_more()
self._generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.writeln(r"}") self.writeln(r"}")
self.writeln(r"\centerline{") self.writeln(r"\centerline{")
self.indent_more() self.indent_more()
self._generate(e.caption) self.generate(e.caption)
self.indent_less() self.indent_less()
self.writeln(r"}") self.writeln(r"}")
self.writeln(r"\vskip5pt{}") self.writeln(r"\vskip5pt{}")
@ -173,7 +173,7 @@ class UCWTexGenerator(OutputGenerator):
else: else:
self.write(r"{\I{}") self.write(r"{\I{}")
self._italic+=1 self._italic+=1
self._generate(e.content) self.generate(e.content)
self._italic-=1 self._italic-=1
self.write(r"}") self.write(r"}")
@ -183,7 +183,7 @@ class UCWTexGenerator(OutputGenerator):
else: else:
self.write(r"{\bf{}") self.write(r"{\bf{}")
self._bold+=1 self._bold+=1
self._generate(e.content) self.generate(e.content)
self._bold-=1 self._bold-=1
self.write(r"}") self.write(r"}")
@ -204,7 +204,7 @@ class UCWTexGenerator(OutputGenerator):
def generate_Note(self, e: Note): def generate_Note(self, e: Note):
self.write(r"\fn{") self.write(r"\fn{")
self._generate(inlinify(e)) self.generate(inlinify(e))
self.write(r"}") self.write(r"}")
def generate_Table(self, e: Table): def generate_Table(self, e: Table):
@ -217,11 +217,11 @@ class UCWTexGenerator(OutputGenerator):
self.writeln(r"\vskip1em") self.writeln(r"\vskip1em")
self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr") self.writeln(r"\halign{\strut"+"&".join([aligns[col[0]] for col in e.colspec])+r"\cr")
self.indent_more() self.indent_more()
self._generate(e.head.content) self.generate(e.head.content)
self.writeln(r"\noalign{\hrule}") self.writeln(r"\noalign{\hrule}")
self._generate(e.content[0].content) self.generate(e.content[0].content)
self.writeln(r"\noalign{\hrule}") self.writeln(r"\noalign{\hrule}")
self._generate(e.foot.content) self.generate(e.foot.content)
self.indent_less() self.indent_less()
self.writeln("}") self.writeln("}")
self.writeln(r"\vskip1em") self.writeln(r"\vskip1em")
@ -230,7 +230,7 @@ class UCWTexGenerator(OutputGenerator):
for cell in e.content: for cell in e.content:
if cell.colspan > 1: if cell.colspan > 1:
self.write(r"\multispan"+str(cell.colspan)+"{} ") self.write(r"\multispan"+str(cell.colspan)+"{} ")
self._generate(cell.content) self.generate(cell.content)
if cell.next: if cell.next:
self.write(" & ") self.write(" & ")
self.write(r"\cr") self.write(r"\cr")
@ -245,10 +245,10 @@ class UCWTexGenerator(OutputGenerator):
self.writeraw(e.text) self.writeraw(e.text)
def generate_Plain(self, e: Plain): def generate_Plain(self, e: Plain):
self._generate(e.content) self.generate(e.content)
def generate_Span(self, e: Span): def generate_Span(self, e: Span):
self._generate(e.content) self.generate(e.content)
def generate_CodeBlock(self, e: CodeBlock): def generate_CodeBlock(self, e: CodeBlock):
self.writeln(r"\verbatim{") self.writeln(r"\verbatim{")
@ -256,15 +256,15 @@ class UCWTexGenerator(OutputGenerator):
self.writeln(r"}") self.writeln(r"}")
def generate_Div(self, e: Div): def generate_Div(self, e: Div):
self._generate(e.content) self.generate(e.content)
def generate_LineBlock(self, e: LineBlock): def generate_LineBlock(self, e: LineBlock):
self.writeln() self.writeln()
self._generate(e.content) self.generate(e.content)
self.writeln() self.writeln()
def generate_LineItem(self, e: LineItem): def generate_LineItem(self, e: LineItem):
self._generate(e.content) self.generate(e.content)
if e.next: if e.next:
self.write(r"\\") self.write(r"\\")
self.endln() self.endln()
@ -273,7 +273,7 @@ class UCWTexGenerator(OutputGenerator):
self.ensure_empty(2) self.ensure_empty(2)
self.writeln(r"\list{o}") self.writeln(r"\list{o}")
self.indent_more() self.indent_more()
self._generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.write(r"\endlist") self.write(r"\endlist")
self.ensure_empty(2) self.ensure_empty(2)
@ -298,7 +298,7 @@ class UCWTexGenerator(OutputGenerator):
style = delimiters[e.delimiter] style = delimiters[e.delimiter]
self.writeln(r"\list{"+style+r"}") self.writeln(r"\list{"+style+r"}")
self.indent_more() self.indent_more()
self._generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.writeln(r"\endlist") self.writeln(r"\endlist")
self.ensure_empty(2) self.ensure_empty(2)
@ -306,13 +306,13 @@ class UCWTexGenerator(OutputGenerator):
def generate_ListItem(self, e: ListItem): def generate_ListItem(self, e: ListItem):
self.endln() self.endln()
self.write(r"\:") self.write(r"\:")
self._generate(e.content) self.generate(e.content)
self.endln() self.endln()
def generate_BlockQuote(self, e: BlockQuote): def generate_BlockQuote(self, e: BlockQuote):
self.writeln(r"\blockquote{") self.writeln(r"\blockquote{")
self.indent_more() self.indent_more()
self._generate(e.content) self.generate(e.content)
self.indent_less() self.indent_less()
self.writeln(r"}") self.writeln(r"}")
@ -321,17 +321,17 @@ class UCWTexGenerator(OutputGenerator):
self.write(r"\url{") self.write(r"\url{")
else: else:
self.write(r"\linkurl{"+e.url+r"}{") self.write(r"\linkurl{"+e.url+r"}{")
self._generate(e.content) self.generate(e.content)
self.write(r"}") # } self.write(r"}") # }
def generate_Subscript(self, e: Subscript): def generate_Subscript(self, e: Subscript):
self.write(r"\subscript{") self.write(r"\subscript{")
self._generate(e.content) self.generate(e.content)
self.write(r"}") self.write(r"}")
def generate_Superscript(self, e: Superscript): def generate_Superscript(self, e: Superscript):
self.write(r"\superscript{") self.write(r"\superscript{")
self._generate(e.content) self.generate(e.content)
self.write(r"}") self.write(r"}")
def generate_simple_tag(self, e: Union[Element, None] = None, tag: str = "", attributes: Union[dict[str, str], None] = None, content: Union[ListContainer, Element, list[Union[Element, ListContainer]], str, None] = None, inline: Union[bool, None] = None): def generate_simple_tag(self, e: Union[Element, None] = None, tag: str = "", attributes: Union[dict[str, str], None] = None, content: Union[ListContainer, Element, list[Union[Element, ListContainer]], str, None] = None, inline: Union[bool, None] = None):

Loading…
Cancel
Save