refactor: Fixed desired ... handling and more tests

This commit is contained in:
Johanna Riedel
2024-12-08 00:13:02 +01:00
parent 5a4e6554c0
commit f908a75c2e
3 changed files with 20 additions and 6 deletions
+5 -1
View File
@@ -26,4 +26,8 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
return f"{token.first} {token.second}"
def render_nonbreaking_spaces_dots(self, token):
return f" {token.first} "
lookup = {
"" : "",
" " : " "
}
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)