# HG changeset patch # User Paul Boddie # Date 1370953157 -7200 # Node ID d67ef560037e4bf1d33224c481f8e23eadae518d # Parent bd01d2ee1e8faa745c6aee31378c9c1cdf919f58 Fixed table cell text translation. Added more quoted character rules. Added table of contents macro support and support for macros without options. diff -r bd01d2ee1e8f -r d67ef560037e tests/test_links.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_links.txt Tue Jun 11 14:19:17 2013 +0200 @@ -0,0 +1,7 @@ +A normal [link] and a \[non-link\]. + +* A [link] in a list. +** A \[non-link\] in a list. + +|| [link] || \[non-link\] || +| [link] | \[non-link\] | diff -r bd01d2ee1e8f -r d67ef560037e tests/test_macros.txt --- a/tests/test_macros.txt Tue Jun 11 01:36:57 2013 +0200 +++ b/tests/test_macros.txt Tue Jun 11 14:19:17 2013 +0200 @@ -1,3 +1,5 @@ +{toc} + This is a test of {color:red}colours{color}. {code}sections featuring code{code} diff -r bd01d2ee1e8f -r d67ef560037e wikiparser.py --- a/wikiparser.py Tue Jun 11 01:36:57 2013 +0200 +++ b/wikiparser.py Tue Jun 11 14:19:17 2013 +0200 @@ -278,9 +278,9 @@ # Content inspection. monospace_regexp_str = r"{{(?P.*?)}}" -link_regexp_str = r"[[](?P.*?)]" +link_regexp_str = r"(?.*?)]" image_regexp_str = r"!(?P\w.*?)!" -macro_regexp_str = r"{(?P.*?):(?P.*?)}" +macro_regexp_str = r"{(?P.*?)(?::(?P.*?))?}" # Word-dependent patterns. # Here, the unbracketed markers must test for the absence of surrounding word @@ -367,6 +367,9 @@ (r"\\""\n", "<
>"), (r"\\ ", "<
>"), (r"\~", "~"), + (r"\[", "<>"), + (r"\]", "<>"), + (r"\*", "*"), ] preformatted_notation_mapping = [ @@ -397,6 +400,7 @@ sectiontypes = { "code" : "", + "excerpt" : "#!wiki", "noformat" : "", "quote" : "", "info" : "#!wiki important", @@ -414,6 +418,7 @@ macrotypes = { "anchor" : "<>", "color" : "<>", + "toc" : "<>", } class ConfluenceParser: @@ -527,7 +532,7 @@ if macrotypes.has_key(macro_name): argname = macroargs.get(macro_name) result = macrotypes[macro_name] % { - "args" : quote_macro_argument((argname and ("%s=" % argname) or "") + match.group("options")) + "args" : quote_macro_argument((argname and ("%s=" % argname) or "") + (match.group("options") or "")) } if not self.forbids_macros(): return result @@ -622,7 +627,7 @@ # Enter the table. - self.enter_section() + self.enter_section("table") table_parts = [] first = True