MCPcopy
hub / github.com/Python-Markdown/markdown / SetextHeaderProcessor

Class SetextHeaderProcessor

markdown/blockprocessors.py:493–513  ·  view source on GitHub ↗

Process Setext-style Headers.

Source from the content-addressed store, hash-verified

491
492
493class SetextHeaderProcessor(BlockProcessor):
494 """ Process Setext-style Headers. """
495
496 # Detect Setext-style header. Must be first 2 lines of block.
497 RE = re.compile(r'^.*?\n[=-]+[ ]*(\n|$)', re.MULTILINE)
498
499 def test(self, parent: etree.Element, block: str) -> bool:
500 return bool(self.RE.match(block))
501
502 def run(self, parent: etree.Element, blocks: list[str]) -> None:
503 lines = blocks.pop(0).split('\n')
504 # Determine level. `=` is 1 and `-` is 2.
505 if lines[1].startswith('='):
506 level = 1
507 else:
508 level = 2
509 h = etree.SubElement(parent, 'h%d' % level)
510 h.text = lines[0].strip()
511 if len(lines) > 2:
512 # Block contains additional lines. Add to master blocks for later.
513 blocks.insert(0, '\n'.join(lines[2:]))
514
515
516class HRProcessor(BlockProcessor):

Callers 1

build_block_parserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…