From 663546de4cb60a51b04704ef080387ca8eca62a2 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Tue, 6 May 2014 21:21:39 +0400 Subject: Add smarty to extensions for attr_list test To make it easier to notice (and fix) the failure. --- tests/extensions/test.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index 494d79b..8b0d748 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -1,5 +1,5 @@ [attr_list] -extensions=attr_list,def_list +extensions=attr_list,def_list,smarty [codehilite] extensions=codehilite -- cgit v1.2.3 From 54527a062fd4fe861a59cc994535f01acbf8d643 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Mon, 26 May 2014 10:47:35 +0400 Subject: Make it easier to override list of inline patterns for InlineProcessor --- markdown/treeprocessors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index ef0a2aa..32b73b1 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -53,6 +53,7 @@ class InlineProcessor(Treeprocessor): + len(self.__placeholder_suffix) self.__placeholder_re = util.INLINE_PLACEHOLDER_RE self.markdown = md + self.inlinePatterns = md.inlinePatterns def __makePlaceholder(self, type): """ Generate a placeholder """ @@ -99,9 +100,9 @@ class InlineProcessor(Treeprocessor): """ if not isinstance(data, util.AtomicString): startIndex = 0 - while patternIndex < len(self.markdown.inlinePatterns): + while patternIndex < len(self.inlinePatterns): data, matched, startIndex = self.__applyPattern( - self.markdown.inlinePatterns.value_for_index(patternIndex), + self.inlinePatterns.value_for_index(patternIndex), data, patternIndex, startIndex) if not matched: patternIndex += 1 -- cgit v1.2.3 From 47ec0cb1ea31125da1481fb82319f0a1cdfd20e1 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Mon, 26 May 2014 10:44:56 +0400 Subject: Make smarty extension use its own InlineProcessor --- markdown/extensions/smarty.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index 2f946f8..6f15d2c 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -68,6 +68,8 @@ from __future__ import unicode_literals from . import Extension from ..inlinepatterns import HtmlPattern +from ..odict import OrderedDict +from ..treeprocessors import InlineProcessor from ..util import parseBoolValue # Constants for quote education. @@ -145,20 +147,20 @@ class SmartyExtension(Extension): for ind, pattern in enumerate(patterns): pattern += (md,) pattern = SubstituteTextPattern(*pattern) - after = ('>smarty-%s-%d' % (serie, ind - 1) if ind else '>entity') + after = ('>smarty-%s-%d' % (serie, ind - 1) if ind else '_begin') name = 'smarty-%s-%d' % (serie, ind) - md.inlinePatterns.add(name, pattern, after) + self.inlinePatterns.add(name, pattern, after) def educateDashes(self, md): emDashesPattern = SubstituteTextPattern(r'(?entity') - md.inlinePatterns.add('smarty-en-dashes', enDashesPattern, + self.inlinePatterns.add('smarty-em-dashes', emDashesPattern, '_begin') + self.inlinePatterns.add('smarty-en-dashes', enDashesPattern, '>smarty-em-dashes') def educateEllipses(self, md): ellipsesPattern = SubstituteTextPattern(r'(?entity') + self.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '_begin') def educateQuotes(self, md): patterns = ( @@ -179,12 +181,16 @@ class SmartyExtension(Extension): def extendMarkdown(self, md, md_globals): configs = self.getConfigs() + self.inlinePatterns = OrderedDict() if configs['smart_quotes']: self.educateQuotes(md) if configs['smart_dashes']: self.educateDashes(md) if configs['smart_ellipses']: self.educateEllipses(md) + inlineProcessor = InlineProcessor(md) + inlineProcessor.inlinePatterns = self.inlinePatterns + md.treeprocessors.add('smarty', inlineProcessor, '_end') md.ESCAPED_CHARS.extend(['"', "'"]) def makeExtension(configs=None): -- cgit v1.2.3