1.1 --- a/convert.py Sat Mar 02 19:56:23 2013 +0100
1.2 +++ b/convert.py Sun Mar 03 00:42:13 2013 +0100
1.3 @@ -165,8 +165,8 @@
1.4 try:
1.5 fn(join(versions_dir, content["content"]), body)
1.6 except:
1.7 - print >>sys.stderr, "Error parsing..."
1.8 - print >>sys.stderr, body
1.9 + err = codecs.getwriter("utf-8")(sys.stderr)
1.10 + print >>err, "Error parsing", content["content"]
1.11 raise
1.12
1.13 # Handle attachments.
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/test_macros.txt Sun Mar 03 00:42:13 2013 +0100
2.3 @@ -0,0 +1,6 @@
2.4 +This is a test of {color:red}colours{color}.
2.5 +
2.6 +{code}sections featuring code{code}
2.7 +
2.8 +{anchor:second}
2.9 +This is the second paragraph.
3.1 --- a/wikiparser.py Sat Mar 02 19:56:23 2013 +0100
3.2 +++ b/wikiparser.py Sun Mar 03 00:42:13 2013 +0100
3.3 @@ -213,8 +213,8 @@
3.4 notation_mapping = [
3.5 (r"\!", "!"),
3.6 (r"\-", "-"),
3.7 - (r"\\""\n", "<<BR>> "),
3.8 - (r"\\ ", " "),
3.9 + (r"\\""\n", "<<BR>>"),
3.10 + (r"\\ ", "<<BR>>"),
3.11 ]
3.12
3.13 # Translation helpers.
3.14 @@ -232,8 +232,8 @@
3.15 return " " * len(marker) + markers[marker[-1]]
3.16
3.17 cellseps = {
3.18 - "|" : "||",
3.19 - "||" : "||",
3.20 + "|" : "\n|| ",
3.21 + "||" : "\n|| ",
3.22 }
3.23
3.24 cellextra = {
3.25 @@ -413,9 +413,9 @@
3.26 # Handle anonymous blocks.
3.27
3.28 else:
3.29 - parts.append(translate_content(blocktext).rstrip())
3.30 + parts.append(translate_content(blocktext))
3.31
3.32 - return "\n".join(parts) + "\n"
3.33 + return "\n".join(parts)
3.34
3.35 def get_table_rows(text):
3.36
3.37 @@ -452,13 +452,18 @@
3.38 return rows
3.39
3.40 sectiontypes = {
3.41 - "code" : "",
3.42 - "noformat" : "",
3.43 - "quote" : "",
3.44 - "info" : "wiki important",
3.45 - "note" : "wiki caution",
3.46 - "tip" : "wiki tip",
3.47 - "warning" : "wiki warning",
3.48 + "code" : "",
3.49 + "noformat" : "",
3.50 + "quote" : "",
3.51 + "info" : "#!wiki important\n",
3.52 + "note" : "#!wiki caution\n",
3.53 + "tip" : "#!wiki tip\n",
3.54 + "warning" : "#!wiki warning\n",
3.55 + }
3.56 +
3.57 +macrotypes = {
3.58 + "anchor" : "<<Anchor(%s)>>",
3.59 + "color" : "<<Color(%s)>>",
3.60 }
3.61
3.62 # General parsing.
3.63 @@ -469,13 +474,28 @@
3.64
3.65 parts = []
3.66
3.67 + # Control spacing between blocks and other blocks or sections.
3.68 +
3.69 + preceded_by_block = False
3.70 +
3.71 for type, text in get_regions(s):
3.72
3.73 # Handle list, heading, blockquote or anonymous blocks.
3.74
3.75 if type is None:
3.76 + if preceded_by_block:
3.77 + parts.append("\n")
3.78 +
3.79 + first = True
3.80 for blocktype, blocktext in get_blocks(text):
3.81 - parts.append("%s\n" % translate_block(blocktype, blocktext))
3.82 + if not first:
3.83 + parts.append("\n")
3.84 + else:
3.85 + first = False
3.86 + parts.append("%s" % translate_block(blocktype, blocktext))
3.87 +
3.88 + if not first:
3.89 + preceded_by_block = True
3.90
3.91 # Handle sections.
3.92
3.93 @@ -484,15 +504,32 @@
3.94
3.95 # Direct translations of sections.
3.96
3.97 - mointype = sectiontypes.get(sectiontype)
3.98 - if mointype:
3.99 - parts.append("{{{#!%s\n" % mointype)
3.100 + if sectiontypes.has_key(sectiontype):
3.101 + if preceded_by_block:
3.102 + parts.append("\n")
3.103 + mointype = sectiontypes[sectiontype]
3.104 +
3.105 + parts.append("{{{%s" % (mointype or ""))
3.106 if options:
3.107 parts.append("## %s\n" % options)
3.108 + parts.append(translate_content(text.strip(), sectiontype))
3.109 + parts.append("}}}\n")
3.110 +
3.111 + preceded_by_block = True
3.112 +
3.113 + # Translations of macros (which can look like sections).
3.114 +
3.115 + elif macrotypes.has_key(sectiontype):
3.116 + parts.append(macrotypes[sectiontype] % translate_content(text, sectiontype))
3.117 + preceded_by_block = False
3.118 +
3.119 + # Unrecognised sections.
3.120 +
3.121 else:
3.122 parts.append("{{{")
3.123 - parts.append(translate_content(text, sectiontype))
3.124 - parts.append("}}}\n")
3.125 + parts.append(translate_content(text, sectiontype))
3.126 + parts.append("}}}")
3.127 + preceded_by_block = False
3.128
3.129 return "".join(parts)
3.130
4.1 --- a/xmlparser.py Sat Mar 02 19:56:23 2013 +0100
4.2 +++ b/xmlparser.py Sun Mar 03 00:42:13 2013 +0100
4.3 @@ -59,6 +59,7 @@
4.4 "ul" : "%s",
4.5 "ac:plain-text-body" : "{{{%s}}}",
4.6 "ac:link" : "[[%s%s|%s]]",
4.7 + "ac:image" : "{{%s%s|%s}}",
4.8 }
4.9
4.10 for tag, translation in blocktypes.items():
4.11 @@ -154,7 +155,7 @@
4.12 # Parser-related methods.
4.13
4.14 def handleElement(self, name):
4.15 - text = "".join(self.text[-1]).strip()
4.16 + text = "".join(self.text[-1])
4.17
4.18 # Handle state.
4.19
4.20 @@ -199,7 +200,7 @@
4.21 # Links require target information.
4.22 # NOTE: User links should support the intended user namespace prefix.
4.23
4.24 - if name == "ac:link":
4.25 + if name in ("ac:link", "ac:image"):
4.26 if self.target_type == "ri:attachment":
4.27 prefix = "attachment:"
4.28 elif self.target_type == "ri:user":
4.29 @@ -254,7 +255,7 @@
4.30 nodes.append("\n\n")
4.31 elif list_tags.has_key(parent):
4.32 nodes.append("\n")
4.33 - elif list_tags.has_key(name) and parent == "li":
4.34 + elif list_tags.has_key(name):
4.35 nodes.append("\n")
4.36 nodes.append(text)
4.37
4.38 @@ -269,7 +270,7 @@
4.39 # Whitespace normalisation.
4.40
4.41 def get_replacement(self, name):
4.42 - if name in ("html", "body") or list_tags.has_key(name):
4.43 + if name in ("html", "body", "table", "tbody", "tr") or list_tags.has_key(name):
4.44 return ""
4.45 else:
4.46 return " "