feature: add photos
This commit is contained in:
@@ -2,13 +2,13 @@ import textwrap
|
|||||||
|
|
||||||
from mistletoe import Document, HtmlRenderer
|
from mistletoe import Document, HtmlRenderer
|
||||||
|
|
||||||
from renderer.picture import Picture
|
|
||||||
|
|
||||||
from .comment import BlockComment
|
from .comment import BlockComment
|
||||||
from .dash import Dash
|
from .dash import Dash
|
||||||
from .halfwidth_spaces import HalfwidthSpaces
|
from .halfwidth_spaces import HalfwidthSpaces
|
||||||
from .morse import Morse
|
from .morse import Morse
|
||||||
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
||||||
|
from .photo import Photo
|
||||||
|
from .picture import Picture
|
||||||
from .question import Question
|
from .question import Question
|
||||||
from .quote import Quote
|
from .quote import Quote
|
||||||
from .references import References
|
from .references import References
|
||||||
@@ -37,7 +37,8 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
NonbreakingSpacesDots,
|
NonbreakingSpacesDots,
|
||||||
References,
|
References,
|
||||||
Question,
|
Question,
|
||||||
Picture
|
Picture,
|
||||||
|
Photo
|
||||||
)
|
)
|
||||||
self.question_renderer = question_renderer
|
self.question_renderer = question_renderer
|
||||||
|
|
||||||
@@ -176,10 +177,22 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
def render_picture_helper(id, ref, text, number):
|
def render_picture_helper(id, ref, text, number):
|
||||||
return f"""
|
return f"""
|
||||||
<figure class="picture" id="ref_{ref}" name="{ref}">
|
<figure class="picture" id="ref_{ref}" name="{ref}">
|
||||||
<img src="img/picture_{id}.svg">
|
<img src="picture/picture_{id}.svg">
|
||||||
<figcaption>Abbildung {number}: {text}</figcaption>
|
<figcaption>Abbildung {number}: {text}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def render_picture(self, token) :
|
def render_picture(self, token) :
|
||||||
return self.render_picture_helper(token.id, token.ref, token.text, token.number)
|
return self.render_picture_helper(token.id, token.ref, token.text, token.number)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def render_photo_helper(id, ref, text, number):
|
||||||
|
return f"""
|
||||||
|
<figure class="photo" id="ref_{ref}" name="{ref}">
|
||||||
|
<img src="photo/photo_{id}.png">
|
||||||
|
<figcaption>Abbildung {number}: {text}</figcaption>
|
||||||
|
</figure>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render_photo(self, token) :
|
||||||
|
return self.render_photo_helper(token.id, token.ref, token.text, token.number)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
from mistletoe.latex_renderer import LaTeXRenderer
|
from mistletoe.latex_renderer import LaTeXRenderer
|
||||||
|
|
||||||
from renderer.picture import Picture
|
|
||||||
|
|
||||||
from .comment import BlockComment
|
from .comment import BlockComment
|
||||||
from .dash import Dash
|
from .dash import Dash
|
||||||
from .halfwidth_spaces import HalfwidthSpaces
|
from .halfwidth_spaces import HalfwidthSpaces
|
||||||
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
||||||
|
from .photo import Photo
|
||||||
|
from .picture import Picture
|
||||||
from .question import Question
|
from .question import Question
|
||||||
from .quote import Quote
|
from .quote import Quote
|
||||||
from .tag import Tag
|
from .tag import Tag
|
||||||
@@ -24,7 +24,8 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
NonbreakingSpaces,
|
NonbreakingSpaces,
|
||||||
NonbreakingSpacesDots,
|
NonbreakingSpacesDots,
|
||||||
Question,
|
Question,
|
||||||
Picture
|
Picture,
|
||||||
|
Photo
|
||||||
)
|
)
|
||||||
self.question_renderer = question_renderer
|
self.question_renderer = question_renderer
|
||||||
|
|
||||||
@@ -103,4 +104,13 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
\label{{{ref}}}"""
|
\label{{{ref}}}"""
|
||||||
|
|
||||||
def render_picture(self, token) :
|
def render_picture(self, token) :
|
||||||
|
return self.render_picture_helper(token.id, token.ref, token.text, token.number)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def render_photo_helper(id, ref, text, number):
|
||||||
|
return rf"""\includegraphics[width=1.0\linewidth]{{photo/{id}}}
|
||||||
|
\captionof{{figure}}{{{text}}}
|
||||||
|
\label{{{ref}}}"""
|
||||||
|
|
||||||
|
def render_photo(self, token) :
|
||||||
return self.render_picture_helper(token.id, token.ref, token.text, token.number)
|
return 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 Photo(SpanToken):
|
||||||
|
"""
|
||||||
|
Span token for photos.
|
||||||
|
Example: [photo:123:n_wasserfalldiagramm_trx_collage:Ansichten verschiedener Transceiver]
|
||||||
|
"""
|
||||||
|
|
||||||
|
parse_inner = False
|
||||||
|
pattern = re.compile(r"\[photo:(\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"
|
||||||
Reference in New Issue
Block a user