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

Class EmptyBlockProcessor

markdown/blockprocessors.py:561–585  ·  view source on GitHub ↗

Process blocks that are empty or start with an empty line.

Source from the content-addressed store, hash-verified

559
560
561class EmptyBlockProcessor(BlockProcessor):
562 """ Process blocks that are empty or start with an empty line. """
563
564 def test(self, parent: etree.Element, block: str) -> bool:
565 return not block or block.startswith('\n')
566
567 def run(self, parent: etree.Element, blocks: list[str]) -> None:
568 block = blocks.pop(0)
569 filler = '\n\n'
570 if block:
571 # Starts with empty line
572 # Only replace a single line.
573 filler = '\n'
574 # Save the rest for later.
575 theRest = block[1:]
576 if theRest:
577 # Add remaining lines to master blocks for later.
578 blocks.insert(0, theRest)
579 sibling = self.lastChild(parent)
580 if (sibling is not None and sibling.tag == 'pre' and
581 len(sibling) and sibling[0].tag == 'code'):
582 # Last block is a code block. Append to preserve whitespace.
583 sibling[0].text = util.AtomicString(
584 '{}{}'.format(sibling[0].text, filler)
585 )
586
587
588class ReferenceProcessor(BlockProcessor):

Callers 1

build_block_parserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected