Mercurial > piecrust2
comparison piecrust/formatting/hoedownformatter.py @ 1023:0302f690a4c5
formatting: Fix Smartypants option for hoedown.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 12 Dec 2017 22:45:10 -0800 |
parents | 58ef814cc83e |
children | 96f1e5e377ef |
comparison
equal
deleted
inserted
replaced
1022:84492d185813 | 1023:0302f690a4c5 |
---|---|
51 # extension/render flags to make it easier to use Hoedown as a drop-in | 51 # extension/render flags to make it easier to use Hoedown as a drop-in |
52 # replacement. | 52 # replacement. |
53 exts = 0 | 53 exts = 0 |
54 rdrf = 0 | 54 rdrf = 0 |
55 other = 0 | 55 other = 0 |
56 use_smartypants = False | |
56 for n in extensions: | 57 for n in extensions: |
58 # Special case for Smartypants. | |
59 if n.lower() in ['smarty', 'smartypants']: | |
60 use_smartypants = True | |
61 continue | |
62 | |
57 # Try an extension? | 63 # Try an extension? |
58 e = getattr(misaka, 'EXT_' + n.upper(), None) | 64 e = getattr(misaka, 'EXT_' + n.upper(), None) |
59 if e is not None: | 65 if e is not None: |
60 exts |= e | 66 exts |= e |
61 continue | 67 continue |
100 exts |= misaka.EXT_NO_INTRA_EMPHASIS | 106 exts |= misaka.EXT_NO_INTRA_EMPHASIS |
101 | 107 |
102 renderer = misaka.HtmlRenderer(flags=rdrf) | 108 renderer = misaka.HtmlRenderer(flags=rdrf) |
103 self._formatter = misaka.Markdown(renderer, extensions=(exts | other)) | 109 self._formatter = misaka.Markdown(renderer, extensions=(exts | other)) |
104 | 110 |
111 if use_smartypants: | |
112 self._formatter = _SmartypantsFormatter(self._formatter, | |
113 misaka.smartypants) | |
114 | |
105 | 115 |
106 ext_translate = { | 116 ext_translate = { |
107 'fenced_code': 'EXT_FENCED_CODE', | 117 'fenced_code': 'EXT_FENCED_CODE', |
108 'footnotes': 'EXT_FOOTNOTES', | 118 'footnotes': 'EXT_FOOTNOTES', |
109 'tables': 'EXT_TABLES', | 119 'tables': 'EXT_TABLES', |
110 'nl2br': 'HTML_HARD_WRAP', | 120 'nl2br': 'HTML_HARD_WRAP', |
111 'smarty': 'HTML_SMARTYPANTS', | |
112 'smartypants': 'HTML_SMARTYPANTS', | |
113 'toc': 'HTML_TOC', | 121 'toc': 'HTML_TOC', |
114 'extra': ['EXT_FENCED_CODE', 'EXT_FOOTNOTES', 'EXT_TABLES'] | 122 'extra': ['EXT_FENCED_CODE', 'EXT_FOOTNOTES', 'EXT_TABLES'] |
115 } | 123 } |
116 | 124 |
125 | |
126 class _SmartypantsFormatter: | |
127 def __init__(self, formatter, smartier): | |
128 self._fmt = formatter | |
129 self._sp = smartier | |
130 | |
131 def __call__(self, txt): | |
132 return self._sp(self._fmt(txt)) |