aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/extensions/smarty.txt13
-rw-r--r--markdown/extensions/smarty.py13
2 files changed, 23 insertions, 3 deletions
diff --git a/docs/extensions/smarty.txt b/docs/extensions/smarty.txt
index 56e9bd5..394df5c 100644
--- a/docs/extensions/smarty.txt
+++ b/docs/extensions/smarty.txt
@@ -22,6 +22,15 @@ ASCII symbol | Replacements | HTML Entities
`--` | – | `–`
`---` | — | `—`
+Using the options `smart_lsquo` etc. you can reconfigure the replacements for `'` and `"`. Use e.g. the following config to get correct quotes for the German language:
+
+ extensionConfigs = {
+ 'smarty': [('smart_lsquo', '‚'), # sb is not a typo!
+ ('smart_rsquo', '‘'),
+ ('smart_ldquo', '„'),
+ ('smart_rdquo', '“')]
+ }
+
!!! note
This extension reimplements the Python [SmartyPants]
library by intregated it into the markdown parser.
@@ -51,6 +60,10 @@ Option | Default value | Description
`smart_quotes` | enabled | whether to convert straight quotes
`smart_angled_quotes` | disabled | whether to convert angled quotes
`smart_ellipses` | enabled | whether to convert ellipses
+`smart_lsquo` | ‘ | Replacement text for single left quote
+`smart_rsquo` | ’ | Replacement text for single right quote
+`smart_ldquo` | “ | Replacement text for double left quote
+`smart_rdquo` | ” | Replacement text for double right quote
Further reading
---------------
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py
index 5a82dfd..16d2936 100644
--- a/markdown/extensions/smarty.py
+++ b/markdown/extensions/smarty.py
@@ -115,8 +115,6 @@ closingSingleQuotesRegex2 = r"(?<=%s)'(\s|s\b)" % closeClass
remainingSingleQuotesRegex = "'"
remainingDoubleQuotesRegex = '"'
-lsquo, rsquo, ldquo, rdquo = '&lsquo;', '&rsquo;', '&ldquo;', '&rdquo;'
-
class SubstituteTextPattern(HtmlPattern):
def __init__(self, pattern, replace, markdown_instance):
""" Replaces matches with some text. """
@@ -139,7 +137,11 @@ class SmartyExtension(Extension):
'smart_quotes': [True, 'Educate quotes'],
'smart_angled_quotes': [False, 'Educate angled quotes'],
'smart_dashes': [True, 'Educate dashes'],
- 'smart_ellipses': [True, 'Educate ellipses']
+ 'smart_ellipses': [True, 'Educate ellipses'],
+ 'smart_lsquo' : ['&lsquo;', 'Replacement text for single left quote'],
+ 'smart_rsquo' : ['&rsquo;', 'Replacement text for single right quote'],
+ 'smart_ldquo' : ['&ldquo;', 'Replacement text for double left quote'],
+ 'smart_rdquo' : ['&rdquo;', 'Replacement text for double right quote'],
}
super(SmartyExtension, self).__init__(*args, **kwargs)
@@ -171,6 +173,11 @@ class SmartyExtension(Extension):
rightAngledQuotePattern, '>smarty-left-angle-quotes')
def educateQuotes(self, md):
+ configs = self.getConfigs()
+ lsquo = configs['smart_lsquo']
+ rsquo = configs['smart_rsquo']
+ ldquo = configs['smart_ldquo']
+ rdquo = configs['smart_rdquo']
patterns = (
(singleQuoteStartRe, (rsquo,)),
(doubleQuoteStartRe, (rdquo,)),