feature: first slide rendering and acceptance test based on html renderer
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
|
||||
|
||||
from itertools import chain
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from mistletoe import Document, HtmlRenderer
|
||||
|
||||
@@ -28,8 +30,9 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
section_url = "section.html"
|
||||
ref_id = 0
|
||||
|
||||
def __init__(self, question_renderer=None, picture_handler=None, photo_handler=None):
|
||||
super().__init__(
|
||||
def __init__(self, *extras, question_renderer=None, picture_handler=None, photo_handler=None):
|
||||
|
||||
final_extras = chain(extras,(
|
||||
Dash,
|
||||
BlockComment,
|
||||
Quote,
|
||||
@@ -46,7 +49,10 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
Photo,
|
||||
Table,
|
||||
Qso,
|
||||
)
|
||||
))
|
||||
|
||||
super().__init__(*final_extras)
|
||||
|
||||
self.question_renderer = question_renderer
|
||||
self.picture_handler = picture_handler
|
||||
self.photo_handler = photo_handler
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from mistletoe import Document
|
||||
|
||||
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
|
||||
|
||||
from .slide_break import SlideBreak
|
||||
|
||||
|
||||
class FiftyOhmHtmlSlideRenderer(FiftyOhmHtmlRenderer):
|
||||
|
||||
def __init__(self, question_renderer=None, picture_handler=None, photo_handler=None):
|
||||
super().__init__(
|
||||
SlideBreak,
|
||||
question_renderer=question_renderer,
|
||||
picture_handler=picture_handler,
|
||||
photo_handler=photo_handler,
|
||||
)
|
||||
|
||||
def render_wrapper(self, content):
|
||||
content = "---\n" + content
|
||||
return super().render(Document(content))
|
||||
|
||||
def render_slide_break(self, token):
|
||||
inner = self.render_inner(token)
|
||||
|
||||
if token.attribute is None:
|
||||
return f'<section>\n{inner}\n</section>\n'
|
||||
if token.attribute == "attention":
|
||||
return f'<section data-background-color="#B8EAFF">\n{inner}\n</section>\n'
|
||||
elif token.attribute == "danger":
|
||||
return f'<section data-background-color="#FF756D">\n{inner}\n</section>\n'
|
||||
elif token.attribute == "unit":
|
||||
return f'<section data-background-color="#40C08C">\n{inner}\n</section>\n'
|
||||
else:
|
||||
return f'<section {token.attribute}>\n{inner}\n</section>\n'
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
# ^\s*---\s*(.*)\s*$
|
||||
import re
|
||||
|
||||
from mistletoe.block_token import BlockToken, tokenize
|
||||
|
||||
|
||||
class SlideBreak(BlockToken):
|
||||
@staticmethod
|
||||
def start(line):
|
||||
return re.match(r"^\s*---.*$", line)
|
||||
|
||||
@classmethod
|
||||
def read(cls, lines):
|
||||
child_lines = []
|
||||
first_line = next(lines) # Consume the line that started the slide break
|
||||
|
||||
match = re.match(r"^\s*---\s*(.*)\s*.*$", first_line)
|
||||
attribute = match.group(1) if match.group(1) else None
|
||||
|
||||
# We have to work with peak here, since a normal for loop would already
|
||||
# consume the next line, which might be a `---` line that marks the
|
||||
# beginning of a new slide as well
|
||||
next_line = lines.peek()
|
||||
while next_line is not None:
|
||||
if re.match(r"^\s*---.*$", next_line) :
|
||||
break
|
||||
else:
|
||||
child_lines.append(next(lines))
|
||||
next_line = lines.peek()
|
||||
|
||||
return tokenize(child_lines), attribute
|
||||
|
||||
def __init__(self, match):
|
||||
self.children, self.attribute = match
|
||||
Reference in New Issue
Block a user