aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile11
-rwxr-xr-xtools/trac2md.py26
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
diff --git a/Makefile b/Makefile
index 6a93ff2..789b822 100644
--- a/Makefile
+++ b/Makefile
@@ -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())