Store raw inline html and return a placeholder.
| 501 | |
| 502 | |
| 503 | class HtmlInlineProcessor(InlineProcessor): |
| 504 | """ Store raw inline html and return a placeholder. """ |
| 505 | def handleMatch(self, m: re.Match[str], data: str) -> tuple[str, int, int]: |
| 506 | """ Store the text of `group(1)` of a pattern and return a placeholder string. """ |
| 507 | rawhtml = self.backslash_unescape(self.unescape(m.group(1))) |
| 508 | place_holder = self.md.htmlStash.store(rawhtml) |
| 509 | return place_holder, m.start(0), m.end(0) |
| 510 | |
| 511 | def unescape(self, text: str) -> str: |
| 512 | """ Return unescaped text given text with an inline placeholder. """ |
| 513 | try: |
| 514 | stash = self.md.treeprocessors['inline'].stashed_nodes |
| 515 | except KeyError: # pragma: no cover |
| 516 | return text |
| 517 | |
| 518 | def get_stash(m: re.Match[str]) -> str: |
| 519 | id = m.group(1) |
| 520 | value = stash.get(id) |
| 521 | if value is not None: |
| 522 | try: |
| 523 | # Ensure we don't have a placeholder inside a placeholder |
| 524 | return self.unescape(self.md.serializer(value)) |
| 525 | except Exception: |
| 526 | return r'\%s' % value |
| 527 | |
| 528 | return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) |
| 529 | |
| 530 | def backslash_unescape(self, text: str) -> str: |
| 531 | """ Return text with backslash escapes undone (backslashes are restored). """ |
| 532 | try: |
| 533 | RE = self.md.treeprocessors['unescape'].RE |
| 534 | except KeyError: # pragma: no cover |
| 535 | return text |
| 536 | |
| 537 | def _unescape(m: re.Match[str]) -> str: |
| 538 | return chr(int(m.group(1))) |
| 539 | |
| 540 | return RE.sub(_unescape, text) |
| 541 | |
| 542 | |
| 543 | class AsteriskProcessor(InlineProcessor): |
no outgoing calls
no test coverage detected