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

Method replace_marker

markdown/extensions/toc.py:300–319  ·  view source on GitHub ↗

Replace marker with elem.

(self, root: etree.Element, elem: etree.Element)

Source from the content-addressed store, hash-verified

298 yield from self.iterparent(child)
299
300 def replace_marker(self, root: etree.Element, elem: etree.Element) -> None:
301 """ Replace marker with elem. """
302 for (p, c) in self.iterparent(root):
303 text = ''.join(c.itertext()).strip()
304 if not text:
305 continue
306
307 # To keep the output from screwing up the
308 # validation by putting a `<div>` inside of a `<p>`
309 # we actually replace the `<p>` in its entirety.
310
311 # The `<p>` element may contain more than a single text content
312 # (`nl2br` can introduce a `<br>`). In this situation, `c.text` returns
313 # the very first content, ignore children contents or tail content.
314 # `len(c) == 0` is here to ensure there is only text in the `<p>`.
315 if c.text and c.text.strip() == self.marker and len(c) == 0:
316 for i in range(len(p)):
317 if p[i] == c:
318 p[i] = elem
319 break
320
321 def set_level(self, elem: etree.Element) -> None:
322 """ Adjust header level according to base level. """

Callers 1

runMethod · 0.95

Calls 1

iterparentMethod · 0.95

Tested by

no test coverage detected