From 5fa785408f45e5bb9e80811593d04a4a032e31c4 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Sun, 1 Jul 2018 11:50:06 +0200 Subject: [PATCH] Add title to table of contents - Remove unused method build_toc_etree() - Force string in run() method to avoid inserting gettext_lazy objects into the ElementTree structures --- src/wiki/conf/settings.py | 3 +++ src/wiki/plugins/macros/mdx/toc.py | 24 ++++-------------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/wiki/conf/settings.py b/src/wiki/conf/settings.py index 4c444f27..8ea34ab6 100644 --- a/src/wiki/conf/settings.py +++ b/src/wiki/conf/settings.py @@ -60,6 +60,9 @@ MARKDOWN_KWARGS = { 'markdown.extensions.abbr', 'markdown.extensions.sane_lists', ], + 'extension_configs': { + 'wiki.plugins.macros.mdx.toc': {'title': _('Table of Contents')}, + }, } MARKDOWN_KWARGS.update(getattr(django_settings, 'WIKI_MARKDOWN_KWARGS', {})) diff --git a/src/wiki/plugins/macros/mdx/toc.py b/src/wiki/plugins/macros/mdx/toc.py index 21782cbf..3012b483 100644 --- a/src/wiki/plugins/macros/mdx/toc.py +++ b/src/wiki/plugins/macros/mdx/toc.py @@ -15,26 +15,10 @@ def wiki_slugify(*args, **kwargs): class WikiTreeProcessorClass(TocTreeprocessor): - def build_toc_etree(self, div, toc_list): - # Add title to the div - if self.config["title"]: - header = etree.SubElement(div, "span") - header.attrib["class"] = "toctitle" - header.text = self.config["title"] - - def build_etree_ul(toc_list, parent): - ul = etree.SubElement(parent, "ul") - for item in toc_list: - # List item link, to be inserted into the toc div - li = etree.SubElement(ul, "li") - link = etree.SubElement(li, "a") - link.text = item.get('name', '') - link.attrib["href"] = '#' + item.get('id', '') - if item['children']: - build_etree_ul(item['children'], li) - return ul - - return build_etree_ul(toc_list, div) + def run(self, doc): + if self.title: + self.title = str(self.title) + super().run(doc) class WikiTocExtension(TocExtension): -- 2.45.2