feat: Renderer add nonbreakable spaces and halfwidth spaces
This commit is contained in:
@@ -2,11 +2,13 @@ from mistletoe import HtmlRenderer
|
||||
|
||||
from renderer.comment import Comment
|
||||
from renderer.quote import Quote
|
||||
from renderer.halfwidth_spaces import HalfwidthSpaces
|
||||
from renderer.nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
||||
|
||||
|
||||
class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
def __init__(self):
|
||||
super().__init__(Comment, Quote)
|
||||
super().__init__(Comment, Quote, HalfwidthSpaces, NonbreakingSpaces, NonbreakingSpacesDots)
|
||||
|
||||
def render_comment():
|
||||
return None
|
||||
@@ -15,4 +17,13 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||
return f"„{self.render_inner(token)}“"
|
||||
|
||||
def render_underline(self, token):
|
||||
return f"<u>{self.render_inner(token)}</u>"
|
||||
return f"<u>{self.render_inner(token)}</u>"
|
||||
|
||||
def render_halfwidth_spaces(self, token):
|
||||
return f"{token.first}. {token.second}."
|
||||
|
||||
def render_nonbreaking_spaces(self, token):
|
||||
return f"{token.first} {token.second}"
|
||||
|
||||
def render_nonbreaking_spaces_dots(self, token):
|
||||
return f" {token.first} "
|
||||
@@ -0,0 +1,18 @@
|
||||
import re
|
||||
|
||||
from mistletoe.span_token import SpanToken
|
||||
|
||||
|
||||
class HalfwidthSpaces(SpanToken):
|
||||
"""
|
||||
Insert halfwidth space into span token (Z. B.)
|
||||
Identifies "z.B.", "d.h." and "D.h." with and without space in between.
|
||||
"""
|
||||
pattern = re.compile(r"\b(z|d|D)\.(B|h)\.")
|
||||
|
||||
def __init__(self, match_object):
|
||||
self.first = match_object.group(1)
|
||||
self.second = match_object.group(2)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
from mistletoe.span_token import SpanToken
|
||||
|
||||
|
||||
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])")
|
||||
|
||||
def __init__(self, match_object):
|
||||
self.first = match_object.group(1)
|
||||
self.second = match_object.group(2)
|
||||
|
||||
class NonbreakingSpacesDots(SpanToken):
|
||||
pattern = re.compile(r"\s?(\.\.\.)\s?")
|
||||
|
||||
def __init__(self, match_object):
|
||||
self.first = match_object.group(1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user