| 610 | return True |
| 611 | |
| 612 | def run(self, parent: etree.Element, blocks: list[str]) -> None: |
| 613 | block = blocks.pop(0) |
| 614 | if block.strip(): |
| 615 | # Not a blank block. Add to parent, otherwise throw it away. |
| 616 | if self.parser.state.isstate('list'): |
| 617 | # The parent is a tight-list. |
| 618 | # |
| 619 | # Check for any children. This will likely only happen in a |
| 620 | # tight-list when a header isn't followed by a blank line. |
| 621 | # For example: |
| 622 | # |
| 623 | # * # Header |
| 624 | # Line 2 of list item - not part of header. |
| 625 | sibling = self.lastChild(parent) |
| 626 | if sibling is not None: |
| 627 | # Insert after sibling. |
| 628 | if sibling.tail: |
| 629 | sibling.tail = '{}\n{}'.format(sibling.tail, block) |
| 630 | else: |
| 631 | sibling.tail = '\n%s' % block |
| 632 | else: |
| 633 | # Append to parent.text |
| 634 | if parent.text: |
| 635 | parent.text = '{}\n{}'.format(parent.text, block) |
| 636 | else: |
| 637 | parent.text = block.lstrip() |
| 638 | else: |
| 639 | # Create a regular paragraph |
| 640 | p = etree.SubElement(parent, 'p') |
| 641 | p.text = block.lstrip() |