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