1.1 --- a/moinformat/macros/toc.py Tue May 21 00:03:39 2019 +0200
1.2 +++ b/moinformat/macros/toc.py Thu May 30 23:33:15 2019 +0200
1.3 @@ -175,7 +175,7 @@
1.4 item = ListItem(nodes, indent, marker, space, None)
1.5 items.append(item)
1.6
1.7 - # Replace the macro node with the top-level list.
1.8 + # Augment the macro node with the top-level list.
1.9
1.10 self.insert_table(lists[0])
1.11
1.12 @@ -187,17 +187,15 @@
1.13 parent = macro.parent
1.14 region = macro.region
1.15
1.16 - # Replace the macro if it is not inside a block.
1.17 - # NOTE: This attempts to avoid blocks being used in inline-only contexts
1.18 - # NOTE: but may not be successful in every case.
1.19 + # Set the children of this macro with the generated content.
1.20
1.21 - if not isinstance(parent, Block) or parent is region:
1.22 - parent.replace(macro, content)
1.23 + macro.nodes = [content]
1.24 + macro.inline = False
1.25
1.26 # Split any block containing the macro into preceding and following
1.27 # parts.
1.28
1.29 - else:
1.30 + if isinstance(parent, Block):
1.31 following = parent.split_at(macro)
1.32
1.33 # Insert any non-empty following block.
1.34 @@ -207,7 +205,7 @@
1.35
1.36 # Insert the new content.
1.37
1.38 - region.insert_after(parent, content)
1.39 + region.insert_after(parent, macro)
1.40
1.41 # Remove any empty preceding block.
1.42
2.1 --- a/moinformat/serialisers/html/moin.py Tue May 21 00:03:39 2019 +0200
2.2 +++ b/moinformat/serialisers/html/moin.py Thu May 30 23:33:15 2019 +0200
2.3 @@ -147,8 +147,9 @@
2.4 def end_listitem(self, indent, marker, space, num):
2.5 self.out("</li>")
2.6
2.7 - def start_macro(self, name, args, nodes):
2.8 - self.out("<span class='macro'>")
2.9 + def start_macro(self, name, args, nodes, inline):
2.10 + tag = inline and "span" or "div"
2.11 + self.out("<%s class='macro %s'>" % (tag, escape_text(name)))
2.12
2.13 # Fallback case for when macros are not replaced.
2.14
2.15 @@ -167,8 +168,9 @@
2.16 self.out(")")
2.17 self.out(escape_text(">>"))
2.18
2.19 - def end_macro(self):
2.20 - self.out("</span>")
2.21 + def end_macro(self, inline):
2.22 + tag = inline and "span" or "div"
2.23 + self.out("</%s>" % tag)
2.24
2.25 def start_monospace(self):
2.26 self.out("<tt>")
3.1 --- a/moinformat/serialisers/moin/moin.py Tue May 21 00:03:39 2019 +0200
3.2 +++ b/moinformat/serialisers/moin/moin.py Thu May 30 23:33:15 2019 +0200
3.3 @@ -90,14 +90,14 @@
3.4 def end_listitem(self, indent, marker, space, num):
3.5 pass
3.6
3.7 - def start_macro(self, name, args, nodes):
3.8 + def start_macro(self, name, args, nodes, inline):
3.9
3.10 # Fallback case for when macros are not replaced.
3.11
3.12 if not nodes:
3.13 self.out("<<%s%s>>" % (name, args and "(%s)" % ",".join(args) or ""))
3.14
3.15 - def end_macro(self):
3.16 + def end_macro(self, inline):
3.17 pass
3.18
3.19 def start_monospace(self):
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/moinformat/themes/default/css/all-toc.css Thu May 30 23:33:15 2019 +0200
4.3 @@ -0,0 +1,3 @@
4.4 +.TableOfContents {
4.5 + border: 1px solid #000;
4.6 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/moinformat/themes/mercurial/css/all-toc.css Thu May 30 23:33:15 2019 +0200
5.3 @@ -0,0 +1,3 @@
5.4 +.TableOfContents {
5.5 + border: 1px solid #000;
5.6 +}
6.1 --- a/moinformat/tree/moin.py Tue May 21 00:03:39 2019 +0200
6.2 +++ b/moinformat/tree/moin.py Thu May 30 23:33:15 2019 +0200
6.3 @@ -575,25 +575,28 @@
6.4
6.5 "Macro details."
6.6
6.7 - def __init__(self, name, args, parent, region, nodes=None):
6.8 + def __init__(self, name, args, parent, region, nodes=None, inline=True):
6.9 Container.__init__(self, nodes or [])
6.10 self.name = name
6.11 self.args = args
6.12 self.parent = parent
6.13 self.region = region
6.14 + self.inline = inline
6.15
6.16 def __repr__(self):
6.17 - return "Macro(%r, %r, %r, %r, %r)" % (self.name, self.args, self.parent, self.region, self.nodes)
6.18 + return "Macro(%r, %r, %r, %r, %r, %r)" % (self.name, self.args,
6.19 + self.parent, self.region,
6.20 + self.nodes, self.inline)
6.21
6.22 def prettyprint(self, indent=""):
6.23 l = ["%sMacro: name=%r args=%r" % (indent, self.name, self.args)]
6.24 return self._prettyprint(l, indent)
6.25
6.26 def to_string(self, out):
6.27 - out.start_macro(self.name, self.args, self.nodes)
6.28 + out.start_macro(self.name, self.args, self.nodes, self.inline)
6.29 if self.nodes:
6.30 self._to_string(out)
6.31 - out.end_macro()
6.32 + out.end_macro(self.inline)
6.33
6.34 class Monospace(Inline):
6.35
8.1 --- a/tests/test_parser.py Tue May 21 00:03:39 2019 +0200
8.2 +++ b/tests/test_parser.py Thu May 30 23:33:15 2019 +0200
8.3 @@ -260,7 +260,7 @@
8.4
8.5 # Read and parse the input.
8.6
8.7 - s = input.readfile(text_filename, encoding)
8.8 + s = input.readfile(filename, encoding)
8.9 p = make_parser(metadata)
8.10 d = parse(s, p)
8.11