MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / HiliteTreeprocessor

Class HiliteTreeprocessor

markdown/extensions/codehilite.py:178–197  ·  view source on GitHub ↗

Hilight source code in code blocks.

Source from the content-addressed store, hash-verified

176
177# ------------------ The Markdown Extension -------------------------------
178class HiliteTreeprocessor(markdown.treeprocessors.Treeprocessor):
179 """ Hilight source code in code blocks. """
180
181 def run(self, root):
182 """ Find code blocks and store in htmlStash. """
183 blocks = root.getiterator('pre')
184 for block in blocks:
185 children = block.getchildren()
186 if len(children) == 1 and children[0].tag == 'code':
187 code = CodeHilite(children[0].text,
188 linenos=self.config['force_linenos'][0],
189 css_class=self.config['css_class'][0])
190 placeholder = self.markdown.htmlStash.store(code.hilite(),
191 safe=True)
192 # Clear codeblock in etree instance
193 block.clear()
194 # Change to p element which will later
195 # be removed when inserting raw html
196 block.tag = 'p'
197 block.text = placeholder
198
199
200class CodeHiliteExtension(markdown.Extension):

Callers 1

extendMarkdownMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected