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

Function _html_sub

markdown/extensions/toc.py:84–94  ·  view source on GitHub ↗

Substitute raw html with plain text.

(m: re.Match[str])

Source from the content-addressed store, hash-verified

82def 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected