Store raw inline html and return a placeholder.
| 553 | |
| 554 | |
| 555 | class HtmlInlineProcessor(InlineProcessor): |
| 556 | """ Store raw inline html and return a placeholder. """ |
| 557 | def handleMatch(self, m: re.Match[str], data: str) -> tuple[str, int, int]: |
| 558 | """ Store the text of `group(1)` of a pattern and return a placeholder string. """ |
| 559 | rawhtml = self.backslash_unescape(self.unescape(m.group(1))) |
| 560 | place_holder = self.md.htmlStash.store(rawhtml) |
| 561 | return place_holder, m.start(0), m.end(0) |
| 562 | |
| 563 | def unescape(self, text: str) -> str: |
| 564 | """ Return unescaped text given text with an inline placeholder. """ |
| 565 | try: |
| 566 | stash = self.md.treeprocessors['inline'].stashed_nodes |
| 567 | except KeyError: # pragma: no cover |
| 568 | return text |
| 569 | |
| 570 | def get_stash(m: re.Match[str]) -> str: |
| 571 | id = m.group(1) |
| 572 | value = stash.get(id) |
| 573 | if value is not None: |
| 574 | try: |
| 575 | # Ensure we don't have a placeholder inside a placeholder |
| 576 | return self.unescape(self.md.serializer(value)) |
| 577 | except Exception: |
| 578 | return r'\%s' % value |
| 579 | |
| 580 | return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) |
| 581 | |
| 582 | def backslash_unescape(self, text: str) -> str: |
| 583 | """ Return text with backslash escapes undone (backslashes are restored). """ |
| 584 | try: |
| 585 | RE = self.md.treeprocessors['unescape'].RE |
| 586 | except KeyError: # pragma: no cover |
| 587 | return text |
| 588 | |
| 589 | def _unescape(m: re.Match[str]) -> str: |
| 590 | return chr(int(m.group(1))) |
| 591 | |
| 592 | return RE.sub(_unescape, text) |
| 593 | |
| 594 | |
| 595 | class AsteriskProcessor(InlineProcessor): |
no outgoing calls
no test coverage detected