Mercurial > piecrust2
changeset 1023:0302f690a4c5
formatting: Fix Smartypants option for hoedown.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 12 Dec 2017 22:45:10 -0800 |
parents | 84492d185813 |
children | 60b431c57ea9 |
files | piecrust/formatting/hoedownformatter.py |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/formatting/hoedownformatter.py Tue Dec 05 22:30:39 2017 -0800 +++ b/piecrust/formatting/hoedownformatter.py Tue Dec 12 22:45:10 2017 -0800 @@ -53,7 +53,13 @@ exts = 0 rdrf = 0 other = 0 + use_smartypants = False for n in extensions: + # Special case for Smartypants. + if n.lower() in ['smarty', 'smartypants']: + use_smartypants = True + continue + # Try an extension? e = getattr(misaka, 'EXT_' + n.upper(), None) if e is not None: @@ -102,15 +108,25 @@ renderer = misaka.HtmlRenderer(flags=rdrf) self._formatter = misaka.Markdown(renderer, extensions=(exts | other)) + if use_smartypants: + self._formatter = _SmartypantsFormatter(self._formatter, + misaka.smartypants) + ext_translate = { 'fenced_code': 'EXT_FENCED_CODE', 'footnotes': 'EXT_FOOTNOTES', 'tables': 'EXT_TABLES', 'nl2br': 'HTML_HARD_WRAP', - 'smarty': 'HTML_SMARTYPANTS', - 'smartypants': 'HTML_SMARTYPANTS', 'toc': 'HTML_TOC', 'extra': ['EXT_FENCED_CODE', 'EXT_FOOTNOTES', 'EXT_TABLES'] } + +class _SmartypantsFormatter: + def __init__(self, formatter, smartier): + self._fmt = formatter + self._sp = smartier + + def __call__(self, txt): + return self._sp(self._fmt(txt))