[Cryptech-Commits] [wiki] 12/75: Fix headers, handle CamelCase escapes

git at cryptech.is git at cryptech.is
Fri Oct 8 18:51:38 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 156b5673fe5d0e6abccd53792817800ae87ca117
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Thu Mar 21 13:17:23 2019 +0000

    Fix headers, handle CamelCase escapes
---
 tools/trac2md.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/trac2md.py b/tools/trac2md.py
index 43e167a..377cf20 100755
--- a/tools/trac2md.py
+++ b/tools/trac2md.py
@@ -15,10 +15,11 @@ from datetime import datetime
 
 wikilink_pattern = re.compile('\[http(.*)\]')
 wikilink_extract = re.compile('\[(.*)\]')
-wikiheading1_pattern = re.compile('^= (.*) =$')
-wikiheading2_pattern = re.compile('^== (.*) ==$')
-wikiheading3_pattern = re.compile('^=== (.*) ===$')
 strikethrough_pattern = re.compile('~~(.*)~~')
+camelcase_pattern = re.compile("!(\w+)")
+
+wikiheading_patterns = tuple((level, re.compile("^{} (.*)[ \t]*=*$".format("=" * level)))
+                             for level in xrange(1, 7))
 
 def to_timestamp(tm):
     ''' Convert to timestamp which can be jsonified '''
@@ -54,19 +55,15 @@ def strip_wikilink(content):
 def convert_headers(line):
     ''' Convert wikiformat headers
     '''
-    level_count = 1
-    for header in [wikiheading1_pattern,
-                   wikiheading2_pattern,
-                   wikiheading3_pattern]:
+    for level_count, header in wikiheading_patterns:
         try:
             level = header.search(line).group(1)
             if level:
-                line = "%s %s" % ('#' * level_count, level)
+                line = "%s %s" % ('#' * level_count, level.rstrip("= \r\t"))
                 break  # No need to check other heading levels
         except:
             # Try the next heading level
             pass
-        level_count += 1
 
     return line
 
@@ -203,6 +200,9 @@ def WikiToMD(content):
                 nested_level = 0
                 prev_indent = 0
 
+            # Convert CamelCase
+            line = camelcase_pattern.sub("\\1", line)
+
             # Convert headers
             line = convert_headers(line)
 



More information about the Commits mailing list