aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2019-03-21 12:37:45 +0000
committerRob Austein <sra@hactrn.net>2019-03-21 12:37:45 +0000
commit1760ab4579fb2ba9f2321f2cd7153216593b217c (patch)
treee2f961efb36d14c85b15146049b908772f1ddc28
parentf24e937f689bb465be36685ddb032d165336191e (diff)
First cut at table conversion; more cleanup
-rwxr-xr-xtools/trac2md.py19
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)