From e721727476f984b7d4e991e13c80a88f3d605e4d Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 23 Feb 2013 22:59:22 -0600 Subject: [PATCH] Allow explicit setting of markdown extensions These additions are to make it easier to disable pygments or any other extension the user may not want. In the previous version, these plugins are hardcoded, but by making it a variable in the config, it is possible to not use pygments or easily load extra markdown plugins if needed; you can have multiple plugins in one virtual environment and have different configs load them as needed. In my `pelicanconf.py` I then have the following: MD_EXTENSIONS = ['extra', 'syntaxhighlighter'] where `syntaxhighlighter` is a custom markdown extension I am working on to use syntax highlighter instead of pygments for code highlighting. --- pelican/readers.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 6f99a6a1..99dc6e54 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -140,17 +140,23 @@ class RstReader(Reader): class MarkdownReader(Reader): enabled = bool(Markdown) file_extensions = ['md', 'markdown', 'mkd'] - extensions = ['codehilite', 'extra'] + default_extensions = ['codehilite', 'extra'] + + def __init__(self, *args, **kwargs): + super(MarkdownReader, self).__init__(*args, **kwargs) + self.extensions = self.settings.get('MD_EXTENSIONS', + self.default_extensions) + self.extensions.append('meta') + self._md = Markdown(extensions=self.extensions) def _parse_metadata(self, meta): """Return the dict containing document metadata""" - md = Markdown(extensions=set(self.extensions + ['meta'])) output = {} for name, value in meta.items(): name = name.lower() if name == "summary": summary_values = "\n".join(str(item) for item in value) - summary = md.convert(summary_values) + summary = self._md.convert(summary_values) output[name] = self.process_metadata(name, summary) else: output[name] = self.process_metadata(name, value[0]) @@ -160,10 +166,9 @@ class MarkdownReader(Reader): """Parse content and metadata of markdown files""" with pelican_open(source_path) as text: - md = Markdown(extensions=set(self.extensions + ['meta'])) - content = md.convert(text) + content = self._md.convert(text) - metadata = self._parse_metadata(md.Meta) + metadata = self._parse_metadata(self._md.Meta) return content, metadata