mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #523 from StephaneBunel/master
New config parameter to enable Markdown extensions
This commit is contained in:
commit
848fdedec7
7 changed files with 40 additions and 9 deletions
|
|
@ -155,7 +155,5 @@ SITEURL :
|
||||||
STATIC_PATHS :
|
STATIC_PATHS :
|
||||||
Les chemins statiques que vous voulez avoir accès sur le chemin de sortie "statique" ;
|
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 ;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ Setting name (default value) What doe
|
||||||
This only applies if your content does not otherwise
|
This only applies if your content does not otherwise
|
||||||
specify a summary. Setting to None will cause the summary
|
specify a summary. Setting to None will cause the summary
|
||||||
to be a copy of the original content.
|
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.
|
.. [#] Default is the system locale.
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import re
|
||||||
from pelican.contents import Category, Tag, Author
|
from pelican.contents import Category, Tag, Author
|
||||||
from pelican.utils import get_date, pelican_open
|
from pelican.utils import get_date, pelican_open
|
||||||
|
|
||||||
|
|
||||||
_METADATA_PROCESSORS = {
|
_METADATA_PROCESSORS = {
|
||||||
'tags': lambda x, y: [Tag(tag, y) for tag in unicode(x).split(',')],
|
'tags': lambda x, y: [Tag(tag, y) for tag in unicode(x).split(',')],
|
||||||
'date': lambda x, y: get_date(x),
|
'date': lambda x, y: get_date(x),
|
||||||
|
|
@ -102,7 +101,7 @@ class RstReader(Reader):
|
||||||
def _get_publisher(self, filename):
|
def _get_publisher(self, filename):
|
||||||
extra_params = {'initial_header_level': '2'}
|
extra_params = {'initial_header_level': '2'}
|
||||||
pub = docutils.core.Publisher(
|
pub = docutils.core.Publisher(
|
||||||
destination_class=docutils.io.StringOutput)
|
destination_class=docutils.io.StringOutput)
|
||||||
pub.set_components('standalone', 'restructuredtext', 'html')
|
pub.set_components('standalone', 'restructuredtext', 'html')
|
||||||
pub.writer.translator_class = PelicanHTMLTranslator
|
pub.writer.translator_class = PelicanHTMLTranslator
|
||||||
pub.process_programmatic_settings(None, extra_params, None)
|
pub.process_programmatic_settings(None, extra_params, None)
|
||||||
|
|
@ -129,8 +128,13 @@ class MarkdownReader(Reader):
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""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)
|
text = pelican_open(filename)
|
||||||
md = Markdown(extensions=set(self.extensions + ['meta']))
|
md = Markdown(extensions=set(
|
||||||
|
self.extensions + markdown_extensions + ['meta']))
|
||||||
content = md.convert(text)
|
content = md.convert(text)
|
||||||
|
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'SUMMARY_MAX_LENGTH': 50,
|
'SUMMARY_MAX_LENGTH': 50,
|
||||||
'WEBASSETS': False,
|
'WEBASSETS': False,
|
||||||
'PLUGINS': [],
|
'PLUGINS': [],
|
||||||
|
'MARKDOWN_EXTENSIONS': ['toc', ],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
8
tests/content/article_with_markdown_markup_extensions.md
Normal file
8
tests/content/article_with_markdown_markup_extensions.md
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
Title: Test Markdown extensions
|
||||||
|
|
||||||
|
[TOC]
|
||||||
|
|
||||||
|
## Level1
|
||||||
|
|
||||||
|
### Level2
|
||||||
|
|
||||||
|
|
@ -69,6 +69,7 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
[u'Article title', 'published', 'Default', 'article'],
|
[u'Article title', 'published', 'Default', 'article'],
|
||||||
[u'Article with template', 'published', 'Default', 'custom'],
|
[u'Article with template', 'published', 'Default', 'custom'],
|
||||||
[u'Test md File', 'published', 'test', 'article'],
|
[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 a super article !', 'published', 'Yeah', 'article'],
|
||||||
[u'This is an article with category !', 'published', 'yeah', 'article'],
|
[u'This is an article with category !', 'published', 'yeah', 'article'],
|
||||||
[u'This is an article without category !', 'published', 'Default', 'article'],
|
[u'This is an article without category !', 'published', 'Default', 'article'],
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
class MdReaderTest(unittest.TestCase):
|
class MdReaderTest(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
|
@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
|
# test to ensure the md extension is being processed by the correct reader
|
||||||
reader = readers.MarkdownReader({})
|
reader = readers.MarkdownReader({})
|
||||||
content, metadata = reader.read(_filename('article_with_md_extension.md'))
|
content, metadata = reader.read(_filename('article_with_md_extension.md'))
|
||||||
|
|
@ -90,3 +90,22 @@ class MdReaderTest(unittest.TestCase):
|
||||||
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
||||||
|
|
||||||
self.assertEqual(content, expected)
|
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 = '<div class="toc">\n'\
|
||||||
|
'<ul>\n'\
|
||||||
|
'<li><a href="#level1">Level1</a><ul>\n'\
|
||||||
|
'<li><a href="#level2">Level2</a></li>\n'\
|
||||||
|
'</ul>\n'\
|
||||||
|
'</li>\n'\
|
||||||
|
'</ul>\n'\
|
||||||
|
'</div>\n'\
|
||||||
|
'<h2 id="level1">Level1</h2>\n'\
|
||||||
|
'<h3 id="level2">Level2</h3>'
|
||||||
|
|
||||||
|
self.assertEqual(content, expected)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue