WIP: Experimental error handling with snippets of input for OutputGenerator. Would be nice to generalise for TransformProcessor, which is not easy as they don't have a common parent class.
This commit is contained in:
parent
05ffd321d8
commit
a7963ba824
5 changed files with 120 additions and 82 deletions
|
@ -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) + ")")
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class KatexClient:
|
||||||
if "error" in response:
|
if "error" in response:
|
||||||
raise KatexServerError(response["error"])
|
raise KatexServerError(response["error"])
|
||||||
if "error" in response["results"][0]:
|
if "error" in response["results"][0]:
|
||||||
raise KatexError(response["results"][0]["error"])
|
raise KatexError(response["results"][0]["error"] + " in $" + tex + "$")
|
||||||
else:
|
else:
|
||||||
return response["results"][0]["html"]
|
return response["results"][0]["html"]
|
||||||
|
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
|
@ -3,18 +3,31 @@ from panflute import Cite, Code, Emph, Image, LineBreak, Link, Math, Note, Quote
|
||||||
from panflute import BlockQuote, BulletList, Citation, CodeBlock, Definition, DefinitionItem, DefinitionList, Div, Figure, Header, HorizontalRule, LineBlock, LineItem, ListItem, MetaBlocks, MetaBool, MetaInlines, MetaList, MetaMap, MetaString, Null, OrderedList, Para, Plain, RawBlock, Table, TableBody, TableFoot, TableHead
|
from panflute import BlockQuote, BulletList, Citation, CodeBlock, Definition, DefinitionItem, DefinitionList, Div, Figure, Header, HorizontalRule, LineBlock, LineItem, ListItem, MetaBlocks, MetaBool, MetaInlines, MetaList, MetaMap, MetaString, Null, OrderedList, Para, Plain, RawBlock, Table, TableBody, TableFoot, TableHead
|
||||||
from panflute import TableRow, TableCell, Caption, Doc
|
from panflute import TableRow, TableCell, Caption, Doc
|
||||||
from panflute import MetaValue
|
from panflute import MetaValue
|
||||||
|
from panflute import stringify
|
||||||
from typing import Union, Callable
|
from typing import Union, Callable
|
||||||
|
|
||||||
from .whitespace import NBSP
|
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
|
import re, 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):
|
||||||
|
"A generic exception which wraps other exceptions and adds element-based traceback"
|
||||||
|
elements: list[Union[Element, ListContainer, list[Union[Element, ListContainer]]]]
|
||||||
|
|
||||||
|
def __init__(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]], *args):
|
||||||
|
self.elements = [e]
|
||||||
|
super().__init__(args)
|
||||||
|
|
||||||
|
def add_element(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
|
||||||
|
self.elements.append(e)
|
||||||
|
|
||||||
class OutputGenerator:
|
class OutputGenerator:
|
||||||
_empty_lines: int
|
_empty_lines: int
|
||||||
context: Union[Context, None]
|
context: Union[Context, None]
|
||||||
|
@ -101,28 +114,53 @@ class OutputGenerator:
|
||||||
}
|
}
|
||||||
|
|
||||||
def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
|
def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
|
||||||
if isinstance(e, Group):
|
try:
|
||||||
old_context = self.context
|
self._generate(e)
|
||||||
self.context = e.context
|
except OutputGeneratorError as err:
|
||||||
if isinstance(e, list):
|
def eprint(*args, **kwargs):
|
||||||
self.generate_list(e)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
elif isinstance(e, ListContainer):
|
eprint("Error occured in ", end="")
|
||||||
self.generate_ListContainer(e)
|
for i in range(len(err.elements)-1, 0, -1):
|
||||||
elif isinstance(e, Inline):
|
if hasattr(err.elements[i], "content") and isinstance(err.elements[i].content[0], Inline):
|
||||||
self.generate_Inline(e)
|
eprint()
|
||||||
elif isinstance(e, Block):
|
eprint('on line: "' + stringify(err.elements[i]) + '"', end="")
|
||||||
self.generate_Block(e)
|
break
|
||||||
elif isinstance(e, MetaValue):
|
eprint(type(err.elements[i]).__name__ + "[" + str(err.elements[i-1].index) + "]", end=": ")
|
||||||
self.generate_MetaValue(e)
|
eprint()
|
||||||
elif isinstance(e, MetaList):
|
eprint("in element: " + str(err.elements[0]))
|
||||||
self.generate_MetaList(e)
|
sys.tracebacklimit = 0
|
||||||
else:
|
raise err.__cause__ from None
|
||||||
try:
|
|
||||||
self.TYPE_DICT_MISC[type(e)](e)
|
def _generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
|
||||||
except KeyError:
|
try:
|
||||||
raise UnknownElementError(type(e))
|
if isinstance(e, Group):
|
||||||
if isinstance(e, Group):
|
old_context = self.context
|
||||||
self.context = old_context
|
self.context = e.context
|
||||||
|
if isinstance(e, list):
|
||||||
|
self.generate_list(e)
|
||||||
|
elif isinstance(e, ListContainer):
|
||||||
|
self.generate_ListContainer(e)
|
||||||
|
elif isinstance(e, Inline):
|
||||||
|
self.generate_Inline(e)
|
||||||
|
elif isinstance(e, Block):
|
||||||
|
self.generate_Block(e)
|
||||||
|
elif isinstance(e, MetaValue):
|
||||||
|
self.generate_MetaValue(e)
|
||||||
|
elif isinstance(e, MetaList):
|
||||||
|
self.generate_MetaList(e)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.TYPE_DICT_MISC[type(e)](e)
|
||||||
|
except KeyError as err:
|
||||||
|
raise UnknownElementError(type(e)) from err
|
||||||
|
if isinstance(e, Group):
|
||||||
|
self.context = old_context
|
||||||
|
except OutputGeneratorError as err:
|
||||||
|
if not isinstance(e, ListContainer):
|
||||||
|
err.add_element(e)
|
||||||
|
raise err
|
||||||
|
except Exception as err:
|
||||||
|
raise OutputGeneratorError(e) from err
|
||||||
|
|
||||||
def escape_special_chars(self, text: str) -> str:
|
def escape_special_chars(self, text: str) -> str:
|
||||||
return text
|
return text
|
||||||
|
@ -210,13 +248,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))
|
||||||
|
|
||||||
|
@ -235,27 +273,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)
|
||||||
|
@ -285,33 +323,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("\"")
|
||||||
|
|
||||||
|
|
||||||
|
@ -434,10 +472,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)
|
||||||
|
|
|
@ -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…
Reference in a new issue