From 4f5253bcb39e0ba6feddbd091cfa48883628e5ae Mon Sep 17 00:00:00 2001 From: stephane Date: Thu, 27 Sep 2012 19:49:42 +0200 Subject: [PATCH 1/8] Add MARKDOWN_EXTENTIONS configuration parameter to enable Markdown extentions of your choice. Ex: MARKDOWN_EXTENTIONS = [ 'toc', ] enable TOC markup to generate Table of Contents. --- pelican/readers.py | 6 +++--- pelican/settings.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 30038f7a..38e7834f 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -18,7 +18,6 @@ import re from pelican.contents import Category, Tag, Author from pelican.utils import get_date, pelican_open - _METADATA_PROCESSORS = { 'tags': lambda x, y: [Tag(tag, y) for tag in unicode(x).split(',')], 'date': lambda x, y: get_date(x), @@ -125,12 +124,13 @@ class RstReader(Reader): class MarkdownReader(Reader): enabled = bool(Markdown) file_extensions = ['md', 'markdown', 'mkd'] - extensions = ['codehilite', 'extra'] + extensions = ['codehilite', 'extra' ] def read(self, filename): """Parse content and metadata of markdown files""" + markdown_extentions = self.settings.get('MARKDOWN_EXTENTIONS', []) text = pelican_open(filename) - md = Markdown(extensions=set(self.extensions + ['meta'])) + md = Markdown(extensions=set(self.extensions + markdown_extentions + ['meta'])) content = md.convert(text) metadata = {} diff --git a/pelican/settings.py b/pelican/settings.py index 92c68ddc..f2511844 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -75,6 +75,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'SUMMARY_MAX_LENGTH': 50, 'WEBASSETS': False, 'PLUGINS': [], + 'MARKDOWN_EXTENTIONS': [], } From 226aa2d8f31125e0320e1c78c3f96ff52899b3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Fri, 28 Sep 2012 22:54:01 +0200 Subject: [PATCH 2/8] Update docs and tests for MARKDOWN_EXTENTIONS --- tests/content/article_with_markdown_markup_extentions.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/content/article_with_markdown_markup_extentions.md diff --git a/tests/content/article_with_markdown_markup_extentions.md b/tests/content/article_with_markdown_markup_extentions.md new file mode 100644 index 00000000..201cc5e9 --- /dev/null +++ b/tests/content/article_with_markdown_markup_extentions.md @@ -0,0 +1,8 @@ +Title: Test Markdown extentions + +[TOC] + +## Level1 + +### Level2 + From 45c836fdf54c38763fffd65d485b35981b0e9f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Fri, 28 Sep 2012 23:09:57 +0200 Subject: [PATCH 3/8] Update docs and tests for MARKDOWN_EXTENTIONS --- docs/fr/configuration.rst | 6 ++---- docs/settings.rst | 2 +- pelican/readers.py | 10 +++++++--- pelican/settings.py | 2 +- tests/test_readers.py | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/docs/fr/configuration.rst b/docs/fr/configuration.rst index 151eff3a..35965ed6 100644 --- a/docs/fr/configuration.rst +++ b/docs/fr/configuration.rst @@ -155,7 +155,5 @@ SITEURL : STATIC_PATHS : Les chemins statiques que vous voulez avoir accès sur le chemin de sortie "statique" ; - - - - +MARKDOWN_EXTENTIONS : + Liste des extentions Markdown que vous souhaitez utiliser ; diff --git a/docs/settings.rst b/docs/settings.rst index 4d865a7f..384c1a19 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -103,7 +103,7 @@ Setting name (default value) What doe This only applies if your content does not otherwise specify a summary. Setting to None will cause the summary to be a copy of the original content. - +`MARKDOWN_EXTENSIONS` (``['toc',]``) A list of any Markdown extensions you want to use. ===================================================================== ===================================================================== .. [#] Default is the system locale. diff --git a/pelican/readers.py b/pelican/readers.py index 38e7834f..1c2ac666 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -101,7 +101,7 @@ class RstReader(Reader): def _get_publisher(self, filename): extra_params = {'initial_header_level': '2'} pub = docutils.core.Publisher( - destination_class=docutils.io.StringOutput) + destination_class=docutils.io.StringOutput) pub.set_components('standalone', 'restructuredtext', 'html') pub.writer.translator_class = PelicanHTMLTranslator pub.process_programmatic_settings(None, extra_params, None) @@ -124,13 +124,17 @@ class RstReader(Reader): class MarkdownReader(Reader): enabled = bool(Markdown) file_extensions = ['md', 'markdown', 'mkd'] - extensions = ['codehilite', 'extra' ] + extensions = ['codehilite', 'extra'] def read(self, filename): """Parse content and metadata of markdown files""" markdown_extentions = self.settings.get('MARKDOWN_EXTENTIONS', []) + if isinstance(markdown_extentions, (str, unicode)): + markdown_extentions = [m.strip() for m in + markdown_extentions.split(',')] text = pelican_open(filename) - md = Markdown(extensions=set(self.extensions + markdown_extentions + ['meta'])) + md = Markdown(extensions=set( + self.extensions + markdown_extentions + ['meta'])) content = md.convert(text) metadata = {} diff --git a/pelican/settings.py b/pelican/settings.py index f2511844..ad0ff8fc 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -75,7 +75,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'SUMMARY_MAX_LENGTH': 50, 'WEBASSETS': False, 'PLUGINS': [], - 'MARKDOWN_EXTENTIONS': [], + 'MARKDOWN_EXTENTIONS': [ 'toc', ], } diff --git a/tests/test_readers.py b/tests/test_readers.py index 299aa378..d831252d 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -90,3 +90,22 @@ class MdReaderTest(unittest.TestCase): "

