aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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():])