Substitute raw html with plain text.
(m: re.Match[str])
| 104 | def stashedHTML2text(text: str, md: Markdown, strip_entities: bool = True) -> str: |
| 105 | """ Extract raw HTML from stash, reduce to plain text and swap with placeholder. """ |
| 106 | def _html_sub(m: re.Match[str]) -> str: |
| 107 | """ Substitute raw html with plain text. """ |
| 108 | try: |
| 109 | raw = md.htmlStash.rawHtmlBlocks[int(m.group(1))] |
| 110 | except (IndexError, TypeError): # pragma: no cover |
| 111 | return m.group(0) |
| 112 | # Strip out tags and/or entities - leaving text |
| 113 | res = re.sub(r'(<[^>]+>)', '', raw) |
| 114 | if strip_entities: |
| 115 | res = re.sub(r'(&[\#a-zA-Z0-9]+;)', '', res) |
| 116 | return res |
| 117 | |
| 118 | return HTML_PLACEHOLDER_RE.sub(_html_sub, text) |
| 119 |
nothing calls this directly
no outgoing calls
no test coverage detected