1.1 --- a/moinformat/macros/toc.py Wed Aug 01 15:35:40 2018 +0200
1.2 +++ b/moinformat/macros/toc.py Fri Aug 03 22:34:55 2018 +0200
1.3 @@ -20,7 +20,8 @@
1.4 """
1.5
1.6 from moinformat.macros.common import Macro
1.7 -from moinformat.tree.moin import Container, Heading, List, ListItem, Text
1.8 +from moinformat.serialisers.common import make_id
1.9 +from moinformat.tree.moin import Container, Heading, Link, List, ListItem, Text
1.10
1.11 class TableOfContents(Macro):
1.12
1.13 @@ -63,7 +64,6 @@
1.14 marker = "1."
1.15 space = " "
1.16 num = "1"
1.17 - nl = [Text("\n")]
1.18
1.19 # Start with no lists, no current item.
1.20
1.21 @@ -89,7 +89,7 @@
1.22 # level or whether there are intermediate levels being
1.23 # produced.
1.24
1.25 - nodes = level == new_level and heading.nodes[:] + nl or []
1.26 + nodes = level == new_level and self.get_entry(heading) or []
1.27 indent = level - 1
1.28
1.29 # Create a new item for the heading or sublists.
1.30 @@ -148,7 +148,7 @@
1.31
1.32 if min_level <= level <= max_level:
1.33 indent = level - 1
1.34 - nodes = heading.nodes[:] + nl
1.35 + nodes = self.get_entry(heading)
1.36
1.37 item = ListItem(nodes, indent, marker, space, None)
1.38 items.append(item)
1.39 @@ -169,6 +169,13 @@
1.40 elif isinstance(n, Container):
1.41 self.find_headings(n, headings)
1.42
1.43 + def get_entry(self, heading):
1.44 +
1.45 + "Return nodes for an entry involving 'heading'."
1.46 +
1.47 + target = make_id(heading.text_content())
1.48 + return [Link(heading.nodes[:], "#%s" % target), Text("\n")]
1.49 +
1.50 macro = TableOfContents
1.51
1.52 # vim: tabstop=4 expandtab shiftwidth=4