MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / build_toc_div

Method build_toc_div

markdown/extensions/toc.py:334–363  ·  view source on GitHub ↗

Return a string div given a toc list.

(self, toc_list: list)

Source from the content-addressed store, hash-verified

332 c.append(permalink)
333
334 def build_toc_div(self, toc_list: list) -> etree.Element:
335 """ Return a string div given a toc list. """
336 div = etree.Element("div")
337 div.attrib["class"] = self.toc_class
338
339 # Add title to the div
340 if self.title:
341 header = etree.SubElement(div, "span")
342 if self.title_class:
343 header.attrib["class"] = self.title_class
344 header.text = self.title
345
346 def build_etree_ul(toc_list: list, parent: etree.Element) -> etree.Element:
347 ul = etree.SubElement(parent, "ul")
348 for item in toc_list:
349 # List item link, to be inserted into the toc div
350 li = etree.SubElement(ul, "li")
351 link = etree.SubElement(li, "a")
352 link.text = item.get('name', '')
353 link.attrib["href"] = '#' + item.get('id', '')
354 if item['children']:
355 build_etree_ul(item['children'], li)
356 return ul
357
358 build_etree_ul(toc_list, div)
359
360 if 'prettify' in self.md.treeprocessors:
361 self.md.treeprocessors['prettify'].run(div)
362
363 return div
364
365 def run(self, doc: etree.Element) -> None:
366 # Get a list of id attributes

Callers 1

runMethod · 0.95

Calls 1

runMethod · 0.45

Tested by

no test coverage detected