Substitute raw html with plain text.
(m: re.Match[str])
| 82 | def stashedHTML2text(text: str, md: Markdown, strip_entities: bool = True) -> str: |
| 83 | """ Extract raw HTML from stash, reduce to plain text and swap with placeholder. """ |
| 84 | def _html_sub(m: re.Match[str]) -> str: |
| 85 | """ Substitute raw html with plain text. """ |
| 86 | try: |
| 87 | raw = md.htmlStash.rawHtmlBlocks[int(m.group(1))] |
| 88 | except (IndexError, TypeError): # pragma: no cover |
| 89 | return m.group(0) |
| 90 | # Strip out tags and/or entities - leaving text |
| 91 | res = re.sub(r'(<[^>]+>)', '', raw) |
| 92 | if strip_entities: |
| 93 | res = re.sub(r'(&[\#a-zA-Z0-9]+;)', '', res) |
| 94 | return res |
| 95 | |
| 96 | return HTML_PLACEHOLDER_RE.sub(_html_sub, text) |
| 97 |
nothing calls this directly
no outgoing calls
no test coverage detected