diff --git a/.drone.yml b/.drone.yml index 01ba815..2dc868f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,10 +4,8 @@ name: default steps: - name: 50ohm.de - image: debian:latest + image: ghcr.io/astral-sh/uv:python3.12-bookworm environment: commands: - - apt-get update && apt-get install -qyf --no-install-recommends python3 - - curl -LsSf https://astral.sh/uv/install.sh | sh - - pip install --break-system-packages `cat requirements.txt` - - cd test && pytest \ No newline at end of file + - uv pip install --system --break-system-packages --requirements requirements.txt + - cd test && pytest --junitxml=./test-reports/junit.xml diff --git a/renderer/comment.py b/renderer/comment.py index cd4ff6f..52fff45 100644 --- a/renderer/comment.py +++ b/renderer/comment.py @@ -1,7 +1,17 @@ +import re + from mistletoe.block_token import BlockToken +from mistletoe.span_token import SpanToken -class Comment(BlockToken): +class SpanComment(SpanToken): + """ + Coment span token (% Eiersalat). + Identifies a comment in text. + """ + pattern = re.compile(r'(%.*\n?)') + +class BlockComment(BlockToken): @staticmethod def start(line): return line.startswith("%") diff --git a/renderer/dash.py b/renderer/dash.py new file mode 100644 index 0000000..10f80a2 --- /dev/null +++ b/renderer/dash.py @@ -0,0 +1,11 @@ +import re + +from mistletoe.span_token import SpanToken + + +class Dash(SpanToken): + """ + Dash span token ( - ). + Identifies a dash in a text. + """ + pattern = re.compile(r'(\s-\s)') diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index 804ebdb..7e8b1e7 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -2,7 +2,8 @@ import textwrap from mistletoe import HtmlRenderer -from renderer.comment import Comment +from renderer.comment import BlockComment, SpanComment +from renderer.dash import Dash from renderer.halfwidth_spaces import HalfwidthSpaces from renderer.nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots from renderer.quote import Quote @@ -16,10 +17,16 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): margin_id = 0 def __init__(self): - super().__init__(Comment, Quote, Underline, Tag, HalfwidthSpaces, NonbreakingSpaces, NonbreakingSpacesDots) + super().__init__(Dash, BlockComment, SpanComment, Quote, Underline, Tag, HalfwidthSpaces, NonbreakingSpaces, NonbreakingSpacesDots) - def render_comment(): - return None + def render_dash(self, token): + return " – " + + def render_block_comment(self, token): + return "" + + def render_span_comment(self, token): + return "" def render_quote(self, token): return f"„{self.render_inner(token)}“" @@ -67,7 +74,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): if(token.tagtype == "webmargin"): type = "margin" - elif(token.tagtype == "webtip"): + elif(token.tagtype == "webtipp"): type = "tipp" elif(token.tagtype == "webindepth"): type = "indepth" diff --git a/renderer/tag.py b/renderer/tag.py index 05d089b..6bdc187 100644 --- a/renderer/tag.py +++ b/renderer/tag.py @@ -2,12 +2,24 @@ import re from mistletoe.block_token import BlockToken, tokenize +captures = [ + "margin", + "indepth", + "webmargin", + "tipp", + "webtipp", + "webindepth", + "unit", + "danger", + "webonly", + "latexonly", +] class Tag(BlockToken): @staticmethod def start(line): - return re.match(r"^\s*<[^>]+>", line) + return re.match(r"^\s*<("+"|".join(captures)+r")+>", line) @classmethod def read(cls, lines): diff --git a/test/test_comment.py b/test/test_comment.py new file mode 100644 index 0000000..9abf3ce --- /dev/null +++ b/test/test_comment.py @@ -0,0 +1,20 @@ +import mistletoe +import pytest +from mistletoe.ast_renderer import AstRenderer + +from renderer.comment import BlockComment, SpanComment +from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer +from test.util import paragraph + + +def test_comment_html(capsys) : + + assertions = { + "%Comment\nBar" : "
Bar
\n", + # TODO: This test is not working as expected. The comment should be removed + #"%Comment\n" : "a", + "Foo\n%Comment\nBar" : "Foo\nBar
\n", + } + + for assertion in assertions: + assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion] diff --git a/test/test_dash.py b/test/test_dash.py new file mode 100644 index 0000000..2289b0c --- /dev/null +++ b/test/test_dash.py @@ -0,0 +1,14 @@ +import mistletoe + +from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer +from test.util import paragraph + + +def test_dash_html() : + + assertions = { + "Foo - Bar" : "Foo – Bar", + } + + for assertion in assertions: + assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion]) diff --git a/test/test_tag.py b/test/test_tag.py index ba6ab95..967e8f3 100644 --- a/test/test_tag.py +++ b/test/test_tag.py @@ -18,7 +18,7 @@ def test_tag_html() : "Foo
",1,0)+'\n', "Foo
",1,0)+'\n', "Foo
",1,0)+'\n', - "Foo
",1,0)+'\n', + "Foo
",1,0)+'\n', "Foo
",1,0)+'\n', "Foo
",1,0)+'\n', "Foo
",1,0)+'\n',