diff --git a/docs/fr/configuration.rst b/docs/fr/configuration.rst index 151eff3a..abfc7ef5 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_EXTENSIONS : + Liste des extentions Markdown que vous souhaitez utiliser ; diff --git a/docs/settings.rst b/docs/settings.rst index 68cc4734..61dc9697 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 30038f7a..c53ff5b1 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), @@ -102,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) @@ -129,8 +128,13 @@ class MarkdownReader(Reader): def read(self, filename): """Parse content and metadata of markdown files""" + 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 + ['meta'])) + md = Markdown(extensions=set( + self.extensions + markdown_extensions + ['meta'])) content = md.convert(text) metadata = {} diff --git a/pelican/settings.py b/pelican/settings.py index 92c68ddc..c454c27b 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -75,6 +75,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'SUMMARY_MAX_LENGTH': 50, 'WEBASSETS': False, 'PLUGINS': [], + 'MARKDOWN_EXTENSIONS': ['toc', ], } diff --git a/tests/content/article_with_markdown_markup_extensions.md b/tests/content/article_with_markdown_markup_extensions.md new file mode 100644 index 00000000..6cf56403 --- /dev/null +++ b/tests/content/article_with_markdown_markup_extensions.md @@ -0,0 +1,8 @@ +Title: Test Markdown extensions + +[TOC] + +## Level1 + +### Level2 + diff --git a/tests/test_generators.py b/tests/test_generators.py index 3a4ea1e3..374172d8 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 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 299aa378..406027c1 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')) @@ -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_EXTENSIONS=['toc', ])) + content, metadata = reader.read(_filename('article_with_markdown_markup_extensions.md')) + expected = '
\n'\ + '\n'\ + '
\n'\ + '

Level1

\n'\ + '

Level2

' + + self.assertEqual(content, expected)