diff options
author | Dmitry Shachnev <mitya57@gmail.com> | 2014-06-18 21:15:55 +0400 |
---|---|---|
committer | Dmitry Shachnev <mitya57@gmail.com> | 2014-06-19 09:32:32 +0400 |
commit | 2d47fcedc08973b0250d29c456609c8a687037cd (patch) | |
tree | 2e3e36c68de508f8b0681646ee9cbee0d663c1e9 | |
parent | 51857fd458c991a10c7a9d8797ba8fb03af2f4d8 (diff) | |
download | markdown-2d47fcedc08973b0250d29c456609c8a687037cd.tar.gz markdown-2d47fcedc08973b0250d29c456609c8a687037cd.tar.bz2 markdown-2d47fcedc08973b0250d29c456609c8a687037cd.zip |
smarty: add support for angled quotes
See <http://en.wikipedia.org/wiki/Guillemet>.
-rw-r--r-- | docs/extensions/smarty.txt | 24 | ||||
-rw-r--r-- | markdown/extensions/smarty.py | 11 | ||||
-rw-r--r-- | tests/extensions/smarty.html | 2 | ||||
-rw-r--r-- | tests/extensions/smarty.txt | 3 | ||||
-rw-r--r-- | 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'(?<!\.)\.{3}(?!\.)', ('…',), md) 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 = ( (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<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 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) |