1.1 --- a/moinformat/parsers/moin.py Tue Jul 17 23:31:28 2018 +0200
1.2 +++ b/moinformat/parsers/moin.py Mon Jul 23 23:52:27 2018 +0200
1.3 @@ -23,8 +23,8 @@
1.4 excl, expect, group, optional, recur, repeat
1.5 from moinformat.serialisers import serialise
1.6 from moinformat.tree import Break, DefItem, DefTerm, FontStyle, Heading, \
1.7 - Larger, Link, List, ListItem, Monospace, Region, \
1.8 - Rule, Smaller, Strikethrough, Subscript, \
1.9 + Larger, Link, List, ListItem, Macro, Monospace, \
1.10 + Region, Rule, Smaller, Strikethrough, Subscript, \
1.11 Superscript, Table, TableAttr, TableAttrs, \
1.12 TableCell, TableRow, Text, Underline
1.13
1.14 @@ -421,12 +421,6 @@
1.15 def parse_larger(self, region):
1.16 self.parse_inline(region, Larger, "larger")
1.17
1.18 - def parse_link(self, region):
1.19 - target = self.match_group("target")
1.20 - text = self.match_group("text")
1.21 - link = Link(text and [Text(text)], target)
1.22 - region.append_inline(link)
1.23 -
1.24 def parse_monospace(self, region):
1.25 span = Monospace([])
1.26 self.parse_region_details(span, ["monospaceend"])
1.27 @@ -449,6 +443,27 @@
1.28
1.29
1.30
1.31 + # Complete inline pattern handlers.
1.32 +
1.33 + def parse_link(self, region):
1.34 + target = self.match_group("target")
1.35 + text = self.match_group("text")
1.36 + link = Link(text and [Text(text)], target)
1.37 + region.append_inline(link)
1.38 +
1.39 + def parse_macro(self, region):
1.40 + name = self.match_group("name")
1.41 + args = self.match_group("args")
1.42 +
1.43 + # Obtain the raw arguments. Moin usually leaves it to the macro to
1.44 + # interpret the individual arguments.
1.45 +
1.46 + arglist = args and args.split(",") or []
1.47 + macro = Macro(name, arglist)
1.48 + region.append_inline(macro)
1.49 +
1.50 +
1.51 +
1.52 # Table attribute handlers.
1.53
1.54 def parse_table_attr(self, attrs, pattern_name):
1.55 @@ -489,7 +504,9 @@
1.56 group("args", ".*?"), "\n")), # text-excl-nl
1.57
1.58 # Region contents:
1.59 - # Line-oriented patterns:
1.60 +
1.61 + # Line-oriented patterns support features which require their own
1.62 + # separate lines.
1.63
1.64 "break" : r"^(\s*?)\n", # blank line
1.65
1.66 @@ -541,7 +558,10 @@
1.67 "tablerow" : r"^\|\|", # ||
1.68
1.69 # Region contents:
1.70 - # Inline patterns:
1.71 +
1.72 + # Inline patterns are for markup features that appear within blocks.
1.73 + # The patterns below start inline spans that can contain other markup
1.74 + # features.
1.75
1.76 "fontstyle" : group("style", repeat("'", 2, 6)), # ''...
1.77 "larger" : r"~\+", # ~+
1.78 @@ -553,14 +573,22 @@
1.79 "super" : r"\^", # ^
1.80 "underline" : r"__", # __
1.81
1.82 - # Complete inline patterns:
1.83 + # Complete inline patterns are for markup features that do not support
1.84 + # arbitrary content within them:
1.85
1.86 "link" : join((r"\[\[", # [[
1.87 group("target", ".*?"), # target
1.88 optional(join((r"\|", group("text", ".*?")))), # | text (optional)
1.89 "]]")), # ]]
1.90
1.91 - # Inline contents:
1.92 + "macro" : join(("<<", # <<
1.93 + group("name", "\w+?"), # digit-letter...
1.94 + optional(join((r"\(", # ( (optional)
1.95 + group("args", ".*?"), # not-)...
1.96 + r"\)"))), # ) (optional)
1.97 + ">>")), # >>
1.98 +
1.99 + # Ending patterns for inline features:
1.100
1.101 "largerend" : r"\+~", # +~
1.102 "monospaceend" : r"`", # `
1.103 @@ -623,7 +651,7 @@
1.104
1.105
1.106
1.107 - # Pattern details.
1.108 + # Patterns available within certain markup features.
1.109
1.110 table_pattern_names = [
1.111 "attrname", "colour", "colspan", "halign", "rowspan", "tableattrsend",
1.112 @@ -631,8 +659,8 @@
1.113 ]
1.114
1.115 inline_pattern_names = [
1.116 - "fontstyle", "larger", "link", "monospace", "regionstart", "smaller",
1.117 - "strike", "sub", "super", "underline",
1.118 + "fontstyle", "larger", "link", "macro", "monospace", "regionstart",
1.119 + "smaller", "strike", "sub", "super", "underline",
1.120 ]
1.121
1.122 list_pattern_names = [
1.123 @@ -681,6 +709,7 @@
1.124 "larger" : parse_larger,
1.125 "largerend" : end_region,
1.126 "link" : parse_link,
1.127 + "macro" : parse_macro,
1.128 "listitemend" : end_region,
1.129 "listitem" : parse_listitem,
1.130 "listitem_alpha" : parse_listitem,