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

Method run

markdown/blockprocessors.py:477–501  ·  view source on GitHub ↗
(self, parent: etree.Element, blocks: list[str])

Source from the content-addressed store, hash-verified

475 return (block.startswith('#') or '\n#' in block) and bool(self.RE.search(block))
476
477 def run(self, parent: etree.Element, blocks: list[str]) -> None:
478 block = blocks.pop(0)
479 m = self.RE.search(block)
480 if m:
481 before = block[:m.start()] # All lines before header
482 after = block[m.end():] # All lines after header
483 if before:
484 # As the header was not the first line of the block and the
485 # lines before the header must be parsed first,
486 # recursively parse this lines as a block.
487 self.parser.parseBlocks(parent, [before])
488 # Create header using named groups from RE
489 h = etree.SubElement(parent, 'h%d' % len(m.group('level')))
490 h.text = m.group('header').strip()
491 if after:
492 # Insert remaining lines as first block for future parsing.
493 if self.parser.state.isstate('looselist'):
494 # This is a weird edge case where a header is a child of a loose list
495 # and there is no blank line after the header. To ensure proper
496 # parsing, the line(s) after need to be detabbed. See #1443.
497 after = self.looseDetab(after)
498 blocks.insert(0, after)
499 else: # pragma: no cover
500 # This should never happen, but just in case...
501 logger.warn("We've got a problem header: %r" % block)
502
503
504class SetextHeaderProcessor(BlockProcessor):

Callers

nothing calls this directly

Calls 4

searchMethod · 0.80
parseBlocksMethod · 0.80
isstateMethod · 0.80
looseDetabMethod · 0.80

Tested by

no test coverage detected