aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2013-08-19 19:04:06 -0400
committerWaylan Limberg <waylan@gmail.com>2013-08-19 19:04:06 -0400
commit018dd886d3500090dec57fcf0de92b91fa3201f0 (patch)
treeb42a7a8128f6c460c7efe1a84c9b9b2a54f163bf
parentdf657a917a6ad9c79ee5bf9e4a109282ed905c2a (diff)
downloadmarkdown-018dd886d3500090dec57fcf0de92b91fa3201f0.tar.gz
markdown-018dd886d3500090dec57fcf0de92b91fa3201f0.tar.bz2
markdown-018dd886d3500090dec57fcf0de92b91fa3201f0.zip
Allow fenced_code to be configurable in subclasses.
Not sure why I was using global variables here. Anyway. Fixed now. Thanks to Andrew for pointing it out.
-rw-r--r--markdown/extensions/fenced_code.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py
index ecdb20d..c5aaa6a 100644
--- a/markdown/extensions/fenced_code.py
+++ b/markdown/extensions/fenced_code.py
@@ -80,13 +80,6 @@ from ..preprocessors import Preprocessor
from .codehilite import CodeHilite, CodeHiliteExtension
import re
-# Global vars
-FENCED_BLOCK_RE = re.compile( \
- r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P<code>.*?)(?<=\n)(?P=fence)[ ]*$',
- re.MULTILINE|re.DOTALL
- )
-CODE_WRAP = '<pre><code%s>%s</code></pre>'
-LANG_TAG = ' class="%s"'
class FencedCodeExtension(Extension):
@@ -100,6 +93,12 @@ class FencedCodeExtension(Extension):
class FencedBlockPreprocessor(Preprocessor):
+ FENCED_BLOCK_RE = re.compile( \
+ r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P<code>.*?)(?<=\n)(?P=fence)[ ]*$',
+ re.MULTILINE|re.DOTALL
+ )
+ CODE_WRAP = '<pre><code%s>%s</code></pre>'
+ LANG_TAG = ' class="%s"'
def __init__(self, md):
super(FencedBlockPreprocessor, self).__init__(md)
@@ -121,11 +120,11 @@ class FencedBlockPreprocessor(Preprocessor):
text = "\n".join(lines)
while 1:
- m = FENCED_BLOCK_RE.search(text)
+ m = self.FENCED_BLOCK_RE.search(text)
if m:
lang = ''
if m.group('lang'):
- lang = LANG_TAG % m.group('lang')
+ lang = self.LANG_TAG % m.group('lang')
# If config is not empty, then the codehighlite extension
# is enabled, so we call it to highlite the code
@@ -140,7 +139,7 @@ class FencedBlockPreprocessor(Preprocessor):
code = highliter.hilite()
else:
- code = CODE_WRAP % (lang, self._escape(m.group('code')))
+ code = self.CODE_WRAP % (lang, self._escape(m.group('code')))
placeholder = self.markdown.htmlStash.store(code, safe=True)
text = '%s\n%s\n%s'% (text[:m.start()], placeholder, text[m.end():])