Compare commits
2 commits
e364217734
...
aab9cfff0b
Author | SHA1 | Date | |
---|---|---|---|
aab9cfff0b | |||
91329e6339 |
2 changed files with 41 additions and 17 deletions
|
@ -134,15 +134,18 @@ def process_file(ifile: TextIOWrapper):
|
||||||
return contents, title
|
return contents, title
|
||||||
|
|
||||||
def process_list(line: str, in_list: bool):
|
def process_list(line: str, in_list: bool):
|
||||||
if in_list:
|
try:
|
||||||
if line[0] == "*":
|
if in_list:
|
||||||
line = re.sub(r'^\* (.*)', r'<li>\1</li>', line)
|
if line[:2] == "* ":
|
||||||
else:
|
line = re.sub(r'^\* (.*)', r'<li>\1</li>', line)
|
||||||
in_list = False
|
else:
|
||||||
line = "</ul>\n\n"
|
in_list = False
|
||||||
elif line[0] == "*":
|
line = f"</ul>\n\n{line}"
|
||||||
line = "<ul>\n" + re.sub(r'^\* (.*)', r'<li>\1</li>', line)
|
elif line[:2] == "* ":
|
||||||
in_list = True
|
line = "<ul>\n" + re.sub(r'^\* (.*)', r'<li>\1</li>', line)
|
||||||
|
in_list = True
|
||||||
|
except IndexError:
|
||||||
|
in_list = False
|
||||||
return line, in_list
|
return line, in_list
|
||||||
|
|
||||||
def process_inline(line: str):
|
def process_inline(line: str):
|
||||||
|
|
|
@ -11,14 +11,22 @@ from gmirator.generate import (
|
||||||
def test_process_file():
|
def test_process_file():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_process_list():
|
def test_process_list_legit_item():
|
||||||
test_str = "this is a line outside a list"
|
|
||||||
assert process_list(test_str, True) == ("</ul>\n\n", False)
|
|
||||||
assert process_list(test_str, False) == (test_str, False)
|
|
||||||
test_str = "* this is a list item"
|
test_str = "* this is a list item"
|
||||||
assert process_list(test_str, True) == ("<li>this is a list item</li>", True)
|
assert process_list(test_str, True) == (f"<li>{test_str[2:]}</li>", True)
|
||||||
assert process_list(test_str, False) == ("<ul>\n<li>this is a list item</li>", True)
|
assert process_list(test_str, False) == (f"<ul>\n<li>{test_str[2:]}</li>", True)
|
||||||
pass
|
|
||||||
|
def test_process_list_not_list_items():
|
||||||
|
test_str = "this is a line outside a list"
|
||||||
|
assert process_list(test_str, True) == (f"</ul>\n\n{test_str}", False)
|
||||||
|
assert process_list(test_str, False) == (test_str, False)
|
||||||
|
test_str = "*this is NOT a list item*"
|
||||||
|
assert process_list(test_str, True) == (f"</ul>\n\n{test_str}", False)
|
||||||
|
assert process_list(test_str, False) == (f"{test_str}", False)
|
||||||
|
|
||||||
|
def test_process_list_empty_line():
|
||||||
|
assert process_list("", True) == ("</ul>\n\n", False)
|
||||||
|
assert process_list("", False) == ("", False)
|
||||||
|
|
||||||
def test_process_inline():
|
def test_process_inline():
|
||||||
assert process_inline("*Hello* ~~world~~!") == "<em>Hello</em> <s>world</s>!"
|
assert process_inline("*Hello* ~~world~~!") == "<em>Hello</em> <s>world</s>!"
|
||||||
|
@ -34,4 +42,17 @@ def test_repl_url_internal_gmi_url():
|
||||||
assert new_url == '<a href="/gempage.html">=> title</a><br>\n'
|
assert new_url == '<a href="/gempage.html">=> title</a><br>\n'
|
||||||
|
|
||||||
def test_repl_heading():
|
def test_repl_heading():
|
||||||
pass
|
line = "# this is h1 title"
|
||||||
|
html_h1 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||||
|
line = "## this is h2 title"
|
||||||
|
html_h2 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||||
|
line = "### this is h3 title"
|
||||||
|
html_h3 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||||
|
assert html_h1 == "<h1># this is h1 title</h1>"
|
||||||
|
assert html_h2 == "<h2>## this is h2 title</h2>"
|
||||||
|
assert html_h3 == "<h3>### this is h3 title</h3>"
|
||||||
|
|
||||||
|
def test_repl_heading_h4():
|
||||||
|
line = "#### this is h4 title"
|
||||||
|
html_h4 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||||
|
assert html_h4 == "<h4>#### this is h4 title</h4>"
|
||||||
|
|
Loading…
Reference in a new issue