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

Method run

markdown/postprocessors.py:73–93  ·  view source on GitHub ↗

Iterate over html stash and restore html.

(self, text: str)

Source from the content-addressed store, hash-verified

71 BLOCK_LEVEL_REGEX = re.compile(r'^\<\/?([^ >]+)')
72
73 def run(self, text: str) -> str:
74 """ Iterate over html stash and restore html. """
75 def substitute_match(m: re.Match[str]) -> str:
76 if key := m.group(1):
77 wrapped = True
78 else:
79 key = m.group(2)
80 wrapped = False
81 if (key := int(key)) >= self.md.htmlStash.html_counter:
82 return m.group(0)
83 html = self.stash_to_string(self.md.htmlStash.rawHtmlBlocks[key])
84 if not wrapped or self.isblocklevel(html):
85 return pattern.sub(substitute_match, html)
86 return pattern.sub(substitute_match, f"<p>{html}</p>")
87
88 if self.md.htmlStash.html_counter:
89 base_placeholder = util.HTML_PLACEHOLDER % r'([0-9]+)'
90 pattern = re.compile(f'<p>{ base_placeholder }</p>|{ base_placeholder }')
91 return pattern.sub(substitute_match, text)
92 else:
93 return text
94
95 def isblocklevel(self, html: str) -> bool:
96 """ Check is block of HTML is block-level. """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected