fix process_list() function

to handle IndexError exception as well as lines starting with '*' that
were not list items.
This commit is contained in:
stev 2023-09-09 23:21:43 +02:00
parent e364217734
commit 91329e6339

View file

@ -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):