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