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 From 445e263a0c571e465b9b03fae867eebf4004429c Mon Sep 17 00:00:00 2001 From: Andrey Rahmatullin Date: Sat, 31 May 2014 22:13:23 +0600 Subject: Fix a doctest in fenced_code.py. --- markdown/extensions/fenced_code.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index d6e043c..0bbd9e0 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -68,10 +68,10 @@ If the codehighlite extension and Pygments are installed, lines can be highlight ... line 3 ... ```''' >>> print markdown.markdown(text, extensions=['codehilite', 'fenced_code']) -
line 1
-    line 2
-    line 3
-    
+
line 1
+    line 2
+    line 3
+    
Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). -- cgit v1.2.3 From 8be0d1f517a0857b69763fd3bad1875badede2d2 Mon Sep 17 00:00:00 2001 From: Lawrence Kesteloot Date: Sat, 31 May 2014 18:58:11 -0700 Subject: Add failing unit test for smarty: ellipsis before close double quote generates opening double quote. --- tests/extensions/smarty.html | 1 + tests/extensions/smarty.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html index 6b5e698..16aba6d 100644 --- a/tests/extensions/smarty.html +++ b/tests/extensions/smarty.html @@ -13,6 +13,7 @@ one two ‘60s
‘quoted’ text and bold ‘quoted’ text
em-dashes (—) and ellipes (…)
Link” — she said.

+

“Ellipsis within quotes…”


Escaped -- ndash
'Escaped' "quotes"
diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt index fbf4d03..00dc1a2 100644 --- a/tests/extensions/smarty.txt +++ b/tests/extensions/smarty.txt @@ -15,6 +15,8 @@ It's fun. What's fun? em-dashes (---) and ellipes (...) "[Link](http://example.com)" --- she said. +"Ellipsis within quotes..." + --- -- --- Escaped \-- ndash -- cgit v1.2.3 From cd076d004e9a666c0d3e179371de40cb6ca466d2 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sun, 8 Jun 2014 15:50:02 +0400 Subject: Fix #315: Change order of smarty patterns to make the test pass again --- markdown/extensions/smarty.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index 6f15d2c..21f30a4 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -182,12 +182,12 @@ 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_dashes']: self.educateDashes(md) - if configs['smart_ellipses']: - self.educateEllipses(md) inlineProcessor = InlineProcessor(md) inlineProcessor.inlinePatterns = self.inlinePatterns md.treeprocessors.add('smarty', inlineProcessor, '_end') -- cgit v1.2.3 From ca4347ac1c596aec3635fbab634aa9e7959a2719 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Wed, 11 Jun 2014 20:48:47 +0400 Subject: Add 3.4 to list of Python versions to test with --- .travis.yml | 1 + tox.ini | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 22a5855..1f07f39 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/tox.ini b/tox.ini index fc2207a..c10eef8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26, py27, py31, py32, py33 +envlist = py26, py27, py31, py32, py33, py34 [testenv] downloadcache = {toxworkdir}/cache -- cgit v1.2.3 From 580712a84f973458ac82958c63661bfa7b709df6 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sun, 8 Jun 2014 16:19:04 +0400 Subject: Make doctests support Python 3 --- markdown/extensions/abbr.py | 2 +- markdown/extensions/fenced_code.py | 12 ++++++------ markdown/extensions/headerid.py | 12 ++++++------ markdown/extensions/meta.py | 8 ++++---- markdown/extensions/nl2br.py | 2 +- markdown/extensions/smart_strong.py | 12 ++++++------ markdown/extensions/wikilinks.py | 18 +++++++++--------- 7 files changed, 33 insertions(+), 33 deletions(-) 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']))

Some text with an ABBR and a REF. Ignore REFERENCE and ref.

Copyright 2007-2008 diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 0bbd9e0..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)

A paragraph before a fenced code block:

Fenced code block
     
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'))

A paragraph before a fenced code block:

Fenced code block
     
@@ -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']))

     ~~~~
     
@@ -43,7 +43,7 @@ Language tags: ... ~~~~{.python} ... # Some python code ... ~~~~''' - >>> print markdown.markdown(text, extensions=['fenced_code']) + >>> print(markdown.markdown(text, extensions=['fenced_code']))
# Some python code
     
@@ -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']))
# Arbitrary code
     ~~~~~ # these tildes will not close the block
     
@@ -67,7 +67,7 @@ If the codehighlite extension and Pygments are installed, lines can be highlight ... line 2 ... line 3 ... ```''' - >>> print markdown.markdown(text, extensions=['codehilite', 'fenced_code']) + >>> print(markdown.markdown(text, extensions=['codehilite', 'fenced_code']))
line 1
     line 2
     line 3
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)
     

Some Header

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)

Header

Header

Header

@@ -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)

Some Header

Next Level

@@ -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)

Some Header with markup.

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)

Some Header

Another Header

@@ -58,7 +58,7 @@ Use with MetaData extension: ... ... # A Header''' >>> md = markdown.markdown(text, ['headerid', 'meta']) - >>> print md + >>> print(md)

