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

This commit is contained in:
Johanna Riedel
2024-12-08 12:12:06 +01:00
3 changed files with 21 additions and 10 deletions
+6 -5
View File
@@ -18,7 +18,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
margin_id = 0
def __init__(self):
super().__init__(Dash, BlockComment, SpanComment, Quote, Underline, Tag, HalfwidthSpaces, NonbreakingSpaces, NonbreakingSpacesDots, References)
super().__init__(Dash, BlockComment, SpanComment, Quote, Underline, Tag, HalfwidthSpaces, NonbreakingSpaces, NonbreakingSpacesDots, HalfwidthSpaces, NonbreakingSpaces, NonbreakingSpacesDots, References)
def render_dash(self, token):
return " – "
@@ -97,7 +97,8 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
return f"{token.first} {token.second}"
def render_nonbreaking_spaces_dots(self, token):
return f" {token.first} "
def render_references(self, token, dest_id=0, chap_url="DeineMama.html"):
return f"<a href=&#34;{chap_url}#ref_{token.first}&#34; onclick=&#34;highlightRef(&#39;{token.first}&#39;);&#34;>{dest_id}</a>"
lookup = {
"" : "",
" " : "&#160;"
}
return f"{lookup[token.first]}{token.second}{lookup[token.third]}"
+7 -2
View File
@@ -7,7 +7,6 @@ class NonbreakingSpaces(SpanToken):
"""
Insert unbreakable space into span token (§ 3)
Identifies "§$number", "Abs.$number", "Klasse [A,E,N]" w/ and w\ space between.
Identifies "..." with and without leading and trailing space
"""
pattern = re.compile(r"(§|Abs\.|Klasse)\s?(\d|[NEA])")
@@ -16,10 +15,16 @@ class NonbreakingSpaces(SpanToken):
self.second = match_object.group(2)
class NonbreakingSpacesDots(SpanToken):
pattern = re.compile(r"\s?(\.\.\.)\s?")
"""
Insert unbreakable space before and after "..." if there is a space
Identifies "..." with leading and/or trailing space
"""
pattern = re.compile(r"(\s?)(\.\.\.)(\s?)")
def __init__(self, match_object):
self.first = match_object.group(1)
self.second = match_object.group(2)
self.third = match_object.group(3)
+8 -3
View File
@@ -10,10 +10,15 @@ def test_paragraph_html():
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
def test_three_points_html():
input = "Heute hatte ich ... zum Mittagessen."
target = "Heute hatte ich&#160;...&#160;zum Mittagessen."
assertions = {
"Heute hatte ich ... zum Mittagessen." : "Heute hatte ich&#160;...&#160;zum Mittagessen.",
"Niemals hätte ich gedacht, dass...ich ...nicht kann." : "Niemals hätte ich gedacht, dass...ich&#160;...nicht kann.",
"Oh nein ...ein Pinguin." : "Oh nein&#160;...ein Pinguin.",
"Haha .. . Hahaha" : "Haha .. . Hahaha"
}
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
for key, value in assertions.items():
assert mistletoe.markdown(key, FiftyOhmHtmlRenderer) == paragraph(value)
def test_absatz_html():