mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Update docs and tests for MARKDOWN_EXTENTIONS
This commit is contained in:
parent
226aa2d8f3
commit
45c836fdf5
5 changed files with 30 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_EXTENTIONS :
|
||||||
|
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.
|
||||||
|
|
|
||||||
|
|
@ -101,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)
|
||||||
|
|
@ -124,13 +124,17 @@ class RstReader(Reader):
|
||||||
class MarkdownReader(Reader):
|
class MarkdownReader(Reader):
|
||||||
enabled = bool(Markdown)
|
enabled = bool(Markdown)
|
||||||
file_extensions = ['md', 'markdown', 'mkd']
|
file_extensions = ['md', 'markdown', 'mkd']
|
||||||
extensions = ['codehilite', 'extra' ]
|
extensions = ['codehilite', 'extra']
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""Parse content and metadata of markdown files"""
|
||||||
markdown_extentions = self.settings.get('MARKDOWN_EXTENTIONS', [])
|
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)
|
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)
|
content = md.convert(text)
|
||||||
|
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'SUMMARY_MAX_LENGTH': 50,
|
'SUMMARY_MAX_LENGTH': 50,
|
||||||
'WEBASSETS': False,
|
'WEBASSETS': False,
|
||||||
'PLUGINS': [],
|
'PLUGINS': [],
|
||||||
'MARKDOWN_EXTENTIONS': [],
|
'MARKDOWN_EXTENTIONS': [ 'toc', ],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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_EXTENTIONS=['toc']))
|
||||||
|
content, metadata = reader.read(_filename('article_with_markdown_markup_extentions.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