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

Method run

markdown/treeprocessors.py:432–451  ·  view source on GitHub ↗

Add line breaks to `Element` object and its children.

(self, root: etree.Element)

Source from the content-addressed store, hash-verified

430 elem.tail = i
431
432 def run(self, root: etree.Element) -> None:
433 """ Add line breaks to `Element` object and its children. """
434
435 self._prettifyETree(root)
436 # Do `<br />`'s separately as they are often in the middle of
437 # inline content and missed by `_prettifyETree`.
438 brs = root.iter('br')
439 for br in brs:
440 if not br.tail or not br.tail.strip():
441 br.tail = '\n'
442 else:
443 br.tail = '\n%s' % br.tail
444 # Clean up extra empty lines at end of code blocks.
445 pres = root.iter('pre')
446 for pre in pres:
447 if len(pre) and pre[0].tag == 'code':
448 code = pre[0]
449 # Only prettify code containing text only
450 if not len(code) and code.text is not None:
451 code.text = util.AtomicString(code.text.rstrip() + '\n')
452
453
454class UnescapeTreeprocessor(Treeprocessor):

Callers 1

testCommentPrettifyMethod · 0.95

Calls 1

_prettifyETreeMethod · 0.95

Tested by 1

testCommentPrettifyMethod · 0.76