# HG changeset patch # User Paul Boddie # Date 1532988442 -7200 # Node ID 966d6212d92166fd4b2288515c6cf4eec8d569fb # Parent da161661f733e13b5b3664adb1af91bc39edd36d Introduced a replace method on container nodes. Added a note to explain the preservation of the macro when generating table of contents nodes. diff -r da161661f733 -r 966d6212d921 moinformat/macros/br.py --- a/moinformat/macros/br.py Tue Jul 31 00:00:49 2018 +0200 +++ b/moinformat/macros/br.py Tue Jul 31 00:07:22 2018 +0200 @@ -32,16 +32,10 @@ "Evaluate the macro, producing a line break node." - macro = self.node - nodes = macro.parent.nodes - # Replace the macro node with the line break. - try: - i = nodes.index(macro) - nodes[i] = LineBreak() - except ValueError: - pass + macro = self.node + macro.parent.replace(macro, LineBreak()) macro = LineBreakMacro diff -r da161661f733 -r 966d6212d921 moinformat/macros/toc.py --- a/moinformat/macros/toc.py Tue Jul 31 00:00:49 2018 +0200 +++ b/moinformat/macros/toc.py Tue Jul 31 00:07:22 2018 +0200 @@ -134,6 +134,7 @@ items.append(item) # Replace the macro node's children with the top-level list. + # The macro cannot be replaced because it will be appearing inline. self.node.nodes = [lists[0]] diff -r da161661f733 -r 966d6212d921 moinformat/tree/moin.py --- a/moinformat/tree/moin.py Tue Jul 31 00:00:49 2018 +0200 +++ b/moinformat/tree/moin.py Tue Jul 31 00:07:22 2018 +0200 @@ -106,6 +106,13 @@ if text: self.append(text) + def replace(self, old, new): + + "Replace 'old' with 'new' in the children." + + i = self.nodes.index(old) + self.nodes[i] = new + def __str__(self): return self.prettyprint()