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

Method run

markdown/treeprocessors.py:443–462  ·  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

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

Callers 1

testCommentPrettifyMethod · 0.95

Calls 1

_prettifyETreeMethod · 0.95

Tested by 1

testCommentPrettifyMethod · 0.76