diff options
Diffstat (limited to 'markdown_extensions/fenced_code.py')
-rw-r--r-- | markdown_extensions/fenced_code.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/markdown_extensions/fenced_code.py b/markdown_extensions/fenced_code.py index c3d9f7f..1825106 100644 --- a/markdown_extensions/fenced_code.py +++ b/markdown_extensions/fenced_code.py @@ -16,12 +16,12 @@ This extension adds Fenced Code Blocks to Python-Markdown. ... ''' >>> html = markdown.markdown(text, extensions=['fenced_code']) >>> html - u'<p>A paragraph before a fenced code block:\\n</p>\\n<pre><code>Fenced code block\\n</code></pre>' + u'<p>A paragraph before a fenced code block:</p>\\n<pre><code>Fenced code block\\n</code></pre>' Works with safe_mode also (we check this because we are using the HtmlStash): >>> markdown.markdown(text, extensions=['fenced_code'], safe_mode='replace') - u'<p>A paragraph before a fenced code block:\\n</p>\\n<pre><code>Fenced code block\\n</code></pre>' + u'<p>A paragraph before a fenced code block:</p>\\n<pre><code>Fenced code block\\n</code></pre>' Include tilde's in a code block and wrap with blank lines: @@ -47,6 +47,17 @@ Multiple blocks and language tags: >>> markdown.markdown(text, extensions=['fenced_code']) u'<pre><code class="python">block one\\n</code></pre>\\n\\n<pre><code class="html"><p>block two</p>\\n</code></pre>' +Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). + +Project website: <http://www.freewisdom.org/project/python-markdown/Fenced__Code__Blocks> +Contact: markdown@freewisdom.org + +License: BSD (see ../docs/LICENSE for details) + +Dependencies: +* [Python 2.3+](http://python.org) +* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/) + """ import markdown, re @@ -65,9 +76,9 @@ class FencedCodeExtension(markdown.Extension): def extendMarkdown(self, md, md_globals): """ Add FencedBlockPreprocessor to the Markdown instance. """ - FENCED_BLOCK_PREPROCESSOR = FencedBlockPreprocessor() - FENCED_BLOCK_PREPROCESSOR.md = md - md.textPreprocessors.insert(0, FENCED_BLOCK_PREPROCESSOR) + md.textPreprocessors.add('fenced_code_block', + FencedBlockPreprocessor(md), + "_begin") class FencedBlockPreprocessor(markdown.TextPreprocessor): @@ -81,7 +92,7 @@ class FencedBlockPreprocessor(markdown.TextPreprocessor): if m.group('lang'): lang = LANG_TAG % m.group('lang') code = CODE_WRAP % (lang, self._escape(m.group('code'))) - placeholder = self.md.htmlStash.store(code, safe=True) + placeholder = self.markdown.htmlStash.store(code, safe=True) text = '%s\n%s\n%s'% (text[:m.start()], placeholder, text[m.end():]) else: break |