From 35dba138e0b3dc0f3ff58eae413f059ab68f57b3 Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Mon, 14 Mar 2016 20:37:27 +0100 Subject: [PATCH 1/5] Replaces MD_EXTENSIONS with MARKDOWN MARKDOWN allows to configure the python markdown module fixes #1024 --- pelican/readers.py | 15 +++++++++++---- pelican/settings.py | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index f130991f..e54aa4e0 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -246,8 +246,16 @@ class MarkdownReader(BaseReader): def __init__(self, *args, **kwargs): super(MarkdownReader, self).__init__(*args, **kwargs) - self.extensions = self.settings['MD_EXTENSIONS'] - self.extensions.setdefault('markdown.extensions.meta', {}) + # make sure 'extension_configs' exists and + # and either way 'markdown.extensions.meta' must be in there + settings = self.settings['MARKDOWN'] + settings.setdefault('extension_configs', {}) + settings['extension_configs'].setdefault( + 'markdown.extensions.meta', {}) + settings.setdefault('extensions', []) + settings['extensions'].extend( + list(settings['extension_configs'].keys())) + settings['extensions'] = list(set(settings['extensions'])) self._source_path = None def _parse_metadata(self, meta): @@ -283,8 +291,7 @@ class MarkdownReader(BaseReader): """Parse content and metadata of markdown files""" self._source_path = source_path - self._md = Markdown(extensions=self.extensions.keys(), - extension_configs=self.extensions) + self._md = Markdown(**self.settings['MARKDOWN']) with pelican_open(source_path) as text: content = self._md.convert(text) diff --git a/pelican/settings.py b/pelican/settings.py index f1142077..14ddb8ba 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -101,10 +101,12 @@ DEFAULT_CONFIG = { 'PELICAN_CLASS': 'pelican.Pelican', 'DEFAULT_DATE_FORMAT': '%a %d %B %Y', 'DATE_FORMATS': {}, - 'MD_EXTENSIONS': { - 'markdown.extensions.codehilite': {'css_class': 'highlight'}, - 'markdown.extensions.extra': {}, - 'markdown.extensions.meta': {}, + 'MARKDOWN': { + 'extension_configs': { + 'markdown.extensions.codehilite': {'css_class': 'highlight'}, + 'markdown.extensions.extra': {}, + 'markdown.extensions.meta': {}, + }, }, 'JINJA_EXTENSIONS': [], 'JINJA_FILTERS': {}, @@ -368,13 +370,11 @@ def configure_settings(settings): PATH_KEY) settings[PATH_KEY] = DEFAULT_CONFIG[PATH_KEY] - # Save people from declaring MD_EXTENSIONS as a list rather than a dict - if not isinstance(settings.get('MD_EXTENSIONS', {}), dict): - logger.warning('The format of the MD_EXTENSIONS setting has ' - 'changed. It should now be a dict mapping ' - 'fully-qualified extension names to their ' - 'configurations. Falling back to the default.') - settings['MD_EXTENSIONS'] = DEFAULT_CONFIG['MD_EXTENSIONS'] + # Deprecated warning of MD_EXTENSIONS + if 'MD_EXTENSIONS' in settings: + logger.warning('MD_EXTENSIONS is deprecated use MARKDOWN ' + 'instead. Falling back to the default.') + settings['MARKDOWN'] = DEFAULT_CONFIG['MARKDOWN'] # Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES mutually_exclusive = ('ARTICLE', 'PAGE') From 9e399e7a0536894349b94d86b81a6645108b9a75 Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Mon, 14 Mar 2016 20:37:54 +0100 Subject: [PATCH 2/5] Updates test cases to use MARKDOWN --- pelican/tests/test_pelican.py | 9 ++++----- pelican/tests/test_readers.py | 10 ++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pelican/tests/test_pelican.py b/pelican/tests/test_pelican.py index 75d644bc..ea28e021 100644 --- a/pelican/tests/test_pelican.py +++ b/pelican/tests/test_pelican.py @@ -208,18 +208,17 @@ class TestPelican(LoggedTestCase): msg="Writing .*", level=logging.INFO) - def test_md_extensions_list_deprecation(self): - """Test that a warning is issued if MD_EXTENSIONS is a list""" + def test_md_extensions_deprecation(self): + """Test that a warning is issued if MD_EXTENSIONS is used""" settings = read_settings(path=None, override={ 'PATH': INPUT_PATH, 'OUTPUT_PATH': self.temp_path, 'CACHE_PATH': self.temp_cache, - 'MD_EXTENSIONS': ['meta'], + 'MD_EXTENSIONS': {}, }) pelican = Pelican(settings=settings) mute(True)(pelican.run)() - self.assertIsInstance(pelican.settings['MD_EXTENSIONS'], dict) self.assertLogCountEqual( count=1, - msg="The format of the MD_EXTENSIONS setting has changed", + msg="MD_EXTENSIONS is deprecated use MARKDOWN instead.", level=logging.WARNING) diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py index 43279179..89c3dd61 100644 --- a/pelican/tests/test_readers.py +++ b/pelican/tests/test_readers.py @@ -482,10 +482,12 @@ class MdReaderTest(ReaderTest): # expected page = self.read_file( path='article_with_markdown_markup_extensions.md', - MD_EXTENSIONS={ - 'markdown.extensions.toc': {}, - 'markdown.extensions.codehilite': {}, - 'markdown.extensions.extra': {} + MARKDOWN={ + 'extension_configs': { + 'markdown.extensions.toc': {}, + 'markdown.extensions.codehilite': {}, + 'markdown.extensions.extra': {} + } } ) expected = ('
\n' From 114e64dcf7e65145bc2b79afcb3df939c4f0cb4f Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Tue, 1 Nov 2016 13:02:22 +0100 Subject: [PATCH 3/5] doc: updates MARKDOWN --- THANKS | 1 + docs/changelog.rst | 1 + docs/content.rst | 2 +- docs/settings.rst | 17 +++++++++-------- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/THANKS b/THANKS index a3af2426..cfa343f6 100644 --- a/THANKS +++ b/THANKS @@ -26,6 +26,7 @@ asselinpaul Axel Haustant Ben Rosser (TC01) BenoƮt HERVIER +Bernhard Scheirle Borgar Brandon W Maister Brendan Wholihan diff --git a/docs/changelog.rst b/docs/changelog.rst index 6a4d65a4..d7bbb99a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,7 @@ Next release * Author slugs can be controlled with greater precision using the ``AUTHOR_SUBSTITUTIONS`` setting. Keeping non-alphanum characters is supported as well but discouraged. +* Replaced ``MD_EXTENSIONS`` with ``MARKDOWN`` 3.6.3 (2015-08-14) ================== diff --git a/docs/content.rst b/docs/content.rst index 4ef73f65..507593bf 100644 --- a/docs/content.rst +++ b/docs/content.rst @@ -55,7 +55,7 @@ install Markdown``. Pelican also supports `Markdown Extensions`_, which might have to be installed 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 ``MARKDOWN`` setting. Metadata syntax for Markdown posts should follow this pattern:: diff --git a/docs/settings.rst b/docs/settings.rst index 6f695f90..231906e6 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -114,15 +114,16 @@ Setting name (followed by default value, if any) of these patterns will be ignored by the processor. For example, the default ``['.#*']`` will ignore emacs lock files, and ``['__pycache__']`` would ignore Python 3's bytecode caches. -``MD_EXTENSIONS =`` ``{...}`` A dict of the extensions that the Markdown processor - will use, with extensions' settings as the values. +``MARKDOWN =`` ``{...}`` Extra configuration settings for the Markdown processor. Refer to the Python Markdown documentation's - `Extensions section `_ - for a complete list of supported extensions and their options. - Default is ``{'markdown.extensions.codehilite' : {'css_class': 'highlight'}, - 'markdown.extensions.extra': {}, 'markdown.extensions.meta': {}}``. - (Note that the dictionary defined in your settings file will - update this default one.) + `Options section + `_ + for a complete list of supported options. + The ``extensions`` option will be automatically computed from the + ``extension_configs`` option. + Default is ``'extension_configs': {'markdown.extensions.codehilite': + {'css_class': 'highlight'},'markdown.extensions.extra': {}, + 'markdown.extensions.meta': {},},``. ``OUTPUT_PATH = 'output/'`` Where to output the generated files. ``PATH`` Path to content directory to be processed by Pelican. If undefined, and content path is not specified via an argument to the ``pelican`` From a80a707321937062a8d6fe4514f7fd8a3efc0e29 Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Wed, 2 Nov 2016 21:00:04 +0100 Subject: [PATCH 4/5] Set the Markdown output format to html5 by default --- docs/settings.rst | 4 ++-- pelican/settings.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 231906e6..bf203841 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -121,9 +121,9 @@ Setting name (followed by default value, if any) for a complete list of supported options. The ``extensions`` option will be automatically computed from the ``extension_configs`` option. - Default is ``'extension_configs': {'markdown.extensions.codehilite': + Default is ``{'extension_configs': {'markdown.extensions.codehilite': {'css_class': 'highlight'},'markdown.extensions.extra': {}, - 'markdown.extensions.meta': {},},``. + 'markdown.extensions.meta': {},}, 'output_format': 'html5',}``. ``OUTPUT_PATH = 'output/'`` Where to output the generated files. ``PATH`` Path to content directory to be processed by Pelican. If undefined, and content path is not specified via an argument to the ``pelican`` diff --git a/pelican/settings.py b/pelican/settings.py index 14ddb8ba..5773b925 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -107,6 +107,7 @@ DEFAULT_CONFIG = { 'markdown.extensions.extra': {}, 'markdown.extensions.meta': {}, }, + 'output_format': 'html5', }, 'JINJA_EXTENSIONS': [], 'JINJA_FILTERS': {}, From 27d67f04cbbc808002e0a778475cd7dc92ebb9fe Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Wed, 2 Nov 2016 21:19:41 +0100 Subject: [PATCH 5/5] Update unittest to match the new Markdown output format --- pelican/tests/test_readers.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py index 89c3dd61..9f13473e 100644 --- a/pelican/tests/test_readers.py +++ b/pelican/tests/test_readers.py @@ -405,20 +405,20 @@ class MdReaderTest(ReaderTest): _path('article_with_markdown_and_footnote.md')) expected_content = ( '

This is some content' - '1' + '1' ' with some footnotes' - '2

\n' + '2

\n' '
\n' - '
\n
    \n
  1. \n' + '
    \n
      \n
    1. \n' '

      Numbered footnote ' - '

      \n' - '
    2. \n
    3. \n' + '
    4. \n
    5. \n' '

      Named footnote ' - '

      \n' '
    6. \n
    \n
') expected_metadata = {