aboutsummaryrefslogtreecommitdiffstats
path: root/markdown_extensions/fenced_code.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2008-10-13 22:37:36 -0400
committerWaylan Limberg <waylan@gmail.com>2008-10-13 22:37:36 -0400
commit1a4a66feea2faf8fe12138b25a96d516ee8aed4e (patch)
treeb793b8918bb7819ecf518e88767c0fa6f17f42d1 /markdown_extensions/fenced_code.py
parent1f675dafafe4c50552f0d28ed6efaf164492e6e2 (diff)
downloadmarkdown-1a4a66feea2faf8fe12138b25a96d516ee8aed4e.tar.gz
markdown-1a4a66feea2faf8fe12138b25a96d516ee8aed4e.tar.bz2
markdown-1a4a66feea2faf8fe12138b25a96d516ee8aed4e.zip
Updated the Fenced_Code extension to recent refactor.
Diffstat (limited to 'markdown_extensions/fenced_code.py')
-rw-r--r--markdown_extensions/fenced_code.py23
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">&lt;p&gt;block two&lt;/p&gt;\\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