Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.

Commit 1f8d2e7

Browse files
committed
Fix a few parsing bugs
1 parent 5d24c70 commit 1f8d2e7

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

wikiconvert.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ def convert_file(proj_id, src_path, dst_dir):
3838
for i, line in enumerate(lines):
3939
if line.startswith("#"):
4040
meta_lines.append(line)
41-
else:
42-
assert not line.strip(), "line isn't empty in file %s %r" % (src_path, line)
43-
# TODO is it actually mandatory that a blank line separate meta text from body text?
44-
body_lines = lines[i+1:]
41+
elif line.strip():
42+
body_lines = lines[i:]
4543
break
4644
meta = {}
4745
for line in meta_lines:
@@ -56,9 +54,10 @@ def sub_pre_block(match):
5654
hash = md5(pre.encode('utf8')).hexdigest()
5755
s_from_hash[hash] = _indent(pre)
5856
return hash
59-
text = re.compile(r'^{{{\n(.*?)^}}}', re.M|re.S).sub(sub_pre_block, text)
57+
text = re.compile(r'^{{{\s*\n(.*?)^}}}', re.M|re.S).sub(sub_pre_block, text)
6058

6159
# TODO: Add support for `backtick` code quotes
60+
text = re.sub(r'{{{(.*?)}}}', r'`\1`', text)
6261

6362
# Headings.
6463
text = re.compile(r'^===(.*?)===\s*$', re.M).sub(lambda m: "### %s\n"%m.group(1).strip(), text)
@@ -132,12 +131,11 @@ def sub_link(m):
132131
#---- internal support stuff
133132

134133
def _indent(text):
135-
return ' ' + '\n '.join(text.splitlines(False))
134+
return '\n ' + '\n '.join(text.splitlines(False))
136135

137136
def _gh_page_name_from_gc_page_name(gc):
138137
"""Github (gh) Wiki page name from Google Code (gc) Wiki page name."""
139-
# FIXME: fails on all uppercase / all lowercase names (e.g. FAQ)
140-
gh = re.sub(r'([A-Z][a-z]+)', r'-\1', gc)[1:]
138+
gh = re.sub(r'([A-Za-z]+)_?', r'-\1', gc)[1:]
141139
return gh
142140

143141

0 commit comments

Comments
 (0)