view piecrust/formatting/smartypantsformatter.py @ 440:32c7c2d219d2

performance: Refactor how data is managed to reduce copying. * Make use of `collections.abc.Mapping` to better identify things that are supposed to look like dictionaries. * Instead of handling "overlay" of data in a dict tree in each different data object, make all objects `Mapping`s and handle merging at a higher level with the new `MergedMapping` object. * Since this new object is read-only, remove the need for deep-copying of app and page configurations. * Split data classes into separate modules.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 28 Jun 2015 08:22:39 -0700
parents fdb08d986384
children 370e74941d32
line wrap: on
line source

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)