diff options
author | Rob Austein <sra@hactrn.net> | 2019-03-19 17:20:12 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2019-03-19 17:20:12 +0000 |
commit | 97fc9ee04159bb55554310cf65a5843a7a5f8847 (patch) | |
tree | ca9f50b0486fbbba17b519110e1752d321c23342 | |
parent | 6ae4982696652c6cde8a9167b18a85f8d08be63f (diff) |
tags and theoretically better verbatim text handling
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 11 | ||||
-rwxr-xr-x | tools/trac2md.py | 26 |
3 files changed, 22 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bea5755 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +TAGS @@ -1,11 +1,14 @@ TRAC := $(shell find raw-wiki-dump -type f -name '*.trac') -MD := ${TRAC:.trac=.md} +OUT := ${TRAC:.trac=.md} TAGS TOOL := tools/trac2md.py -all: ${MD} +all: ${OUT} clean: - rm ${MD} + rm ${OUT} -%.md: %.trac +TAGS: ${TRAC} + etags -l none $^ + +%.md: %.trac Makefile ${TOOL} ${TOOL} $< diff --git a/tools/trac2md.py b/tools/trac2md.py index 40c09d4..01d7f41 100755 --- a/tools/trac2md.py +++ b/tools/trac2md.py @@ -115,16 +115,17 @@ def WikiToMD(content): in_list = False nested_level = 0 prev_indent = 0 - new_content = "" + new_content = [] for line in content.split('\n'): line = line.replace("\r", "") - if "{{{" in line: - code_block = True - line = line.replace("{{{", "```") - if "}}}" in line: - code_block = False - line = line.replace("}}}", "```") + while "{{{" in line or "}}}" in line: + if "{{{" in line: + code_block = True + line = line.replace("{{{", "```") + if "}}}" in line: + code_block = False + line = line.replace("}}}", "```") if not code_block: # # Convert bullet lists. The start and end of a list needs @@ -133,14 +134,14 @@ def WikiToMD(content): # if line.startswith('* '): if not in_list: - new_content = "%s\n" % (new_content) + new_content.append("\n") in_list = True line = line[1:] line = '-%s' % (line) elif line.startswith('- '): # No need to modify the line, just add the new line if not in_list: - new_content = "%s\n" % (new_content) + new_content.append("\n") in_list = True elif line.startswith(' '): # Check for nested lists @@ -161,7 +162,7 @@ def WikiToMD(content): else: if in_list: # Add the closing empty line - new_content = "%s\n" % (new_content) + new_content.append("\n") in_list = False nested_level = 0 prev_indent = 0 @@ -179,9 +180,10 @@ def WikiToMD(content): line = line.replace("'''", "**") # Convert bold text line = line.replace("''", "*") # Convert italic text - new_content = "%s%s\n" % (new_content, line) + new_content.append(line) + new_content.append("\n") - return new_content + return "".join(new_content) for f in sys.argv[1:]: d = WikiToMD(open(f, "r").read()) |