First draft for pictures
This commit is contained in:
@@ -2,6 +2,8 @@ import textwrap
|
||||
|
||||
from mistletoe import Document, HtmlRenderer
|
||||
|
||||
from renderer.picture import Picture
|
||||
|
||||
from .comment import BlockComment
|
||||
from .dash import Dash
|
||||
from .halfwidth_spaces import HalfwidthSpaces
|
||||
@@ -35,6 +37,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
NonbreakingSpacesDots,
|
||||
References,
|
||||
Question,
|
||||
Picture
|
||||
)
|
||||
self.question_renderer = question_renderer
|
||||
|
||||
@@ -168,3 +171,15 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
# 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 f"{inner}\n" if inner else ""
|
||||
|
||||
@staticmethod
|
||||
def render_picture_helper(id, ref, text, number):
|
||||
return f"""
|
||||
<figure class="picture" id="ref_{ref}" name="{ref}">
|
||||
<img src="img/picture_{id}.svg">
|
||||
<figcaption>Abbildung {number}: {text}</figcaption>
|
||||
</figure>
|
||||
"""
|
||||
|
||||
def render_picture(self, token) :
|
||||
self.render_picture_helper(token.id, token.ref, token.text, token.number)
|
||||
@@ -0,0 +1,19 @@
|
||||
import re
|
||||
|
||||
from mistletoe.span_token import SpanToken
|
||||
|
||||
|
||||
class Picture(SpanToken):
|
||||
"""
|
||||
Span token for pictures.
|
||||
Example: [picture:727:amplitude_periode_halbwellen:Positive und negative Halbwellen einer Sinusschwingung]
|
||||
"""
|
||||
|
||||
parse_inner = False
|
||||
pattern = re.compile(r"\[picture:(\d+):(.+):(.+)\]")
|
||||
|
||||
def __init__(self, match_object):
|
||||
self.id = match_object.group(1)
|
||||
self.ref = match_object.group(2)
|
||||
self.text = match_object.group(3)
|
||||
self.number = "TODO"
|
||||
@@ -0,0 +1,27 @@
|
||||
import mistletoe
|
||||
import pytest
|
||||
|
||||
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
|
||||
from test.util import paragraph
|
||||
|
||||
|
||||
@pytest.mark.html
|
||||
def test_underline_html():
|
||||
assertions = {
|
||||
"[picture:123:abc:Text]": FiftyOhmHtmlRenderer.render_picture_helper("123", "abc", "Text", "TODO"),
|
||||
}
|
||||
|
||||
for assertion in assertions:
|
||||
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
|
||||
|
||||
|
||||
#@pytest.mark.latex
|
||||
#def test_underline_latex():
|
||||
# assertions = {
|
||||
# "<u>Text</u>": "\n\\underline{Text}\n",
|
||||
# "<u> Text Text </u>": "\n\\underline{ Text Text }\n",
|
||||
# "<u> Text *Text* </u>": "\n\\underline{ Text \emph{Text} }\n",
|
||||
# }
|
||||
#
|
||||
# for assertion in assertions:
|
||||
# assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
|
||||
Reference in New Issue
Block a user