view piecrust/formatting/smartypantsformatter.py @ 991:1857dbd4580f

bake: Fix bugs introduced by bake optimizations, of course. - Make the execution stats JSON-serializable. - Re-add ability to differentiate between sources used during segment rendering and during layout rendering. Fixes problems with cache invalidation of pages that use other sources. - Make taxonomy-related stuff JSON-serializable.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 20 Nov 2017 23:06:47 -0800
parents 370e74941d32
children
line wrap: on
line source

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

        import smartypants
        self._sp = smartypants.smartypants

    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 self._sp(txt)