Mercurial > piecrust2
view piecrust/formatting/markdownformatter.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 370e74941d32 |
children | 8adc27285d93 |
line wrap: on
line source
from piecrust.formatting.base import Formatter class MarkdownFormatter(Formatter): FORMAT_NAMES = ['markdown', 'mdown', 'md'] OUTPUT_FORMAT = 'html' def __init__(self): super(MarkdownFormatter, self).__init__() self._formatter = None def render(self, format_name, txt): assert format_name in self.FORMAT_NAMES self._ensureInitialized() return self._formatter.reset().convert(txt) def _ensureInitialized(self): if self._formatter is not None: return config = self.app.config.get('markdown') if config is None: config = {} elif not isinstance(config, dict): raise Exception("The `markdown` configuration setting must be " "a dictionary.") extensions = config.get('extensions', []) if isinstance(extensions, str): extensions = [e.strip() for e in extensions.split(',')] # Compatibility with PieCrust 1.x if config.get('use_markdown_extra'): extensions.append('extra') extension_configs = config.get('extension_configs', {}) from markdown import Markdown self._formatter = Markdown(extensions=extensions, extension_configs=extension_configs)