Add MD_EXTENSION_CONFIGS setting

used to control Markdown extensions configuration
This commit is contained in:
Alexander Todorov 2015-11-29 00:36:52 +02:00
commit b02e0ffb07
4 changed files with 8 additions and 2 deletions

View file

@ -53,7 +53,8 @@ install Markdown``.
Pelican also supports `Markdown Extensions`_, which might have to be installed Pelican also supports `Markdown Extensions`_, which might have to be installed
separately if they are not included in the default ``Markdown`` package and can separately if they are not included in the default ``Markdown`` package and can
be configured and loaded via the ``MD_EXTENSIONS`` setting. be configured and loaded via the ``MD_EXTENSIONS`` setting. The
``MD_EXTENSION_CONFIGS`` setting controls extensions configuration.
Metadata syntax for Markdown posts should follow this pattern:: Metadata syntax for Markdown posts should follow this pattern::

View file

@ -121,6 +121,8 @@ Setting name (followed by default value, if any)
to the default values for this setting, you'll need to to the default values for this setting, you'll need to
include them explicitly and enumerate the full list of include them explicitly and enumerate the full list of
desired Markdown extensions.) desired Markdown extensions.)
``MD_EXTENSION_CONFIGS = {}`` A configuration dictionary for the extensions the Markdown
processor will use.
``OUTPUT_PATH = 'output/'`` Where to output the generated files. ``OUTPUT_PATH = 'output/'`` Where to output the generated files.
``PATH`` Path to content directory to be processed by Pelican. If undefined, ``PATH`` Path to content directory to be processed by Pelican. If undefined,
and content path is not specified via an argument to the ``pelican`` and content path is not specified via an argument to the ``pelican``

View file

@ -247,6 +247,7 @@ class MarkdownReader(BaseReader):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(MarkdownReader, self).__init__(*args, **kwargs) super(MarkdownReader, self).__init__(*args, **kwargs)
self.extensions = list(self.settings['MD_EXTENSIONS']) self.extensions = list(self.settings['MD_EXTENSIONS'])
self.extension_configs = self.settings['MD_EXTENSION_CONFIGS']
if 'meta' not in self.extensions: if 'meta' not in self.extensions:
self.extensions.append('meta') self.extensions.append('meta')
self._source_path = None self._source_path = None
@ -284,7 +285,8 @@ class MarkdownReader(BaseReader):
"""Parse content and metadata of markdown files""" """Parse content and metadata of markdown files"""
self._source_path = source_path self._source_path = source_path
self._md = Markdown(extensions=self.extensions) self._md = Markdown(extensions=self.extensions,
extension_configs=self.extension_configs)
with pelican_open(source_path) as text: with pelican_open(source_path) as text:
content = self._md.convert(text) content = self._md.convert(text)

View file

@ -102,6 +102,7 @@ DEFAULT_CONFIG = {
'DEFAULT_DATE_FORMAT': '%a %d %B %Y', 'DEFAULT_DATE_FORMAT': '%a %d %B %Y',
'DATE_FORMATS': {}, 'DATE_FORMATS': {},
'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'], 'MD_EXTENSIONS': ['codehilite(css_class=highlight)', 'extra'],
'MD_EXTENSION_CONFIGS': {},
'JINJA_EXTENSIONS': [], 'JINJA_EXTENSIONS': [],
'JINJA_FILTERS': {}, 'JINJA_FILTERS': {},
'LOG_FILTER': [], 'LOG_FILTER': [],