This is another markdown test file. Uses the mkd extension.

" self.assertEqual(content, expected) + + @unittest.skipUnless(readers.Markdown, "markdown isn't installed") + def test_article_with_markdown_markup_extension(self): + # test to ensure the markdown markup extension is being processed as expected + reader = readers.MarkdownReader({}) + reader.settings.update(dict(MARKDOWN_EXTENTIONS=['toc'])) + content, metadata = reader.read(_filename('article_with_markdown_markup_extentions.md')) + expected = '
\n'\ + '\n'\ + '
\n'\ + '

Level1

\n'\ + '

Level2

' + + self.assertEqual(content, expected) From 1beff31bd87026725e0b6d8585c1fb95b3b2944d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Fri, 28 Sep 2012 23:29:10 +0200 Subject: [PATCH 4/8] FIX test_generate_context() to include new file content/article_with_markdown_markup_extentions.md --- tests/test_generators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_generators.py b/tests/test_generators.py index 3a4ea1e3..caad4725 100644 --- a/tests/test_generators.py +++ b/tests/test_generators.py @@ -69,6 +69,7 @@ class TestArticlesGenerator(unittest.TestCase): [u'Article title', 'published', 'Default', 'article'], [u'Article with template', 'published', 'Default', 'custom'], [u'Test md File', 'published', 'test', 'article'], + [u'Test Markdown extentions', 'published', u'Default', 'article'], [u'This is a super article !', 'published', 'Yeah', 'article'], [u'This is an article with category !', 'published', 'yeah', 'article'], [u'This is an article without category !', 'published', 'Default', 'article'], From d9d58b0510801327e634e988108f3682ffa20905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Wed, 3 Oct 2012 22:28:00 +0200 Subject: [PATCH 5/8] FIX: "extentions" -> "extensions" --- ...p_extentions.md => article_with_markdown_markup_extensions.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/content/{article_with_markdown_markup_extentions.md => article_with_markdown_markup_extensions.md} (100%) diff --git a/tests/content/article_with_markdown_markup_extentions.md b/tests/content/article_with_markdown_markup_extensions.md similarity index 100% rename from tests/content/article_with_markdown_markup_extentions.md rename to tests/content/article_with_markdown_markup_extensions.md From ee46becaf9e7c4c585d9f8b3fd5f112bf9ef11df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Wed, 3 Oct 2012 22:29:59 +0200 Subject: [PATCH 6/8] FIX: Standardizing "extentions" to "extensions" --- pelican/readers.py | 10 +++++----- pelican/settings.py | 2 +- tests/test_generators.py | 2 +- tests/test_readers.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 1c2ac666..55d5ceaa 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -128,13 +128,13 @@ class MarkdownReader(Reader): def read(self, filename): """Parse content and metadata of markdown files""" - markdown_extentions = self.settings.get('MARKDOWN_EXTENTIONS', []) - if isinstance(markdown_extentions, (str, unicode)): - markdown_extentions = [m.strip() for m in - markdown_extentions.split(',')] + markdown_extensions = self.settings.get('MARKDOWN_EXTENsIONS', []) + if isinstance(markdown_extensions, (str, unicode)): + markdown_extensions = [m.strip() for m in + markdown_extensions.split(',')] text = pelican_open(filename) md = Markdown(extensions=set( - self.extensions + markdown_extentions + ['meta'])) + self.extensions + markdown_extensions + ['meta'])) content = md.convert(text) metadata = {} diff --git a/pelican/settings.py b/pelican/settings.py index ad0ff8fc..c454c27b 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -75,7 +75,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'SUMMARY_MAX_LENGTH': 50, 'WEBASSETS': False, 'PLUGINS': [], - 'MARKDOWN_EXTENTIONS': [ 'toc', ], + 'MARKDOWN_EXTENSIONS': ['toc', ], } diff --git a/tests/test_generators.py b/tests/test_generators.py index caad4725..374172d8 100644 --- a/tests/test_generators.py +++ b/tests/test_generators.py @@ -69,7 +69,7 @@ class TestArticlesGenerator(unittest.TestCase): [u'Article title', 'published', 'Default', 'article'], [u'Article with template', 'published', 'Default', 'custom'], [u'Test md File', 'published', 'test', 'article'], - [u'Test Markdown extentions', 'published', u'Default', 'article'], + [u'Test Markdown extensions', 'published', u'Default', 'article'], [u'This is a super article !', 'published', 'Yeah', 'article'], [u'This is an article with category !', 'published', 'yeah', 'article'], [u'This is an article without category !', 'published', 'Default', 'article'], diff --git a/tests/test_readers.py b/tests/test_readers.py index d831252d..1b3a879c 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -95,8 +95,8 @@ class MdReaderTest(unittest.TestCase): def test_article_with_markdown_markup_extension(self): # test to ensure the markdown markup extension is being processed as expected reader = readers.MarkdownReader({}) - reader.settings.update(dict(MARKDOWN_EXTENTIONS=['toc'])) - content, metadata = reader.read(_filename('article_with_markdown_markup_extentions.md')) + reader.settings.update(dict(MARKDOWN_EXTENSIONS=['toc'])) + content, metadata = reader.read(_filename('article_with_markdown_markup_extensions.md')) expected = '
\n'\ '
    \n'\ '
  • Level1
      \n'\ From e0674aad874bcbe64a2a4e0504d84f3363e71b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Wed, 3 Oct 2012 22:37:18 +0200 Subject: [PATCH 7/8] FIX: Standardizing "extentions" to "extensions" --- docs/fr/configuration.rst | 2 +- tests/content/article_with_markdown_markup_extensions.md | 2 +- tests/test_readers.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/fr/configuration.rst b/docs/fr/configuration.rst index 35965ed6..abfc7ef5 100644 --- a/docs/fr/configuration.rst +++ b/docs/fr/configuration.rst @@ -155,5 +155,5 @@ SITEURL : STATIC_PATHS : Les chemins statiques que vous voulez avoir accès sur le chemin de sortie "statique" ; -MARKDOWN_EXTENTIONS : +MARKDOWN_EXTENSIONS : Liste des extentions Markdown que vous souhaitez utiliser ; diff --git a/tests/content/article_with_markdown_markup_extensions.md b/tests/content/article_with_markdown_markup_extensions.md index 201cc5e9..6cf56403 100644 --- a/tests/content/article_with_markdown_markup_extensions.md +++ b/tests/content/article_with_markdown_markup_extensions.md @@ -1,4 +1,4 @@ -Title: Test Markdown extentions +Title: Test Markdown extensions [TOC] diff --git a/tests/test_readers.py b/tests/test_readers.py index 1b3a879c..38b7197a 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -70,7 +70,7 @@ class RstReaderTest(unittest.TestCase): class MdReaderTest(unittest.TestCase): @unittest.skipUnless(readers.Markdown, "markdown isn't installed") - def test_article_with_md_extention(self): + def test_article_with_md_extension(self): # test to ensure the md extension is being processed by the correct reader reader = readers.MarkdownReader({}) content, metadata = reader.read(_filename('article_with_md_extension.md')) From 5e895317f6ba250f2fd80d6e77a67c42035d4706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bunel?= Date: Wed, 3 Oct 2012 22:42:07 +0200 Subject: [PATCH 8/8] FIX: Standardizing "extentions" to "extensions" --- pelican/readers.py | 2 +- tests/test_readers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 55d5ceaa..c53ff5b1 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -128,7 +128,7 @@ class MarkdownReader(Reader): def read(self, filename): """Parse content and metadata of markdown files""" - markdown_extensions = self.settings.get('MARKDOWN_EXTENsIONS', []) + markdown_extensions = self.settings.get('MARKDOWN_EXTENSIONS', []) if isinstance(markdown_extensions, (str, unicode)): markdown_extensions = [m.strip() for m in markdown_extensions.split(',')] diff --git a/tests/test_readers.py b/tests/test_readers.py index 38b7197a..406027c1 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -95,7 +95,7 @@ class MdReaderTest(unittest.TestCase): def test_article_with_markdown_markup_extension(self): # test to ensure the markdown markup extension is being processed as expected reader = readers.MarkdownReader({}) - reader.settings.update(dict(MARKDOWN_EXTENSIONS=['toc'])) + reader.settings.update(dict(MARKDOWN_EXTENSIONS=['toc', ])) content, metadata = reader.read(_filename('article_with_markdown_markup_extensions.md')) expected = '
      \n'\ '
        \n'\