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