Process Setext-style Headers.
| 491 | |
| 492 | |
| 493 | class 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 | |
| 516 | class HRProcessor(BlockProcessor): |
no outgoing calls
no test coverage detected
searching dependent graphs…