Pull request #19: Fix

Merge in FRAG/50ohm.de from fix to main

* commit 'b0749905483b3a554e75febb738c5eafebbee30f':
  fix: Space support for halfwidthspaces
This commit is contained in:
Johanna Riedel DJ4UH
2024-12-10 23:43:39 +00:00
committed by Tim Grelka DA2TG
3 changed files with 11 additions and 6 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ class HalfwidthSpaces(SpanToken):
Insert halfwidth space into span token (Z. B.) Insert halfwidth space into span token (Z. B.)
Identifies "z.B.", "d.h." and "D.h." with and without space in between. Identifies "z.B.", "d.h." and "D.h." with and without space in between.
""" """
pattern = re.compile(r"\b(z|d|D)\.(B|h)\.") pattern = re.compile(r"\b(z|Z|d|D)\.\s?(B|h)\.")
def __init__(self, match_object): def __init__(self, match_object):
self.first = match_object.group(1) self.first = match_object.group(1)
+1 -1
View File
@@ -6,7 +6,7 @@ from mistletoe.span_token import SpanToken
class NonbreakingSpaces(SpanToken): class NonbreakingSpaces(SpanToken):
""" """
Insert unbreakable space into span token (§ 3) Insert unbreakable space into span token (§ 3)
Identifies "§$number", "Abs.$number", "Klasse [A,E,N]" w/ and w\ space between. Identifies "§$number", "Abs.$number", "Klasse [A,E,N]" w/ and without space between.
""" """
pattern = re.compile(r"(§|Abs\.|Klasse)\s?(\d|[NEA])") pattern = re.compile(r"(§|Abs\.|Klasse)\s?(\d|[NEA])")
+9 -4
View File
@@ -3,8 +3,13 @@ import mistletoe
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from test.util import paragraph from test.util import paragraph
def test_halfwidth_space_html():
input = "Dies ist z.B. ein Test. D.h. hier sollten d.h. Spaces ersetzt worden sein."
target = "Dies ist z. B. ein Test. D. h. hier sollten d. h. Spaces ersetzt worden sein."
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target) def test_halfwidth_space_html():
assertions = {
"Dies ist z.B. ein Test. D.h. hier sollten d.h. Spaces ersetzt worden sein." : "Dies ist z. B. ein Test. D. h. hier sollten d. h. Spaces ersetzt worden sein.",
"Dies ist z. B. ein Test. D. h. hier sollten d. h. Spaces ersetzt worden sein." : "Dies ist z. B. ein Test. D. h. hier sollten d. h. Spaces ersetzt worden sein.",
"Z. B. die D.B. wird auch ersetzt, aber das macht nix." : "Z. B. die D. B. wird auch ersetzt, aber das macht nix."
}
for key, value in assertions.items():
assert mistletoe.markdown(key, FiftyOhmHtmlRenderer) == paragraph(value)