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

Function _html_sub

markdown/extensions/toc.py:106–116  ·  view source on GitHub ↗

Substitute raw html with plain text.

(m: re.Match[str])

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected