feat: render comments in LaTeX
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import textwrap
|
||||
|
||||
from mistletoe import HtmlRenderer
|
||||
from mistletoe import Document, HtmlRenderer
|
||||
|
||||
from .comment import BlockComment, SpanComment
|
||||
from .comment import BlockComment
|
||||
from .dash import Dash
|
||||
from .halfwidth_spaces import HalfwidthSpaces
|
||||
from .morse import Morse
|
||||
@@ -24,7 +24,6 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
super().__init__(
|
||||
Dash,
|
||||
BlockComment,
|
||||
SpanComment,
|
||||
Quote,
|
||||
Unit,
|
||||
Underline,
|
||||
@@ -40,10 +39,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
return " – "
|
||||
|
||||
def render_block_comment(self, token):
|
||||
return ""
|
||||
|
||||
def render_span_comment(self, token):
|
||||
return ""
|
||||
return None
|
||||
|
||||
def render_quote(self, token):
|
||||
return f"„{self.render_inner(token)}“"
|
||||
@@ -158,5 +154,11 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
lookup = {"": "", " ": " "}
|
||||
return f"{lookup[token.first]}{token.second}{lookup[token.third]}"
|
||||
|
||||
def render_references(self, token):
|
||||
def render_references(self, token: References):
|
||||
return f'<a href="{self.section_url}#ref_{token.first}" onclick="highlightRef(\'{token.first}\');">{self.ref_id}</a>'
|
||||
|
||||
def render_document(self, token: Document) -> str:
|
||||
self.footnotes.update(token.footnotes)
|
||||
# Filter out None values, so block tokens can return None to not be rendered.
|
||||
inner = "\n".join(filter(lambda x: x is not None, [self.render(child) for child in token.children]))
|
||||
return "{}\n".format(inner) if inner else ""
|
||||
|
||||
@@ -30,7 +30,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
||||
return " -- "
|
||||
|
||||
def render_block_comment(self, token):
|
||||
return "" # TODO propagate comments to the LaTeX document
|
||||
return f"% {token.content}"
|
||||
|
||||
def render_quote(self, token):
|
||||
return rf"\enquote{{{self.render_inner(token)}}}"
|
||||
|
||||
@@ -23,10 +23,10 @@ def test_comment_html():
|
||||
@pytest.mark.latex
|
||||
def test_comment_latex():
|
||||
assertions = {
|
||||
"%Comment\nBar": "\nBar\n",
|
||||
# TODO: This test is not working as expected. The comment should be removed
|
||||
# "%Comment\n" : "a",
|
||||
"Foo\n%Comment\nBar": "\nFoo\nBar\n",
|
||||
"%Comment\nBar": "% Comment\nBar\n",
|
||||
"%Comment\n": "% Comment",
|
||||
"Foo 100 % Bar": "\nFoo 100 \% Bar\n",
|
||||
"Foo\n%Comment\nBar": "\nFoo\n% Comment\nBar\n",
|
||||
}
|
||||
|
||||
for assertion in assertions:
|
||||
|
||||
Reference in New Issue
Block a user