From 9d927e49d9c10fc16c6dfa4a2a96cdb6216e4e2b Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Thu, 21 Mar 2019 14:54:25 +0000 Subject: More fun with lists --- tools/trac2md.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'tools/trac2md.py') diff --git a/tools/trac2md.py b/tools/trac2md.py index 03d8861..99b7df0 100755 --- a/tools/trac2md.py +++ b/tools/trac2md.py @@ -164,29 +164,22 @@ def WikiToMD(content): # Convert bullet lists. The start and end of a list needs # an empty line. # - if line.startswith('- ') or line.startswith('* '): - # No need to modify the line, just add the new line + nested_line = line.lstrip(' ') + if nested_line.startswith('- ') or nested_line.startswith('* '): if not in_list: new_content.append("\n") - in_list = True - elif line.startswith(' '): - # Check for nested lists - nested_line = line.lstrip(' ') - if nested_line.startswith('* ') or nested_line.startswith('- '): - # Adjust the nested list level as needed - indent = len(line) - len(nested_line) - if indent > prev_indent: - nested_level += 1 - elif indent < prev_indent: - nested_level -= 1 - prev_indent = indent - - # Set the proper indentation for markdown - line = ' ' * nested_level + nested_line - else: - if in_list: - # Add the closing empty line - new_content.append("\n") + nested_level = 0 + prev_indent = 0 + in_list = True + indent = len(line) - len(nested_line) + if indent > prev_indent: + nested_level += 1 + elif indent < prev_indent: + nested_level -= 1 + prev_indent = indent + line = ' ' * nested_level + nested_line + elif in_list: + new_content.append("\n") in_list = False nested_level = 0 prev_indent = 0 -- cgit v1.2.3