Add line breaks to `Element` object and its children.
(self, root: etree.Element)
| 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 | |
| 461 | class UnescapeTreeprocessor(Treeprocessor): |