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

Method build_toc_div

markdown/extensions/toc.py:356–385  ·  view source on GitHub ↗

Return a string div given a toc list.

(self, toc_list: list)

Source from the content-addressed store, hash-verified

354 c.append(permalink)
355
356 def build_toc_div(self, toc_list: list) -> etree.Element:
357 """ Return a string div given a toc list. """
358 div = etree.Element("div")
359 div.attrib["class"] = self.toc_class
360
361 # Add title to the div
362 if self.title:
363 header = etree.SubElement(div, "span")
364 if self.title_class:
365 header.attrib["class"] = self.title_class
366 header.text = self.title
367
368 def build_etree_ul(toc_list: list, parent: etree.Element) -> etree.Element:
369 ul = etree.SubElement(parent, "ul")
370 for item in toc_list:
371 # List item link, to be inserted into the toc div
372 li = etree.SubElement(ul, "li")
373 link = etree.SubElement(li, "a")
374 link.text = item.get('name', '')
375 link.attrib["href"] = '#' + item.get('id', '')
376 if item['children']:
377 build_etree_ul(item['children'], li)
378 return ul
379
380 build_etree_ul(toc_list, div)
381
382 if 'prettify' in self.md.treeprocessors:
383 self.md.treeprocessors['prettify'].run(div)
384
385 return div
386
387 def run(self, doc: etree.Element) -> None:
388 # Get a list of id attributes

Callers 1

runMethod · 0.95

Calls 1

runMethod · 0.45

Tested by

no test coverage detected