Mercurial > piecrust2
comparison piecrust/formatting/smartypantsformatter.py @ 850:370e74941d32
optimize: Only load some 3rd party packages when needed.
This commit only optimizes the Markdown, SmartyPants, and Pystache wrappers.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 29 Apr 2017 21:27:33 -0700 |
parents | fdb08d986384 |
children |
comparison
equal
deleted
inserted
replaced
849:8f8bbb2e70e1 | 850:370e74941d32 |
---|---|
1 import smartypants | |
2 from piecrust.formatting.base import Formatter, PRIORITY_LAST | 1 from piecrust.formatting.base import Formatter, PRIORITY_LAST |
3 | 2 |
4 | 3 |
5 class SmartyPantsFormatter(Formatter): | 4 class SmartyPantsFormatter(Formatter): |
6 FORMAT_NAMES = ['html'] | 5 FORMAT_NAMES = ['html'] |
8 | 7 |
9 def __init__(self): | 8 def __init__(self): |
10 super(SmartyPantsFormatter, self).__init__() | 9 super(SmartyPantsFormatter, self).__init__() |
11 self.priority = PRIORITY_LAST | 10 self.priority = PRIORITY_LAST |
12 | 11 |
12 import smartypants | |
13 self._sp = smartypants.smartypants | |
14 | |
13 def initialize(self, app): | 15 def initialize(self, app): |
14 super(SmartyPantsFormatter, self).initialize(app) | 16 super(SmartyPantsFormatter, self).initialize(app) |
15 self.enabled = ( | 17 self.enabled = ( |
16 app.config.get('smartypants/enable') or | 18 app.config.get('smartypants/enable') or |
17 app.config.get('smartypants/enabled')) | 19 app.config.get('smartypants/enabled')) |
18 | 20 |
19 def render(self, format_name, txt): | 21 def render(self, format_name, txt): |
20 assert format_name == 'html' | 22 assert format_name == 'html' |
21 return smartypants.smartypants(txt) | 23 return self._sp(txt) |
22 |