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

Class ParagraphProcessor

markdown/blockprocessors.py:607–642  ·  view source on GitHub ↗

Process Paragraph blocks.

Source from the content-addressed store, hash-verified

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

Callers 1

build_block_parserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected