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

Method run

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

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

Callers 1

testCommentPrettifyMethod · 0.95

Calls 1

_prettifyETreeMethod · 0.95

Tested by 1

testCommentPrettifyMethod · 0.76