aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Altmayer <altmayer@posteo.de>2014-08-11 19:45:09 +0200
committerMartin Altmayer <altmayer@posteo.de>2014-08-11 19:45:09 +0200
commitaf85029ca443609b803ebc83e806c1ee115db900 (patch)
tree5e6a683b4d7e85daed8ac298ff9c5e57eda5a126
parent139e882437e7f3c7295973d0866afea24bbe926b (diff)
downloadmarkdown-af85029ca443609b803ebc83e806c1ee115db900.tar.gz
markdown-af85029ca443609b803ebc83e806c1ee115db900.tar.bz2
markdown-af85029ca443609b803ebc83e806c1ee115db900.zip
Replaced smart_lsquo etc. by a single option smart_substitutions which allows to overwrite all substitution strings. Fixed line length in docs.
-rw-r--r--docs/extensions/smarty.txt26
-rw-r--r--markdown/extensions/smarty.py46
2 files changed, 49 insertions, 23 deletions
diff --git a/docs/extensions/smarty.txt b/docs/extensions/smarty.txt
index 394df5c..1c21d50 100644
--- a/docs/extensions/smarty.txt
+++ b/docs/extensions/smarty.txt
@@ -22,13 +22,24 @@ ASCII symbol | Replacements | HTML Entities
`--` | &ndash; | `&ndash;`
`---` | &mdash; | `&mdash;`
-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:
+Using the configuration option 'smart_substitutions' you can overwrite the
+default substitutions. Just pass a dict mapping (a subset of) the following
+keys to the substitution strings.
+
+ 'mdash', 'ndash', 'ellipsis',
+ 'left-angle-quote', 'right-angle-quote',
+ 'left-single-quote', 'right-single-quote',
+ 'left-double-quote', 'right-double-quote'
+
+Use e.g. the following config to get correct quotes for the German language:
extensionConfigs = {
- 'smarty': [('smart_lsquo', '&sbquo;'), # sb is not a typo!
- ('smart_rsquo', '&lsquo;'),
- ('smart_ldquo', '&bdquo;'),
- ('smart_rdquo', '&ldquo;')]
+ 'smarty': [('smart_substitutions', {
+ 'left-single-quote': '&sbquo;', # sb is not a typo!
+ 'right-single-quote': '&lsquo;',
+ 'left-double-quote': '&bdquo;',
+ 'right-double-quote': '&ldquo;'
+ })]
}
!!! note
@@ -60,10 +71,7 @@ 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` | &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
+`smart_substitutions` | {} | Overwrite default substitutions
Further reading
---------------
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py
index 16d2936..cc6b694 100644
--- a/markdown/extensions/smarty.py
+++ b/markdown/extensions/smarty.py
@@ -85,7 +85,20 @@ openingQuotesBase = (
'|&[mn]dash;' # or named dash entities
'|&#8211;|&#8212;' # or decimal entities
')'
-)
+)
+
+substitutions = {
+ 'mdash': '&mdash;',
+ 'ndash': '&ndash;',
+ 'ellipsis': '&hellip;',
+ 'left-angle-quote': '&laquo;',
+ 'right-angle-quote': '&raquo;',
+ 'left-single-quote': '&lsquo;',
+ 'right-single-quote': '&rsquo;',
+ 'left-double-quote': '&ldquo;',
+ 'right-double-quote': '&rdquo;',
+}
+
# Special case if the very first character is a quote
# followed by punctuation at a non-word-break. Close the quotes by brute force:
@@ -138,12 +151,12 @@ class SmartyExtension(Extension):
'smart_angled_quotes': [False, 'Educate angled quotes'],
'smart_dashes': [True, 'Educate dashes'],
'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'],
+ 'smart_substitutions' : [{}, 'Overwrite default substitutions'],
}
super(SmartyExtension, self).__init__(*args, **kwargs)
+ self.substitutions = dict(substitutions)
+ self.substitutions.update(self.getConfig('smart_substitutions',
+ default={}))
def _addPatterns(self, md, patterns, serie):
for ind, pattern in enumerate(patterns):
@@ -154,19 +167,24 @@ class SmartyExtension(Extension):
self.inlinePatterns.add(name, pattern, after)
def educateDashes(self, md):
- emDashesPattern = SubstituteTextPattern(r'(?<!-)---(?!-)', ('&mdash;',), md)
- enDashesPattern = SubstituteTextPattern(r'(?<!-)--(?!-)', ('&ndash;',), md)
+ emDashesPattern = SubstituteTextPattern(r'(?<!-)---(?!-)',
+ (self.substitutions['mdash'],), md)
+ enDashesPattern = SubstituteTextPattern(r'(?<!-)--(?!-)',
+ (self.substitutions['ndash'],), md)
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}(?!\.)', ('&hellip;',), md)
+ ellipsesPattern = SubstituteTextPattern(r'(?<!\.)\.{3}(?!\.)',
+ (self.substitutions['ellipsis'],), md)
self.inlinePatterns.add('smarty-ellipses', ellipsesPattern, '_begin')
def educateAngledQuotes(self, md):
- leftAngledQuotePattern = SubstituteTextPattern(r'\<\<', ('&laquo;',), md)
- rightAngledQuotePattern = SubstituteTextPattern(r'\>\>', ('&raquo;',), md)
+ leftAngledQuotePattern = SubstituteTextPattern(r'\<\<',
+ (self.substitutions['left-angle-quote'],), md)
+ rightAngledQuotePattern = SubstituteTextPattern(r'\>\>',
+ (self.substitutions['right-angle-quote'],), md)
self.inlinePatterns.add('smarty-left-angle-quotes',
leftAngledQuotePattern, '_begin')
self.inlinePatterns.add('smarty-right-angle-quotes',
@@ -174,10 +192,10 @@ class SmartyExtension(Extension):
def educateQuotes(self, md):
configs = self.getConfigs()
- lsquo = configs['smart_lsquo']
- rsquo = configs['smart_rsquo']
- ldquo = configs['smart_ldquo']
- rdquo = configs['smart_rdquo']
+ lsquo = self.substitutions['left-single-quote']
+ rsquo = self.substitutions['right-single-quote']
+ ldquo = self.substitutions['left-double-quote']
+ rdquo = self.substitutions['right-double-quote']
patterns = (
(singleQuoteStartRe, (rsquo,)),
(doubleQuoteStartRe, (rdquo,)),