From 018dd886d3500090dec57fcf0de92b91fa3201f0 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 19 Aug 2013 19:04:06 -0400 Subject: 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. --- markdown/extensions/fenced_code.py | 19 +++++++++---------- 1 file 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^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P.*?)(?<=\n)(?P=fence)[ ]*$', - re.MULTILINE|re.DOTALL - ) -CODE_WRAP = '
%s
' -LANG_TAG = ' class="%s"' class FencedCodeExtension(Extension): @@ -100,6 +93,12 @@ class FencedCodeExtension(Extension): class FencedBlockPreprocessor(Preprocessor): + FENCED_BLOCK_RE = re.compile( \ + r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_+-]*)\}?)?[ ]*\n(?P.*?)(?<=\n)(?P=fence)[ ]*$', + re.MULTILINE|re.DOTALL + ) + CODE_WRAP = '
%s
' + 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():]) -- cgit v1.2.3