Skip to content

Instantly share code, notes, and snippets.

@jkeyes
Last active December 14, 2015 17:39
Show Gist options
  • Save jkeyes/5123992 to your computer and use it in GitHub Desktop.
Save jkeyes/5123992 to your computer and use it in GitHub Desktop.
A tagged pre block extension (1-pre.md). The `prettypre` extension inserts 'prettyprint' into the class attribute of the `pre` and if there is an additional token it inserts a language class on the `code` element (a child of `pre`) (2-pre.html). And the result after prettifying (3-pretty-pre.html).
@prettyprint python
class PrettyPreExtension (markdown.Extension):

    def extendMarkdown(self, md, md_globals):
        md.registerExtension(self)
        self.processor = PreTreeprocessor()
        self.processor.md = md
        self.processor.config = self.getConfigs()
<pre class="prettyprint"><code class="language-py">class PrettyPreExtension (markdown.Extension):
def extendMarkdown(self, md, md_globals):
md.registerExtension(self)
self.processor = PreTreeprocessor()
self.processor.md = md
self.processor.config = self.getConfigs()
</code></pre>
<pre class="prettyprint prettyprinted" style=""><code class=" language-py"><span class="kwd">class</span><span class="pln"> </span><span class="typ">PrettyPreExtension</span><span class="pln"> </span><span class="pun">(</span><span class="pln">markdown</span><span class="pun">.</span><span class="typ">Extension</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> extendMarkdown</span><span class="pun">(</span><span class="pln">self</span><span class="pun">,</span><span class="pln"> md</span><span class="pun">,</span><span class="pln"> md_globals</span><span class="pun">):</span><span class="pln">
md</span><span class="pun">.</span><span class="pln">registerExtension</span><span class="pun">(</span><span class="pln">self</span><span class="pun">)</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">processor </span><span class="pun">=</span><span class="pln"> </span><span class="typ">PreTreeprocessor</span><span class="pun">()</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">processor</span><span class="pun">.</span><span class="pln">md </span><span class="pun">=</span><span class="pln"> md
self</span><span class="pun">.</span><span class="pln">processor</span><span class="pun">.</span><span class="pln">config </span><span class="pun">=</span><span class="pln"> self</span><span class="pun">.</span><span class="pln">getConfigs</span><span class="pun">()</span></code></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment