# HG changeset patch # User Paul Boddie # Date 1559251995 -7200 # Node ID aebf7d06b6cd8ddaf613cb1212d0273ac95fbb38 # Parent 9f9e706f707d78daa0b24175e1f728c8498a1e62# Parent b62d51eabb5174244e3272ec0a06ddc1064a738b Merged changes from the default branch. diff -r 9f9e706f707d -r aebf7d06b6cd moinformat/macros/toc.py --- a/moinformat/macros/toc.py Tue May 21 00:03:39 2019 +0200 +++ b/moinformat/macros/toc.py Thu May 30 23:33:15 2019 +0200 @@ -175,7 +175,7 @@ item = ListItem(nodes, indent, marker, space, None) items.append(item) - # Replace the macro node with the top-level list. + # Augment the macro node with the top-level list. self.insert_table(lists[0]) @@ -187,17 +187,15 @@ parent = macro.parent region = macro.region - # Replace the macro if it is not inside a block. - # NOTE: This attempts to avoid blocks being used in inline-only contexts - # NOTE: but may not be successful in every case. + # Set the children of this macro with the generated content. - if not isinstance(parent, Block) or parent is region: - parent.replace(macro, content) + macro.nodes = [content] + macro.inline = False # Split any block containing the macro into preceding and following # parts. - else: + if isinstance(parent, Block): following = parent.split_at(macro) # Insert any non-empty following block. @@ -207,7 +205,7 @@ # Insert the new content. - region.insert_after(parent, content) + region.insert_after(parent, macro) # Remove any empty preceding block. diff -r 9f9e706f707d -r aebf7d06b6cd moinformat/serialisers/html/moin.py --- a/moinformat/serialisers/html/moin.py Tue May 21 00:03:39 2019 +0200 +++ b/moinformat/serialisers/html/moin.py Thu May 30 23:33:15 2019 +0200 @@ -147,8 +147,9 @@ def end_listitem(self, indent, marker, space, num): self.out("") - def start_macro(self, name, args, nodes): - self.out("") + def start_macro(self, name, args, nodes, inline): + tag = inline and "span" or "div" + self.out("<%s class='macro %s'>" % (tag, escape_text(name))) # Fallback case for when macros are not replaced. @@ -167,8 +168,9 @@ self.out(")") self.out(escape_text(">>")) - def end_macro(self): - self.out("") + def end_macro(self, inline): + tag = inline and "span" or "div" + self.out("" % tag) def start_monospace(self): self.out("") diff -r 9f9e706f707d -r aebf7d06b6cd moinformat/serialisers/moin/moin.py --- a/moinformat/serialisers/moin/moin.py Tue May 21 00:03:39 2019 +0200 +++ b/moinformat/serialisers/moin/moin.py Thu May 30 23:33:15 2019 +0200 @@ -90,14 +90,14 @@ def end_listitem(self, indent, marker, space, num): pass - def start_macro(self, name, args, nodes): + def start_macro(self, name, args, nodes, inline): # Fallback case for when macros are not replaced. if not nodes: self.out("<<%s%s>>" % (name, args and "(%s)" % ",".join(args) or "")) - def end_macro(self): + def end_macro(self, inline): pass def start_monospace(self): diff -r 9f9e706f707d -r aebf7d06b6cd moinformat/themes/default/css/all-toc.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/themes/default/css/all-toc.css Thu May 30 23:33:15 2019 +0200 @@ -0,0 +1,3 @@ +.TableOfContents { + border: 1px solid #000; +} diff -r 9f9e706f707d -r aebf7d06b6cd moinformat/themes/mercurial/css/all-toc.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/themes/mercurial/css/all-toc.css Thu May 30 23:33:15 2019 +0200 @@ -0,0 +1,3 @@ +.TableOfContents { + border: 1px solid #000; +} diff -r 9f9e706f707d -r aebf7d06b6cd moinformat/tree/moin.py --- a/moinformat/tree/moin.py Tue May 21 00:03:39 2019 +0200 +++ b/moinformat/tree/moin.py Thu May 30 23:33:15 2019 +0200 @@ -575,25 +575,28 @@ "Macro details." - def __init__(self, name, args, parent, region, nodes=None): + def __init__(self, name, args, parent, region, nodes=None, inline=True): Container.__init__(self, nodes or []) self.name = name self.args = args self.parent = parent self.region = region + self.inline = inline def __repr__(self): - return "Macro(%r, %r, %r, %r, %r)" % (self.name, self.args, self.parent, self.region, self.nodes) + return "Macro(%r, %r, %r, %r, %r, %r)" % (self.name, self.args, + self.parent, self.region, + self.nodes, self.inline) def prettyprint(self, indent=""): l = ["%sMacro: name=%r args=%r" % (indent, self.name, self.args)] return self._prettyprint(l, indent) def to_string(self, out): - out.start_macro(self.name, self.args, self.nodes) + out.start_macro(self.name, self.args, self.nodes, self.inline) if self.nodes: self._to_string(out) - out.end_macro() + out.end_macro(self.inline) class Monospace(Inline): diff -r 9f9e706f707d -r aebf7d06b6cd tests/test_macros.tree-exp --- a/tests/test_macros.tree-exp Tue May 21 00:03:39 2019 +0200 +++ b/tests/test_macros.tree-exp Thu May 30 23:33:15 2019 +0200 @@ -1,28 +1,30 @@ Region - List - ListItem - Link - LinkLabel - Text - Text - List - ListItem - Link - LinkLabel - Text - Text + Macro + List + ListItem + Link + LinkLabel + Text + Text + List + ListItem + Link + LinkLabel + Text + Text Break Heading Text Break Block Text - List - ListItem - Link - LinkLabel - Text - Text + Macro + List + ListItem + Link + LinkLabel + Text + Text Block Text Break diff -r 9f9e706f707d -r aebf7d06b6cd tests/test_parser.py --- a/tests/test_parser.py Tue May 21 00:03:39 2019 +0200 +++ b/tests/test_parser.py Thu May 30 23:33:15 2019 +0200 @@ -260,7 +260,7 @@ # Read and parse the input. - s = input.readfile(text_filename, encoding) + s = input.readfile(filename, encoding) p = make_parser(metadata) d = parse(s, p)