OLD | NEW |
(Empty) | |
| 1 ''' |
| 2 Smart_Strong Extension for Python-Markdown |
| 3 ========================================== |
| 4 |
| 5 This extention adds smarter handling of double underscores within words. |
| 6 |
| 7 Simple Usage: |
| 8 |
| 9 >>> import markdown |
| 10 >>> print markdown.markdown('Text with double__underscore__words.', |
| 11 ... extensions=['smart_strong']) |
| 12 <p>Text with double__underscore__words.</p> |
| 13 >>> print markdown.markdown('__Strong__ still works.', |
| 14 ... extensions=['smart_strong']) |
| 15 <p><strong>Strong</strong> still works.</p> |
| 16 >>> print markdown.markdown('__this__works__too__.', |
| 17 ... extensions=['smart_strong']) |
| 18 <p><strong>this__works__too</strong>.</p> |
| 19 |
| 20 Copyright 2011 |
| 21 [Waylan Limberg](http://achinghead.com) |
| 22 |
| 23 ''' |
| 24 |
| 25 from __future__ import absolute_import |
| 26 from __future__ import unicode_literals |
| 27 from . import Extension |
| 28 from ..inlinepatterns import SimpleTagPattern |
| 29 |
| 30 SMART_STRONG_RE = r'(?<!\w)(_{2})(?!_)(.+?)(?<!_)\2(?!\w)' |
| 31 STRONG_RE = r'(\*{2})(.+?)\2' |
| 32 |
| 33 class SmartEmphasisExtension(Extension): |
| 34 """ Add smart_emphasis extension to Markdown class.""" |
| 35 |
| 36 def extendMarkdown(self, md, md_globals): |
| 37 """ Modify inline patterns. """ |
| 38 md.inlinePatterns['strong'] = SimpleTagPattern(STRONG_RE, 'strong') |
| 39 md.inlinePatterns.add('strong2', SimpleTagPattern(SMART_STRONG_RE, 'stro
ng'), '>emphasis2') |
| 40 |
| 41 def makeExtension(configs={}): |
| 42 return SmartEmphasisExtension(configs=dict(configs)) |
OLD | NEW |