# HG changeset patch # User Ludovic Chabant # Date 1409445311 25200 # Node ID fdb08d986384687959fe11640f058eac22c17b8f # Parent 1bfcdbbe2572ff1dea9f98117bd7f910381244a7 Add SmartyPants formatting. diff -r 1bfcdbbe2572 -r fdb08d986384 piecrust/app.py --- 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): diff -r 1bfcdbbe2572 -r fdb08d986384 piecrust/formatting/markdownformatter.py --- 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) diff -r 1bfcdbbe2572 -r fdb08d986384 piecrust/formatting/smartypantsformatter.py --- /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) + diff -r 1bfcdbbe2572 -r fdb08d986384 piecrust/plugins/builtin.py --- 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 [ diff -r 1bfcdbbe2572 -r fdb08d986384 requirements.txt --- a/requirements.txt Sat Aug 30 10:00:52 2014 -0700 +++ b/requirements.txt Sat Aug 30 17:35:11 2014 -0700 @@ -13,4 +13,5 @@ python-dateutil==2.2 repoze.lru==0.6 six==1.7.3 +smartypants==1.8.6 strict-rfc3339==0.4 diff -r 1bfcdbbe2572 -r fdb08d986384 setup.py --- a/setup.py Sat Aug 30 10:00:52 2014 -0700 +++ b/setup.py Sat Aug 30 17:35:11 2014 -0700 @@ -161,6 +161,7 @@ 'py==1.4.23', 'python-dateutil==2.2', 'repoze.lru==0.6', + 'smartypants==1.8.6', 'strict-rfc3339==0.4' ], tests_require=[