Process Setext-style Headers.
| 502 | |
| 503 | |
| 504 | class SetextHeaderProcessor(BlockProcessor): |
| 505 | """ Process Setext-style Headers. """ |
| 506 | |
| 507 | # Detect Setext-style header. Must be first 2 lines of block. |
| 508 | RE = re.compile(r'^.*?\n(?:=+|-+)[ ]*(\n|$)', re.MULTILINE) |
| 509 | |
| 510 | def test(self, parent: etree.Element, block: str) -> bool: |
| 511 | return bool(self.RE.match(block)) |
| 512 | |
| 513 | def run(self, parent: etree.Element, blocks: list[str]) -> None: |
| 514 | lines = blocks.pop(0).split('\n', 2) |
| 515 | # Determine level. `=` is 1 and `-` is 2. |
| 516 | if lines[1].startswith('='): |
| 517 | level = 1 |
| 518 | else: |
| 519 | level = 2 |
| 520 | h = etree.SubElement(parent, 'h%d' % level) |
| 521 | h.text = lines[0].strip() |
| 522 | if len(lines) > 2: |
| 523 | # Block contains additional lines. Add to master blocks for later. |
| 524 | blocks.insert(0, lines[2]) |
| 525 | |
| 526 | |
| 527 | class HRProcessor(BlockProcessor): |
no outgoing calls
no test coverage detected