diff options
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | docs/extensions/smarty.txt | 24 | ||||
-rw-r--r-- | markdown/extensions/abbr.py | 2 | ||||
-rw-r--r-- | markdown/extensions/fenced_code.py | 20 | ||||
-rw-r--r-- | markdown/extensions/headerid.py | 12 | ||||
-rw-r--r-- | markdown/extensions/meta.py | 8 | ||||
-rw-r--r-- | markdown/extensions/nl2br.py | 2 | ||||
-rw-r--r-- | markdown/extensions/smart_strong.py | 12 | ||||
-rw-r--r-- | markdown/extensions/smarty.py | 31 | ||||
-rw-r--r-- | markdown/extensions/wikilinks.py | 18 | ||||
-rw-r--r-- | markdown/treeprocessors.py | 5 | ||||
-rw-r--r-- | tests/extensions/smarty.html | 3 | ||||
-rw-r--r-- | tests/extensions/smarty.txt | 5 | ||||
-rw-r--r-- | tests/extensions/test.cfg | 4 | ||||
-rw-r--r-- | tox.ini | 2 |
15 files changed, 89 insertions, 60 deletions
diff --git a/.travis.yml b/.travis.yml index 7471163..1931a20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ env: - TOXENV=py27 - TOXENV=py32 - TOXENV=py33 + - TOXENV=py34 before_install: - sudo apt-get update -qq - sudo apt-get install libtidy-0.99-0 diff --git a/docs/extensions/smarty.txt b/docs/extensions/smarty.txt index b96b82e..56e9bd5 100644 --- a/docs/extensions/smarty.txt +++ b/docs/extensions/smarty.txt @@ -15,11 +15,12 @@ their HTML entity equivalents. ASCII symbol | Replacements | HTML Entities ------------ | --------------- | ------------------- -' | ‘ ’ | `‘` `’` -" | “ ” | `“` `”` -\... | … | `…` -\-- | – | `–` --\-- | — | `—` +`'` | ‘ ’ | `‘` `’` +`"` | “ ” | `“` `”` +`<< >>` | « » | `«` `»` +`...` | … | `…` +`--` | – | `–` +`---` | — | `—` !!! note This extension reimplements the Python [SmartyPants] @@ -42,13 +43,14 @@ as the name of the extension. See the [Library Reference](../reference.html#extensions) for information about configuring extensions. -The following options are provided to configure the output (all three are set to `True` by default): +The following options are provided to configure the output: -Option | Description ------- | ----------- -`smart_dashes` | whether to convert dashes -`smart_quotes` | whether to convert quotes -`smart_ellipses` | whether to convert ellipses +Option | Default value | Description +------ | ------------- | ----------- +`smart_dashes` | enabled | whether to convert dashes +`smart_quotes` | enabled | whether to convert straight quotes +`smart_angled_quotes` | disabled | whether to convert angled quotes +`smart_ellipses` | enabled | whether to convert ellipses Further reading --------------- diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py index 3f8a443..bed3bb4 100644 --- a/markdown/extensions/abbr.py +++ b/markdown/extensions/abbr.py @@ -13,7 +13,7 @@ Simple Usage: ... *[ABBR]: Abbreviation ... *[REF]: Abbreviation Reference ... """ - >>> print markdown.markdown(text, ['abbr']) + >>> print(markdown.markdown(text, ['abbr'])) <p>Some text with an <abbr title="Abbreviation">ABBR</abbr> and a <abbr title="Abbreviation Reference">REF</abbr>. Ignore REFERENCE and ref.</p> Copyright 2007-2008 diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index d6e043c..fe1559c 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -13,14 +13,14 @@ This extension adds Fenced Code Blocks to Python-Markdown. ... ~~~ ... ''' >>> html = markdown.markdown(text, extensions=['fenced_code']) - >>> print html + >>> print(html) <p>A paragraph before a fenced code block:</p> <pre><code>Fenced code block </code></pre> Works with safe_mode also (we check this because we are using the HtmlStash): - >>> print markdown.markdown(text, extensions=['fenced_code'], safe_mode='replace') + >>> print(markdown.markdown(text, extensions=['fenced_code'], safe_mode='replace')) <p>A paragraph before a fenced code block:</p> <pre><code>Fenced code block </code></pre> @@ -32,7 +32,7 @@ Include tilde's in a code block and wrap with blank lines: ... ... ~~~~ ... ~~~~~~~~''' - >>> print markdown.markdown(text, extensions=['fenced_code']) + >>> print(markdown.markdown(text, extensions=['fenced_code'])) <pre><code> ~~~~ </code></pre> @@ -43,7 +43,7 @@ Language tags: ... ~~~~{.python} ... # Some python code ... ~~~~''' - >>> print markdown.markdown(text, extensions=['fenced_code']) + >>> print(markdown.markdown(text, extensions=['fenced_code'])) <pre><code class="python"># Some python code </code></pre> @@ -54,7 +54,7 @@ Optionally backticks instead of tildes as per how github's code block markdown i ... # Arbitrary code ... ~~~~~ # these tildes will not close the block ... `````''' - >>> print markdown.markdown(text, extensions=['fenced_code']) + >>> print(markdown.markdown(text, extensions=['fenced_code'])) <pre><code># Arbitrary code ~~~~~ # these tildes will not close the block </code></pre> @@ -67,11 +67,11 @@ If the codehighlite extension and Pygments are installed, lines can be highlight ... line 2 ... line 3 ... ```''' - >>> print markdown.markdown(text, extensions=['codehilite', 'fenced_code']) - <pre><code><span class="hilight">line 1</span> - line 2 - <span class="hilight">line 3</span> - </code></pre> + >>> print(markdown.markdown(text, extensions=['codehilite', 'fenced_code'])) + <div class="codehilite"><pre><span class="hll"><span class="n">line</span> <span class="mi">1</span> + </span><span class="n">line</span> <span class="mi">2</span> + <span class="hll"><span class="n">line</span> <span class="mi">3</span> + </span></pre></div> Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). diff --git a/markdown/extensions/headerid.py b/markdown/extensions/headerid.py index 8221fe1..07351cc 100644 --- a/markdown/extensions/headerid.py +++ b/markdown/extensions/headerid.py @@ -9,7 +9,7 @@ Basic usage: >>> import markdown >>> text = "# Some Header #" >>> md = markdown.markdown(text, ['headerid']) - >>> print md + >>> print(md) <h1 id="some-header">Some Header</h1> All header IDs are unique: @@ -19,7 +19,7 @@ All header IDs are unique: ... #Header ... #Header''' >>> md = markdown.markdown(text, ['headerid']) - >>> print md + >>> print(md) <h1 id="header">Header</h1> <h1 id="header_1">Header</h1> <h1 id="header_2">Header</h1> @@ -30,7 +30,7 @@ To fit within a html template's hierarchy, set the header base level: ... #Some Header ... ## Next Level''' >>> md = markdown.markdown(text, ['headerid(level=3)']) - >>> print md + >>> print(md) <h3 id="some-header">Some Header</h3> <h4 id="next-level">Next Level</h4> @@ -38,7 +38,7 @@ Works with inline markup. >>> text = '#Some *Header* with [markup](http://example.com).' >>> md = markdown.markdown(text, ['headerid']) - >>> print md + >>> print(md) <h1 id="some-header-with-markup">Some <em>Header</em> with <a href="http://example.com">markup</a>.</h1> Turn off auto generated IDs: @@ -47,7 +47,7 @@ Turn off auto generated IDs: ... # Some Header ... # Another Header''' >>> md = markdown.markdown(text, ['headerid(forceid=False)']) - >>> print md + >>> print(md) <h1>Some Header</h1> <h1>Another Header</h1> @@ -58,7 +58,7 @@ Use with MetaData extension: ... ... # A Header''' >>> md = markdown.markdown(text, ['headerid', 'meta']) - >>> print md + >>> print(md) <h2>A Header</h2> Copyright 2007-2011 [Waylan Limberg](http://achinghead.com/). diff --git a/markdown/extensions/meta.py b/markdown/extensions/meta.py index c4a4b21..9063188 100644 --- a/markdown/extensions/meta.py +++ b/markdown/extensions/meta.py @@ -15,16 +15,16 @@ Basic Usage: ... The body. This is paragraph one. ... ''' >>> md = markdown.Markdown(['meta']) - >>> print md.convert(text) + >>> print(md.convert(text)) <p>The body. This is paragraph one.</p> - >>> print md.Meta - {u'blank_data': [u''], u'author': [u'Waylan Limberg', u'John Doe'], u'title': [u'A Test Doc.']} + >>> print(md.Meta) # doctest: +SKIP + {'blank_data': [''], 'author': ['Waylan Limberg', 'John Doe'], 'title': ['A Test Doc.']} Make sure text without Meta Data still works (markdown < 1.6b returns a <p>). >>> text = ' Some Code - not extra lines of meta data.' >>> md = markdown.Markdown(['meta']) - >>> print md.convert(text) + >>> print(md.convert(text)) <pre><code>Some Code - not extra lines of meta data. </code></pre> >>> md.Meta diff --git a/markdown/extensions/nl2br.py b/markdown/extensions/nl2br.py index da4b339..028561c 100644 --- a/markdown/extensions/nl2br.py +++ b/markdown/extensions/nl2br.py @@ -8,7 +8,7 @@ GitHub-flavored Markdown does. Usage: >>> import markdown - >>> print markdown.markdown('line 1\\nline 2', extensions=['nl2br']) + >>> print(markdown.markdown('line 1\\nline 2', extensions=['nl2br'])) <p>line 1<br /> line 2</p> diff --git a/markdown/extensions/smart_strong.py b/markdown/extensions/smart_strong.py index 4818cf9..c7ac9f1 100644 --- a/markdown/extensions/smart_strong.py +++ b/markdown/extensions/smart_strong.py @@ -7,14 +7,14 @@ This extention adds smarter handling of double underscores within words. Simple Usage: >>> import markdown - >>> print markdown.markdown('Text with double__underscore__words.', - ... extensions=['smart_strong']) + >>> print(markdown.markdown('Text with double__underscore__words.', + ... extensions=['smart_strong'])) <p>Text with double__underscore__words.</p> - >>> print markdown.markdown('__Strong__ still works.', - ... extensions=['smart_strong']) + >>> print(markdown.markdown('__Strong__ still works.', + ... extensions=['smart_strong'])) <p><strong>Strong</strong> still works.</p> - >>> print markdown.markdown('__this__works__too__.', - ... extensions=['smart_strong']) + >>> print(markdown.markdown('__this__works__too__.', + ... extensions=['smart_strong'])) <p><strong>this__works__too</strong>.</p> Copyright 2011 diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index 2f946f8..8131591 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. @@ -135,6 +137,7 @@ class SmartyExtension(Extension): def __init__(self, configs): self.config = { 'smart_quotes': [True, 'Educate quotes'], + 'smart_angled_quotes': [False, 'Educate angled quotes'], 'smart_dashes': [True, 'Educate dashes'], 'smart_ellipses': [True, 'Educate ellipses'] } @@ -145,20 +148,28 @@ 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'(?<!-)---(?!-)', ('—',), md) enDashesPattern = SubstituteTextPattern(r'(?<!-)--(?!-)', ('–',), 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}(?!\.)', ('…',), md) - md.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '>entity') + self.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '_begin') + + def educateAngledQuotes(self, md): + leftAngledQuotePattern = SubstituteTextPattern(r'\<\<', ('«',), md) + rightAngledQuotePattern = SubstituteTextPattern(r'\>\>', ('»',), md) + self.inlinePatterns.add('smarty-left-angle-quotes', + leftAngledQuotePattern, '_begin') + self.inlinePatterns.add('smarty-right-angle-quotes', + rightAngledQuotePattern, '>smarty-left-angle-quotes') def educateQuotes(self, md): patterns = ( @@ -179,12 +190,18 @@ class SmartyExtension(Extension): def extendMarkdown(self, md, md_globals): configs = self.getConfigs() + self.inlinePatterns = OrderedDict() + if configs['smart_ellipses']: + self.educateEllipses(md) if configs['smart_quotes']: self.educateQuotes(md) + if configs['smart_angled_quotes']: + self.educateAngledQuotes(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): diff --git a/markdown/extensions/wikilinks.py b/markdown/extensions/wikilinks.py index ba1947c..6d34173 100644 --- a/markdown/extensions/wikilinks.py +++ b/markdown/extensions/wikilinks.py @@ -9,21 +9,21 @@ Basic usage: >>> import markdown >>> text = "Some text with a [[WikiLink]]." >>> html = markdown.markdown(text, ['wikilinks']) - >>> print html + >>> print(html) <p>Some text with a <a class="wikilink" href="/WikiLink/">WikiLink</a>.</p> Whitespace behavior: - >>> print markdown.markdown('[[ foo bar_baz ]]', ['wikilinks']) + >>> print(markdown.markdown('[[ foo bar_baz ]]', ['wikilinks'])) <p><a class="wikilink" href="/foo_bar_baz/">foo bar_baz</a></p> - >>> print markdown.markdown('foo [[ ]] bar', ['wikilinks']) + >>> print(markdown.markdown('foo [[ ]] bar', ['wikilinks'])) <p>foo bar</p> To define custom settings the simple way: - >>> print markdown.markdown(text, + >>> print(markdown.markdown(text, ... ['wikilinks(base_url=/wiki/,end_url=.html,html_class=foo)'] - ... ) + ... )) <p>Some text with a <a class="foo" href="/wiki/WikiLink.html">WikiLink</a>.</p> Custom settings the complex way: @@ -35,7 +35,7 @@ Custom settings the complex way: ... ('end_url', '.html'), ... ('html_class', '') ]}, ... safe_mode = True) - >>> print md.convert(text) + >>> print(md.convert(text)) <p>Some text with a <a href="http://example.com/WikiLink.html">WikiLink</a>.</p> Use MetaData with mdx_meta.py (Note the blank html_class in MetaData): @@ -46,12 +46,12 @@ Use MetaData with mdx_meta.py (Note the blank html_class in MetaData): ... ... Some text with a [[WikiLink]].""" >>> md = markdown.Markdown(extensions=['meta', 'wikilinks']) - >>> print md.convert(text) + >>> print(md.convert(text)) <p>Some text with a <a href="http://example.com/WikiLink.html">WikiLink</a>.</p> MetaData should not carry over to next document: - >>> print md.convert("No [[MetaData]] here.") + >>> print(md.convert("No [[MetaData]] here.")) <p>No <a class="wikilink" href="/MetaData/">MetaData</a> here.</p> Define a custom URL builder: @@ -60,7 +60,7 @@ Define a custom URL builder: ... return '/bar/' >>> md = markdown.Markdown(extensions=['wikilinks'], ... extension_configs={'wikilinks' : [('build_url', my_url_builder)]}) - >>> print md.convert('[[foo]]') + >>> print(md.convert('[[foo]]')) <p><a class="wikilink" href="/bar/">foo</a></p> From the command line: 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 diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html index 6b5e698..c0459d9 100644 --- a/tests/extensions/smarty.html +++ b/tests/extensions/smarty.html @@ -13,6 +13,9 @@ one two ‘60s<br /> ‘quoted’ text and <strong>bold ‘quoted’ text</strong><br /> em-dashes (—) and ellipes (…)<br /> “<a href="http://example.com">Link</a>” — she said.</p> +<p>“Ellipsis within quotes…”</p> +<p>Кавычки-«ёлочки»<br /> +Anführungszeichen-»Chevrons«</p> <hr /> <p>Escaped -- ndash<br /> 'Escaped' "quotes"<br /> diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt index fbf4d03..1cee803 100644 --- a/tests/extensions/smarty.txt +++ b/tests/extensions/smarty.txt @@ -15,6 +15,11 @@ It's fun. What's fun? em-dashes (---) and ellipes (...) "[Link](http://example.com)" --- she said. +"Ellipsis within quotes..." + +Кавычки-<<ёлочки>> +Anführungszeichen->>Chevrons<< + --- -- --- Escaped \-- ndash diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index 494d79b..c05a64e 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 @@ -40,4 +40,4 @@ extensions=nl2br,attr_list extensions=admonition [smarty] -extensions=smarty +extensions=smarty(smart_angled_quotes=1) @@ -1,5 +1,5 @@ [tox] -envlist = py26, py27, py31, py32, py33 +envlist = py26, py27, py31, py32, py33, py34 [testenv] downloadcache = {toxworkdir}/cache |