Merge remote-tracking branch 'origin/main' into feature/spaces

This commit is contained in:
Johanna Riedel
2024-12-08 11:52:48 +01:00
8 changed files with 85 additions and 13 deletions
+3 -5
View File
@@ -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
- uv pip install --system --break-system-packages --requirements requirements.txt
- cd test && pytest --junitxml=./test-reports/junit.xml
+11 -1
View File
@@ -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("%")
+11
View File
@@ -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)')
+12 -5
View File
@@ -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"
+13 -1
View File
@@ -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):
+20
View File
@@ -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" : "<p>Bar</p>\n",
# TODO: This test is not working as expected. The comment should be removed
#"%Comment\n" : "a",
"Foo\n%Comment\nBar" : "<p>Foo\nBar</p>\n",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
+14
View File
@@ -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 &ndash; Bar",
}
for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
+1 -1
View File
@@ -18,7 +18,7 @@ def test_tag_html() :
"<indepth>\nFoo\n</indepth>" : FiftyOhmHtmlRenderer.render_tag_helper("indepth","<p>Foo</p>",1,0)+'\n',
"<webmargin>\nFoo\n</webmargin>" : FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,0)+'\n',
"<tipp>\nFoo\n</tipp>" : FiftyOhmHtmlRenderer.render_tag_helper("tipp","<p>Foo</p>",1,0)+'\n',
"<webtipp>\nFoo\n</webtipp>" : FiftyOhmHtmlRenderer.render_tag_helper("webtipp","<p>Foo</p>",1,0)+'\n',
"<webtipp>\nFoo\n</webtipp>" : FiftyOhmHtmlRenderer.render_tag_helper("tipp","<p>Foo</p>",1,0)+'\n',
"<webindepth>\nFoo\n</webindepth>" : FiftyOhmHtmlRenderer.render_tag_helper("indepth","<p>Foo</p>",1,0)+'\n',
"<unit>\nFoo\n</unit>" : FiftyOhmHtmlRenderer.render_tag_helper("unit","<p>Foo</p>",1,0)+'\n',
"<danger>\nFoo\n</danger>" : FiftyOhmHtmlRenderer.render_tag_helper("danger","<p>Foo</p>",1,0)+'\n',