style: reformat code with ruff

This commit is contained in:
Tim Grelka
2024-12-11 01:09:42 +01:00
parent 0b4ce5b8b8
commit 7ef19075ee
17 changed files with 132 additions and 126 deletions
+3 -1
View File
@@ -9,7 +9,9 @@ class SpanComment(SpanToken):
Coment span token (% Eiersalat). Coment span token (% Eiersalat).
Identifies a comment in text. Identifies a comment in text.
""" """
pattern = re.compile(r'(%.*\n?)')
pattern = re.compile(r"(%.*\n?)")
class BlockComment(BlockToken): class BlockComment(BlockToken):
@staticmethod @staticmethod
+2 -1
View File
@@ -8,4 +8,5 @@ class Dash(SpanToken):
Dash span token ( - ). Dash span token ( - ).
Identifies a dash in a text. Identifies a dash in a text.
""" """
pattern = re.compile(r'(\s-\s)')
pattern = re.compile(r"(\s-\s)")
+1 -3
View File
@@ -146,9 +146,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
else: else:
type = token.tagtype type = token.tagtype
return self.render_tag_helper( return self.render_tag_helper(type, self.render_inner(token), self.margin_id, self.margin_anchor_id)
type, self.render_inner(token), self.margin_id, self.margin_anchor_id
)
def render_halfwidth_spaces(self, token): def render_halfwidth_spaces(self, token):
return f"{token.first}. {token.second}." return f"{token.first}. {token.second}."
+7 -12
View File
@@ -10,7 +10,6 @@ from renderer.underline import Underline
class FiftyOhmLaTeXRenderer(LaTeXRenderer): class FiftyOhmLaTeXRenderer(LaTeXRenderer):
def __init__(self): def __init__(self):
super().__init__( super().__init__(
Dash, Dash,
@@ -32,25 +31,24 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
return " -- " return " -- "
def render_block_comment(self, token): def render_block_comment(self, token):
return "" # TODO propagate comments to the LaTeX document return "" # TODO propagate comments to the LaTeX document
def render_span_comment(self, token): def render_span_comment(self, token):
return "" # TODO propagate comments to the LaTeX document return "" # TODO propagate comments to the LaTeX document
def render_quote(self, token): def render_quote(self, token):
return fr"\enquote{{{self.render_inner(token)}}}" return rf"\enquote{{{self.render_inner(token)}}}"
def render_emphasis(self, token): def render_emphasis(self, token):
return fr"\emph{{{self.render_inner(token)}}}" return rf"\emph{{{self.render_inner(token)}}}"
def render_underline(self, token): def render_underline(self, token):
return fr"\underline{{{self.render_inner(token)}}}" return rf"\underline{{{self.render_inner(token)}}}"
def render_thematic_break(self, token): def render_thematic_break(self, token):
return "" return ""
def render_tag(self, token): # noqa: C901 def render_tag(self, token): # noqa: C901
tagtype = None tagtype = None
match token.tagtype: match token.tagtype:
@@ -81,7 +79,7 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
case _: case _:
tagtype = "Margin" tagtype = "Margin"
return fr"\{tagtype}{{{self.render_inner(token)}}}" return rf"\{tagtype}{{{self.render_inner(token)}}}"
def render_halfwidth_spaces(self, token): def render_halfwidth_spaces(self, token):
return f"{token.first}.\,{token.second}." return f"{token.first}.\,{token.second}."
@@ -90,8 +88,5 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
return f"{token.first}~{token.second}" return f"{token.first}~{token.second}"
def render_nonbreaking_spaces_dots(self, token): def render_nonbreaking_spaces_dots(self, token):
lookup = { lookup = {"": "", " ": "~"}
"" : "",
" " : "~"
}
return f"{lookup[token.first]}{token.second}{lookup[token.third]}" return f"{lookup[token.first]}{token.second}{lookup[token.third]}"
+1 -3
View File
@@ -8,11 +8,9 @@ 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|Z|d|D)\.\s?(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)
self.second = match_object.group(2) self.second = match_object.group(2)
+2 -1
View File
@@ -8,6 +8,7 @@ class Morse(SpanToken):
Morse code span token ("[morse:moe]"). Morse code span token ("[morse:moe]").
Generates morse code from a text. Generates morse code from a text.
""" """
@staticmethod @staticmethod
def convert_to_morse_code(text): def convert_to_morse_code(text):
dit = 1 dit = 1
@@ -74,7 +75,7 @@ class Morse(SpanToken):
"bk": [dah, dit, dit, dit, dah, dit, dah], "bk": [dah, dit, dit, dit, dah, dit, dah],
"sk": [dit, dit, dit, dah, dit, dah], "sk": [dit, dit, dit, dah, dit, dah],
"correction": [dit, dit, dit, dit, dit, dit, dit, dit], "correction": [dit, dit, dit, dit, dit, dit, dit, dit],
" ": [space] " ": [space],
} }
result = [] result = []
+3 -3
View File
@@ -8,23 +8,23 @@ 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 without 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])")
def __init__(self, match_object): def __init__(self, match_object):
self.first = match_object.group(1) self.first = match_object.group(1)
self.second = match_object.group(2) self.second = match_object.group(2)
class NonbreakingSpacesDots(SpanToken): class NonbreakingSpacesDots(SpanToken):
""" """
Insert unbreakable space before and after "..." if there is a space Insert unbreakable space before and after "..." if there is a space
Identifies "..." with leading and/or trailing space Identifies "..." with leading and/or trailing space
""" """
pattern = re.compile(r"(\s?)(\.\.\.)(\s?)") pattern = re.compile(r"(\s?)(\.\.\.)(\s?)")
def __init__(self, match_object): def __init__(self, match_object):
self.first = match_object.group(1) self.first = match_object.group(1)
self.second = match_object.group(2) self.second = match_object.group(2)
self.third = match_object.group(3) self.third = match_object.group(3)
+1
View File
@@ -8,4 +8,5 @@ class Quote(SpanToken):
Quote span token ("Eiersalat"). Quote span token ("Eiersalat").
Identifies quoted text. Identifies quoted text.
""" """
pattern = re.compile(r'"([^"]+)"') pattern = re.compile(r'"([^"]+)"')
+1 -1
View File
@@ -8,8 +8,8 @@ class References(SpanToken):
Resolve references for html Resolve references for html
Identifies "[ref:$]" Identifies "[ref:$]"
""" """
pattern = re.compile(r"\[ref\:(\S+)\]") pattern = re.compile(r"\[ref\:(\S+)\]")
def __init__(self, match_object): def __init__(self, match_object):
self.first = match_object.group(1) self.first = match_object.group(1)
+2 -1
View File
@@ -8,4 +8,5 @@ class Underline(SpanToken):
Underline span token (<u>Untersrich</u>). Underline span token (<u>Untersrich</u>).
Identifies underlined text. Identifies underlined text.
""" """
pattern = re.compile(r'<u>(.+)</u>')
pattern = re.compile(r"<u>(.+)</u>")
+8 -9
View File
@@ -4,25 +4,24 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
def test_comment_html() : def test_comment_html():
assertions = { assertions = {
"%Comment\nBar" : "<p>Bar</p>\n", "%Comment\nBar": "<p>Bar</p>\n",
# TODO: This test is not working as expected. The comment should be removed # TODO: This test is not working as expected. The comment should be removed
#"%Comment\n" : "a", # "%Comment\n" : "a",
"Foo\n%Comment\nBar" : "<p>Foo\nBar</p>\n", "Foo\n%Comment\nBar": "<p>Foo\nBar</p>\n",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion] assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_comment_latex() :
def test_comment_latex():
assertions = { assertions = {
"%Comment\nBar" : "\nBar\n", "%Comment\nBar": "\nBar\n",
# TODO: This test is not working as expected. The comment should be removed # TODO: This test is not working as expected. The comment should be removed
#"%Comment\n" : "a", # "%Comment\n" : "a",
"Foo\n%Comment\nBar" : "\nFoo\nBar\n", "Foo\n%Comment\nBar": "\nFoo\nBar\n",
} }
for assertion in assertions: for assertion in assertions:
+4 -5
View File
@@ -5,19 +5,18 @@ from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph from test.util import paragraph
def test_dash_html() : def test_dash_html():
assertions = { assertions = {
"Foo - Bar" : "Foo &ndash; Bar", "Foo - Bar": "Foo &ndash; Bar",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion]) assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_dash_latex() :
def test_dash_latex():
assertions = { assertions = {
"Foo - Bar" : "\nFoo -- Bar\n", "Foo - Bar": "\nFoo -- Bar\n",
} }
for assertion in assertions: for assertion in assertions:
+1 -3
View File
@@ -1,11 +1,9 @@
import mistletoe import mistletoe
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
def test_html(capsys) : def test_html(capsys):
with capsys.disabled(): with capsys.disabled():
with open("test/acceptanceTest.md") as file: with open("test/acceptanceTest.md") as file:
content = file.read() content = file.read()
+14 -10
View File
@@ -11,12 +11,13 @@ def test_paragraph_html():
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target) assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
def test_three_points_html(): def test_three_points_html():
assertions = { assertions = {
"Heute hatte ich ... zum Mittagessen." : "Heute hatte ich&#160;...&#160;zum Mittagessen.", "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.", "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.", "Oh nein ...ein Pinguin.": "Oh nein&#160;...ein Pinguin.",
"Haha .. . Hahaha" : "Haha .. . Hahaha" "Haha .. . Hahaha": "Haha .. . Hahaha",
} }
for key, value in assertions.items(): for key, value in assertions.items():
@@ -29,39 +30,42 @@ def test_absatz_html():
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target) assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
def test_class_html(): def test_class_html():
input = "Ich lerne für Klasse A, Klasse E und Klasse N." input = "Ich lerne für Klasse A, Klasse E und Klasse N."
target = "Ich lerne für Klasse&#160;A, Klasse&#160;E und Klasse&#160;N." target = "Ich lerne für Klasse&#160;A, Klasse&#160;E und Klasse&#160;N."
assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target) assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(target)
def test_paragraph_latex(): def test_paragraph_latex():
input = "Der Test befindet sich unter §2 vielleicht aber auch § 3." input = "Der Test befindet sich unter §2 vielleicht aber auch § 3."
target = "\nDer Test befindet sich unter §~2 vielleicht aber auch §~3.\n" target = "\nDer Test befindet sich unter §~2 vielleicht aber auch §~3.\n"
assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target
def test_three_points_latex(): def test_three_points_latex():
assertions = { assertions = {
"Heute hatte ich ... zum Mittagessen." : "\nHeute hatte ich~...~zum Mittagessen.\n", "Heute hatte ich ... zum Mittagessen.": "\nHeute hatte ich~...~zum Mittagessen.\n",
"Niemals hätte ich gedacht, dass...ich ...nicht kann." : "\nNiemals hätte ich gedacht, dass...ich~...nicht kann.\n", "Niemals hätte ich gedacht, dass...ich ...nicht kann.": "\nNiemals hätte ich gedacht, dass...ich~...nicht kann.\n",
"Oh nein ...ein Pinguin." : "\nOh nein~...ein Pinguin.\n", "Oh nein ...ein Pinguin.": "\nOh nein~...ein Pinguin.\n",
"Haha .. . Hahaha" : "\nHaha .. . Hahaha\n" "Haha .. . Hahaha": "\nHaha .. . Hahaha\n",
} }
for key, value in assertions.items(): for key, value in assertions.items():
assert mistletoe.markdown(key, FiftyOhmLaTeXRenderer) == value assert mistletoe.markdown(key, FiftyOhmLaTeXRenderer) == value
def test_absatz_latex(): def test_absatz_latex():
input = "Der Test befindet sich unter Abs.2 vielleicht aber auch Abs. 3." input = "Der Test befindet sich unter Abs.2 vielleicht aber auch Abs. 3."
target = "\nDer Test befindet sich unter Abs.~2 vielleicht aber auch Abs.~3.\n" target = "\nDer Test befindet sich unter Abs.~2 vielleicht aber auch Abs.~3.\n"
assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target
def test_class_latex(): def test_class_latex():
input = "Ich lerne für Klasse A, Klasse E und Klasse N." input = "Ich lerne für Klasse A, Klasse E und Klasse N."
target = "\nIch lerne für Klasse~A, Klasse~E und Klasse~N.\n" target = "\nIch lerne für Klasse~A, Klasse~E und Klasse~N.\n"
assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target assert mistletoe.markdown(input, FiftyOhmLaTeXRenderer) == target
+14 -15
View File
@@ -5,29 +5,28 @@ from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph from test.util import paragraph
def test_quote_html() : def test_quote_html():
assertions = { assertions = {
'"quote"' : '„quote“', '"quote"': "„quote“",
'" quote "' : '„ quote “', '" quote "': "„ quote “",
'"quote" "' : '„quote“ "', '"quote" "': '„quote“ "',
'"quo te1" filltext "qu ot e2"' : '„quo te1“ filltext „qu ot e2“', '"quo te1" filltext "qu ot e2"': "„quo te1“ filltext „qu ot e2“",
'"quo *te1*" filltext "qu ot e2"' : '„quo <em>te1</em>“ filltext „qu ot e2“', '"quo *te1*" filltext "qu ot e2"': "„quo <em>te1</em>“ filltext „qu ot e2“",
'""' : '""', '""': '""',
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion]) assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_quote_latex() :
def test_quote_latex():
assertions = { assertions = {
'"quote"' : '\n\enquote{quote}\n', '"quote"': "\n\enquote{quote}\n",
'" quote "' : '\n\enquote{ quote }\n', '" quote "': "\n\enquote{ quote }\n",
'"quote" "' : '\n\enquote{quote} "\n', '"quote" "': '\n\enquote{quote} "\n',
'"quo te1" filltext "qu ot e2"' : '\n\enquote{quo te1} filltext \enquote{qu ot e2}\n', '"quo te1" filltext "qu ot e2"': "\n\enquote{quo te1} filltext \enquote{qu ot e2}\n",
'"quo *te1*" filltext "qu ot e2"' : '\n\enquote{quo \emph{te1}} filltext \enquote{qu ot e2}\n', '"quo *te1*" filltext "qu ot e2"': "\n\enquote{quo \emph{te1}} filltext \enquote{qu ot e2}\n",
'""' : '\n""\n', '""': '\n""\n',
} }
for assertion in assertions: for assertion in assertions:
+51 -40
View File
@@ -4,81 +4,92 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
def test_thematic_break_html():
def test_thematic_break_html() :
assertions = { assertions = {
"---" : '<a id="margin_1"></a>\n', "---": '<a id="margin_1"></a>\n',
"---\n---" : '<a id="margin_1"></a>\n<a id="margin_2"></a>\n', "---\n---": '<a id="margin_1"></a>\n<a id="margin_2"></a>\n',
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion] assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_tag_html() :
def test_tag_html():
assertions = { assertions = {
"<margin>\nFoo\n</margin>" : FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,0)+'\n', "<margin>\nFoo\n</margin>": FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 0) + "\n",
"<indepth>\nFoo\n</indepth>" : FiftyOhmHtmlRenderer.render_tag_helper("indepth","<p>Foo</p>",1,0)+'\n', "<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', "<webmargin>\nFoo\n</webmargin>": FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 0) + "\n",
"<tip>\nFoo\n</tip>" : FiftyOhmHtmlRenderer.render_tag_helper("tip","<p>Foo</p>",1,0)+'\n', "<tip>\nFoo\n</tip>": FiftyOhmHtmlRenderer.render_tag_helper("tip", "<p>Foo</p>", 1, 0) + "\n",
"<webtip>\nFoo\n</webtip>" : FiftyOhmHtmlRenderer.render_tag_helper("tip","<p>Foo</p>",1,0)+'\n', "<webtip>\nFoo\n</webtip>": FiftyOhmHtmlRenderer.render_tag_helper("tip", "<p>Foo</p>", 1, 0) + "\n",
"<webindepth>\nFoo\n</webindepth>" : FiftyOhmHtmlRenderer.render_tag_helper("indepth","<p>Foo</p>",1,0)+'\n', "<webindepth>\nFoo\n</webindepth>": FiftyOhmHtmlRenderer.render_tag_helper("indepth", "<p>Foo</p>", 1, 0)
"<unit>\nFoo\n</unit>" : FiftyOhmHtmlRenderer.render_tag_helper("unit","<p>Foo</p>",1,0)+'\n', + "\n",
"<danger>\nFoo\n</danger>" : FiftyOhmHtmlRenderer.render_tag_helper("danger","<p>Foo</p>",1,0)+'\n', "<unit>\nFoo\n</unit>": FiftyOhmHtmlRenderer.render_tag_helper("unit", "<p>Foo</p>", 1, 0) + "\n",
"<webonly>\nFoo\n</webonly>" : '<p>Foo</p>\n', "<danger>\nFoo\n</danger>": FiftyOhmHtmlRenderer.render_tag_helper("danger", "<p>Foo</p>", 1, 0) + "\n",
"<latexonly>\nFoo\n</latexonly>" : "", "<webonly>\nFoo\n</webonly>": "<p>Foo</p>\n",
"<latexonly>\nFoo\n</latexonly>": "",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion] assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_thematic_break_and_tag_html() :
def test_thematic_break_and_tag_html():
assertions = { assertions = {
"---\n<margin>\nFoo\n</margin>" : '<a id="margin_1"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,1)+'\n', "---\n<margin>\nFoo\n</margin>": '<a id="margin_1"></a>\n'
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>" : '<a id="margin_1"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,1)+'\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",2,1)+'\n', + FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 1)
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>" : '<a id="margin_1"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",1,1)+'\n<a id="margin_2"></a>\n'+FiftyOhmHtmlRenderer.render_tag_helper("margin","<p>Foo</p>",2,2)+'\n', + "\n",
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>": '<a id="margin_1"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 1)
+ "\n"
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 2, 1)
+ "\n",
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>": '<a id="margin_1"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 1, 1)
+ '\n<a id="margin_2"></a>\n'
+ FiftyOhmHtmlRenderer.render_tag_helper("margin", "<p>Foo</p>", 2, 2)
+ "\n",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion] assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
def test_thematic_break_latex() :
def test_thematic_break_latex():
assertions = { assertions = {
"---" : '', "---": "",
"---\n---" : '', "---\n---": "",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion] assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
def test_tag_latex() :
def test_tag_latex():
assertions = { assertions = {
"<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}", "<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}",
"<danger>\nFoo\n</danger>" : "\MarginDanger{\nFoo\n}", "<danger>\nFoo\n</danger>": "\MarginDanger{\nFoo\n}",
"<warning>\nFoo\n</warning>" : "\MarginWarning{\nFoo\n}", "<warning>\nFoo\n</warning>": "\MarginWarning{\nFoo\n}",
"<attention>\nFoo\n</attention>" : "\MarginAttention{\nFoo\n}", "<attention>\nFoo\n</attention>": "\MarginAttention{\nFoo\n}",
"<tip>\nFoo\n</tip>" : "\MarginTip{\nFoo\n}", "<tip>\nFoo\n</tip>": "\MarginTip{\nFoo\n}",
"<webtip>\nFoo\n</webtip>" : "\WebTip{\nFoo\n}", "<webtip>\nFoo\n</webtip>": "\WebTip{\nFoo\n}",
"<unit>\nFoo\n</unit>" : "\MarginUnit{\nFoo\n}", "<unit>\nFoo\n</unit>": "\MarginUnit{\nFoo\n}",
"<indepth>\nFoo\n</indepth>" : "\MarginInDepth{\nFoo\n}", "<indepth>\nFoo\n</indepth>": "\MarginInDepth{\nFoo\n}",
"<webindepth>\nFoo\n</webindepth>" : "\MarginWebInDepth{\nFoo\n}", "<webindepth>\nFoo\n</webindepth>": "\MarginWebInDepth{\nFoo\n}",
"<webmargin>\nFoo\n</webmargin>" : "\WebMargin{\nFoo\n}", "<webmargin>\nFoo\n</webmargin>": "\WebMargin{\nFoo\n}",
"<fullwidth>\nFoo\n</fullwidth>" : "\FullWidth{\nFoo\n}", "<fullwidth>\nFoo\n</fullwidth>": "\FullWidth{\nFoo\n}",
"<latexonly>\nFoo\n</latexonly>" : "\nFoo\n", "<latexonly>\nFoo\n</latexonly>": "\nFoo\n",
"<webonly>\nFoo\n</webonly>" : "", "<webonly>\nFoo\n</webonly>": "",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion] assert mistletoe.markdown(assertion, FiftyOhmLaTeXRenderer) == assertions[assertion]
def test_thematic_break_and_tag_latex() :
def test_thematic_break_and_tag_latex():
assertions = { assertions = {
"---\n<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}", "---\n<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}\Margin{\nFoo\n}", "---\n<margin>\nFoo\n</margin>\n<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}\Margin{\nFoo\n}",
"---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>" : "\Margin{\nFoo\n}\Margin{\nFoo\n}", "---\n<margin>\nFoo\n</margin>\n---\n<margin>\nFoo\n</margin>": "\Margin{\nFoo\n}\Margin{\nFoo\n}",
} }
for assertion in assertions: for assertion in assertions:
+8 -9
View File
@@ -5,23 +5,22 @@ from renderer.fifty_ohm_latex_renderer import FiftyOhmLaTeXRenderer
from test.util import paragraph from test.util import paragraph
def test_underline_html() : def test_underline_html():
assertions = { assertions = {
"<u>Text</u>" : "<u>Text</u>", "<u>Text</u>": "<u>Text</u>",
"<u> Text Text </u>" : "<u> Text Text </u>", "<u> Text Text </u>": "<u> Text Text </u>",
"<u> Text *Text* </u>" : "<u> Text <em>Text</em> </u>", "<u> Text *Text* </u>": "<u> Text <em>Text</em> </u>",
} }
for assertion in assertions: for assertion in assertions:
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion]) assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
def test_underline_latex() :
def test_underline_latex():
assertions = { assertions = {
"<u>Text</u>" : "\n\\underline{Text}\n", "<u>Text</u>": "\n\\underline{Text}\n",
"<u> Text Text </u>" : "\n\\underline{ Text Text }\n", "<u> Text Text </u>": "\n\\underline{ Text Text }\n",
"<u> Text *Text* </u>" : "\n\\underline{ Text \emph{Text} }\n", "<u> Text *Text* </u>": "\n\\underline{ Text \emph{Text} }\n",
} }
for assertion in assertions: for assertion in assertions: