MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / stashedHTML2text

Function stashedHTML2text

markdown/extensions/toc.py:104–118  ·  view source on GitHub ↗

Extract raw HTML from stash, reduce to plain text and swap with placeholder.

(text: str, md: Markdown, strip_entities: bool = True)

Source from the content-addressed store, hash-verified

102
103@deprecated('Use `run_postprocessors`, `render_inner_html` and/or `striptags` instead.')
104def 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
120
121def unescape(text: str) -> str:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected