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

Method run

markdown/extensions/codehilite.py:268–289  ·  view source on GitHub ↗

Find code blocks and store in `htmlStash`.

(self, root: etree.Element)

Source from the content-addressed store, hash-verified

266 return text
267
268 def run(self, root: etree.Element) -> None:
269 """ Find code blocks and store in `htmlStash`. """
270 blocks = root.iter('pre')
271 for block in blocks:
272 if len(block) == 1 and block[0].tag == 'code':
273 local_config = self.config.copy()
274 text = block[0].text
275 if text is None:
276 continue
277 code = CodeHilite(
278 self.code_unescape(text),
279 tab_length=self.md.tab_length,
280 style=local_config.pop('pygments_style', 'default'),
281 **local_config
282 )
283 placeholder = self.md.htmlStash.store(code.hilite())
284 # Clear code block in `etree` instance
285 block.clear()
286 # Change to `p` element which will later
287 # be removed when inserting raw html
288 block.tag = 'p'
289 block.text = placeholder
290
291
292class CodeHiliteExtension(Extension):

Callers

nothing calls this directly

Calls 4

code_unescapeMethod · 0.95
hiliteMethod · 0.95
CodeHiliteClass · 0.85
storeMethod · 0.80

Tested by

no test coverage detected