diff options
-rwxr-xr-x | tools/trac2md.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/trac2md.py b/tools/trac2md.py index 85fdd79..43e167a 100755 --- a/tools/trac2md.py +++ b/tools/trac2md.py @@ -113,13 +113,15 @@ def WikiToMD(content): code_block = False in_list = False + in_table = False nested_level = 0 prev_indent = 0 old_content = content.splitlines() new_content = [] while old_content: - line = old_content.pop(0).replace("\r", "") + line = old_content.pop(0).rstrip() + tail = ["\n"] while "{{{" in line or "}}}" in line: if "{{{" in line: code_block = True @@ -147,6 +149,19 @@ def WikiToMD(content): # if the rows do anything different, ouch, because # markdown specifies in delimiter line. # + # Might do something clever with the "=" markers and + # alignment, start with just getting the basic table + # structure to something markdown will believe. + # + if not code_block and line.strip().startswith("||"): + line = line.replace("=|", "|").replace("|=", "|") + line = line.replace("||", "|") + if not in_table: + tail.append("|---" * (line.count("|") - 1) + "|\n") + in_table = True + elif not code_block and in_table and not line.strip().startswith("||"): + new_content.append("\n") + in_table = False # # Convert bullet lists. The start and end of a list needs @@ -202,7 +217,7 @@ def WikiToMD(content): line = line.replace("''", "*") # Convert italic text new_content.append(line) - new_content.append("\n") + new_content.extend(tail) return "".join(new_content) |