Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Commit

Permalink
Merge pull request #228 from facelessuser/master
Browse files Browse the repository at this point in the history
Merge smarty fix
  • Loading branch information
facelessuser committed Jul 22, 2014
2 parents e3cd42d + dcab840 commit f512296
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -145,20 +147,20 @@ def _addPatterns(self, md, patterns, serie):
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'(?<!-)---(?!-)', ('&mdash;',), md)
enDashesPattern = SubstituteTextPattern(r'(?<!-)--(?!-)', ('&ndash;',), md)
md.inlinePatterns.add('smarty-em-dashes', emDashesPattern, '>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'(?<!\.)\.{3}(?!\.)', ('&hellip;',), md)
md.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '>entity')
self.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '_begin')

def educateQuotes(self, md):
patterns = (
Expand All @@ -179,12 +181,16 @@ def educateQuotes(self, md):

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):
Expand Down
5 changes: 3 additions & 2 deletions markdown/treeprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, md):
+ 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 """
Expand Down Expand Up @@ -99,9 +100,9 @@ def __handleInline(self, data, patternIndex=0):
"""
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
Expand Down
3 changes: 1 addition & 2 deletions tests/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- github
- toc
- headerid
- smarty(smart_quotes=False) # smart quotes interferes with attr_list
- smarty
- meta
- wikilinks
- admonition
Expand All @@ -45,7 +45,6 @@ title: This title will be overridden by YAML
- codehilite(guess_lang=False,pygments_style=github)

!!! Caution "Testing Note"
- `smart_quotes` is disabled in `smarty` becuase it conflicts with `attr_list` extension.
- `sane_lists` will alter the results of the second test in [Mixed Lists](#mixed-lists). When turned off, this test will have all list items mixed and aligned proper. With `sane_lists` on, some will not be recognized, and some items may be aligned in different lists.
- having `guess_lang=False` allows the testing of the selective highlighting. When omitted or set `true`, it can be expected that all of the blocks will be highlighted to some extent.
- Most tests are spot checked at this point or a link can be clicked to verify it is working.
Expand Down

0 comments on commit f512296

Please sign in to comment.