Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions sswg.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def sswg_to_html(text:str):
is_in_style_tag = False
inline_images = []
code_block_id = 0
in_unordered_list = False
in_ordered_list = False
current_list_indent = 0
current_ordered_indent = 0

lines = text.split('\n')

Expand Down Expand Up @@ -164,6 +168,52 @@ def sswg_to_html(text:str):
</h3>''')
continue

if (l.strip().startswith('- ')) and not is_in_code_block:
indent_level = (len(l) - len(l.lstrip())) // 2
list_item = l.strip()[2:]

if not in_unordered_list:
new_text += '<ul>\n'
in_unordered_list = True
current_list_indent = indent_level

if indent_level > current_list_indent:
new_text += '<ul>\n'
current_list_indent = indent_level
elif indent_level < current_list_indent:
new_text += '</ul>\n'
current_list_indent = indent_level

new_text += f'<li>{list_item}</li>\n'
continue

if re.match(r'^\s*\d+\.\s+', l) and not is_in_code_block:
indent_level = (len(l) - len(l.lstrip())) // 2
list_item = re.sub(r'^\s*\d+\.\s+', '', l)

if not in_ordered_list:
new_text += '<ol>\n'
in_ordered_list = True
current_ordered_indent = indent_level

if indent_level > current_ordered_indent:
new_text += '<ol>\n'
current_ordered_indent = indent_level
elif indent_level < current_ordered_indent:
new_text += '</ol>\n'
current_ordered_indent = indent_level

new_text += f'<li>{list_item}</li>\n'
continue

if not ((l.strip().startswith('- ') or re.match(r'^\s*\d+\.\s+', l)) or l.strip() == '') and not is_in_code_block:
if in_unordered_list:
new_text += '</ul>\n'
in_unordered_list = False
if in_ordered_list:
new_text += '</ol>\n'
in_ordered_list = False

if l.startswith('#title'):
continue

Expand Down