aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2019-03-21 14:54:25 +0000
committerRob Austein <sra@hactrn.net>2019-03-21 14:54:25 +0000
commit9d927e49d9c10fc16c6dfa4a2a96cdb6216e4e2b (patch)
tree1285a1c90c5252b818fedf3754aac4c45271ab13 /tools
parent0e114758f6595b55eee51e498e048f2407874a5a (diff)
More fun with lists
Diffstat (limited to 'tools')
-rwxr-xr-xtools/trac2md.py35
1 files changed, 14 insertions, 21 deletions
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