From 1760ab4579fb2ba9f2321f2cd7153216593b217c Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Thu, 21 Mar 2019 12:37:45 +0000 Subject: First cut at table conversion; more cleanup --- tools/trac2md.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tools') 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) -- cgit v1.2.3