# HG changeset patch # User Paul Boddie # Date 1365968841 -7200 # Node ID e3262eb82f1d7a5978200eeb850163200b441973 # Parent d87236db28e0049bff199ceff45571714f1c40b4 Added initial newlines to sections containing newlines so that Moin can be persuaded to show them correctly. Made the test program handle UTF-8 content. diff -r d87236db28e0 -r e3262eb82f1d wikiparser.py --- a/wikiparser.py Sun Apr 14 00:42:30 2013 +0200 +++ b/wikiparser.py Sun Apr 14 21:47:21 2013 +0200 @@ -510,9 +510,16 @@ mointype = sectiontypes[sectiontype] parts.append("{{{%s" % (mointype or "")) + text = text.strip() + + # Sections containing newlines must have a separate header line. + + if options or text.find("\n") != -1: + parts.append("\n") + if options: parts.append("## %s\n" % options) - parts.append(translate_content(text.strip(), sectiontype)) + parts.append(translate_content(text, sectiontype)) parts.append("%s}}}\n" % (mointype and "\n" or "")) preceded_by_block = True @@ -527,6 +534,12 @@ else: parts.append("{{{") + + # Sections containing newlines must have a separate header line. + + if text.find("\n") != -1 and not text.startswith("\n"): + parts.append("\n") + parts.append(translate_content(text, sectiontype)) parts.append("}}}") preceded_by_block = False @@ -540,7 +553,7 @@ out.write(parse_text(s)) if __name__ == "__main__": - s = sys.stdin.read() + s = codecs.getreader("utf-8")(sys.stdin).read() out = codecs.getwriter("utf-8")(sys.stdout) parse(s, out)