A Header

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))

The body. This is paragraph one.

- >>> 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

). >>> text = ' Some Code - not extra lines of meta data.' >>> md = markdown.Markdown(['meta']) - >>> print md.convert(text) + >>> print(md.convert(text))

Some Code - not extra lines of meta data.
     
>>> 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']))

line 1
line 2

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']))

Text with double__underscore__words.

- >>> print markdown.markdown('__Strong__ still works.', - ... extensions=['smart_strong']) + >>> print(markdown.markdown('__Strong__ still works.', + ... extensions=['smart_strong']))

Strong still works.

- >>> print markdown.markdown('__this__works__too__.', - ... extensions=['smart_strong']) + >>> print(markdown.markdown('__this__works__too__.', + ... extensions=['smart_strong']))

this__works__too.

Copyright 2011 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)

Some text with a WikiLink.

Whitespace behavior: - >>> print markdown.markdown('[[ foo bar_baz ]]', ['wikilinks']) + >>> print(markdown.markdown('[[ foo bar_baz ]]', ['wikilinks']))

foo bar_baz

- >>> print markdown.markdown('foo [[ ]] bar', ['wikilinks']) + >>> print(markdown.markdown('foo [[ ]] bar', ['wikilinks']))

foo bar

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)'] - ... ) + ... ))

Some text with a WikiLink.

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))

Some text with a WikiLink.

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))

Some text with a WikiLink.

MetaData should not carry over to next document: - >>> print md.convert("No [[MetaData]] here.") + >>> print(md.convert("No [[MetaData]] here."))

No MetaData here.

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]]'))

foo

From the command line: -- cgit v1.2.3 From 2d47fcedc08973b0250d29c456609c8a687037cd Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Wed, 18 Jun 2014 21:15:55 +0400 Subject: smarty: add support for angled quotes See . --- docs/extensions/smarty.txt | 24 +++++++++++++----------- markdown/extensions/smarty.py | 11 +++++++++++ tests/extensions/smarty.html | 2 ++ tests/extensions/smarty.txt | 3 +++ tests/extensions/test.cfg | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) 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/smarty.py b/markdown/extensions/smarty.py index 21f30a4..8131591 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -137,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'] } @@ -162,6 +163,14 @@ class SmartyExtension(Extension): ellipsesPattern = 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 = ( (singleQuoteStartRe, (rsquo,)), @@ -186,6 +195,8 @@ class SmartyExtension(Extension): 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) inlineProcessor = InlineProcessor(md) diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html index 16aba6d..c0459d9 100644 --- a/tests/extensions/smarty.html +++ b/tests/extensions/smarty.html @@ -14,6 +14,8 @@ one two ‘60s
em-dashes (—) and ellipes (…)
Link” — she said.

“Ellipsis within quotes…”

+

Кавычки-«ёлочки»
+Anführungszeichen-»Chevrons«


Escaped -- ndash
'Escaped' "quotes"
diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt index 00dc1a2..1cee803 100644 --- a/tests/extensions/smarty.txt +++ b/tests/extensions/smarty.txt @@ -17,6 +17,9 @@ em-dashes (---) and ellipes (...) "Ellipsis within quotes..." +Кавычки-<<ёлочки>> +Anführungszeichen->>Chevrons<< + --- -- --- Escaped \-- ndash diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index 8b0d748..c05a64e 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -40,4 +40,4 @@ extensions=nl2br,attr_list extensions=admonition [smarty] -extensions=smarty +extensions=smarty(smart_angled_quotes=1) -- cgit v1.2.3