Mercurial > piecrust2
changeset 76:fdb08d986384 2.0.0-alpha2
Add SmartyPants formatting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 30 Aug 2014 17:35:11 -0700 |
parents | 1bfcdbbe2572 |
children | 25bfed36a620 |
files | piecrust/app.py piecrust/formatting/markdownformatter.py piecrust/formatting/smartypantsformatter.py piecrust/plugins/builtin.py requirements.txt setup.py |
diffstat | 6 files changed, 29 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/app.py Sat Aug 30 10:00:52 2014 -0700 +++ b/piecrust/app.py Sat Aug 30 17:35:11 2014 -0700 @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) -CACHE_VERSION = 13 +CACHE_VERSION = 14 class VariantNotFoundError(Exception):
--- a/piecrust/formatting/markdownformatter.py Sat Aug 30 10:00:52 2014 -0700 +++ b/piecrust/formatting/markdownformatter.py Sat Aug 30 17:35:11 2014 -0700 @@ -11,6 +11,7 @@ self._extensions = None def render(self, format_name, txt): + assert format_name in self.FORMAT_NAMES self._ensureInitialized() return markdown(txt, extensions=self._extensions)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/piecrust/formatting/smartypantsformatter.py Sat Aug 30 17:35:11 2014 -0700 @@ -0,0 +1,22 @@ +import smartypants +from piecrust.formatting.base import Formatter, PRIORITY_LAST + + +class SmartyPantsFormatter(Formatter): + FORMAT_NAMES = ['html'] + OUTPUT_FORMAT = 'html' + + def __init__(self): + super(SmartyPantsFormatter, self).__init__() + self.priority = PRIORITY_LAST + + def initialize(self, app): + super(SmartyPantsFormatter, self).initialize(app) + self.enabled = ( + app.config.get('smartypants/enable') or + app.config.get('smartypants/enabled')) + + def render(self, format_name, txt): + assert format_name == 'html' + return smartypants.smartypants(txt) +
--- a/piecrust/plugins/builtin.py Sat Aug 30 10:00:52 2014 -0700 +++ b/piecrust/plugins/builtin.py Sat Aug 30 17:35:11 2014 -0700 @@ -7,6 +7,7 @@ PrepareCommand, ImportCommand) from piecrust.data.provider import (IteratorDataProvider, BlogDataProvider) from piecrust.formatting.markdownformatter import MarkdownFormatter +from piecrust.formatting.smartypantsformatter import SmartyPantsFormatter from piecrust.importing.jekyll import JekyllImporter from piecrust.importing.piecrust import PieCrust1Importer from piecrust.plugins.base import PieCrustPlugin @@ -61,7 +62,8 @@ def getFormatters(self): return [ - MarkdownFormatter()] + MarkdownFormatter(), + SmartyPantsFormatter()] def getProcessors(self): return [