[Cryptech-Commits] [wiki] 11/75: First cut at table conversion; more cleanup

git at cryptech.is git at cryptech.is
Fri Oct 8 18:51:37 UTC 2021


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch production
in repository wiki.

commit 1760ab4579fb2ba9f2321f2cd7153216593b217c
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Thu Mar 21 12:37:45 2019 +0000

    First cut at table conversion; more cleanup
---
 tools/trac2md.py | 19 +++++++++++++++++--
 1 file 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)
 



More information about the Commits mailing list