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

Class HRProcessor

markdown/blockprocessors.py:527–558  ·  view source on GitHub ↗

Process Horizontal Rules.

Source from the content-addressed store, hash-verified

525
526
527class HRProcessor(BlockProcessor):
528 """ Process Horizontal Rules. """
529
530 # Python's `re` module doesn't officially support atomic grouping. However you can fake it.
531 # See https://stackoverflow.com/a/13577411/866026
532 RE = r'^[ ]{0,3}(?=(?P<atomicgroup>(-+[ ]{0,2}){3,}|(_+[ ]{0,2}){3,}|(\*+[ ]{0,2}){3,}))(?P=atomicgroup)[ ]*$'
533 # Detect hr on any line of a block.
534 SEARCH_RE = re.compile(RE, re.MULTILINE)
535
536 def test(self, parent: etree.Element, block: str) -> bool:
537 m = self.SEARCH_RE.search(block)
538 if m:
539 # Save match object on class instance so we can use it later.
540 self.match = m
541 return True
542 return False
543
544 def run(self, parent: etree.Element, blocks: list[str]) -> None:
545 block = blocks.pop(0)
546 match = self.match
547 # Check for lines in block before `hr`.
548 prelines = block[:match.start()].rstrip('\n')
549 if prelines:
550 # Recursively parse lines before `hr` so they get parsed first.
551 self.parser.parseBlocks(parent, [prelines])
552 # create hr
553 etree.SubElement(parent, 'hr')
554 # check for lines in block after `hr`.
555 postlines = block[match.end():].lstrip('\n')
556 if postlines:
557 # Add lines after `hr` to master blocks for later parsing.
558 blocks.insert(0, postlines)
559
560
561class EmptyBlockProcessor(BlockProcessor):

Callers 1

build_block_parserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected