mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #1927 from Scheirle/markdown_options
Replaces MD_EXTENSIONS with MARKDOWN; Fixes #1024
This commit is contained in:
commit
a07c0e6e04
8 changed files with 53 additions and 41 deletions
1
THANKS
1
THANKS
|
|
@ -26,6 +26,7 @@ asselinpaul
|
||||||
Axel Haustant
|
Axel Haustant
|
||||||
Ben Rosser (TC01)
|
Ben Rosser (TC01)
|
||||||
Benoît HERVIER
|
Benoît HERVIER
|
||||||
|
Bernhard Scheirle
|
||||||
Borgar
|
Borgar
|
||||||
Brandon W Maister
|
Brandon W Maister
|
||||||
Brendan Wholihan
|
Brendan Wholihan
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ Next release
|
||||||
* Author slugs can be controlled with greater precision using the
|
* Author slugs can be controlled with greater precision using the
|
||||||
``AUTHOR_SUBSTITUTIONS`` setting. Keeping non-alphanum characters is supported
|
``AUTHOR_SUBSTITUTIONS`` setting. Keeping non-alphanum characters is supported
|
||||||
as well but discouraged.
|
as well but discouraged.
|
||||||
|
* Replaced ``MD_EXTENSIONS`` with ``MARKDOWN``
|
||||||
|
|
||||||
3.6.3 (2015-08-14)
|
3.6.3 (2015-08-14)
|
||||||
==================
|
==================
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ install Markdown``.
|
||||||
|
|
||||||
Pelican also supports `Markdown Extensions`_, which might have to be installed
|
Pelican also supports `Markdown Extensions`_, which might have to be installed
|
||||||
separately if they are not included in the default ``Markdown`` package and can
|
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::
|
Metadata syntax for Markdown posts should follow this pattern::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,15 +114,16 @@ Setting name (followed by default value, if any)
|
||||||
of these patterns will be ignored by the processor. For example,
|
of these patterns will be ignored by the processor. For example,
|
||||||
the default ``['.#*']`` will ignore emacs lock files, and
|
the default ``['.#*']`` will ignore emacs lock files, and
|
||||||
``['__pycache__']`` would ignore Python 3's bytecode caches.
|
``['__pycache__']`` would ignore Python 3's bytecode caches.
|
||||||
``MD_EXTENSIONS =`` ``{...}`` A dict of the extensions that the Markdown processor
|
``MARKDOWN =`` ``{...}`` Extra configuration settings for the Markdown processor.
|
||||||
will use, with extensions' settings as the values.
|
|
||||||
Refer to the Python Markdown documentation's
|
Refer to the Python Markdown documentation's
|
||||||
`Extensions section <http://pythonhosted.org/Markdown/extensions/>`_
|
`Options section
|
||||||
for a complete list of supported extensions and their options.
|
<http://pythonhosted.org/Markdown/reference.html#markdown>`_
|
||||||
Default is ``{'markdown.extensions.codehilite' : {'css_class': 'highlight'},
|
for a complete list of supported options.
|
||||||
'markdown.extensions.extra': {}, 'markdown.extensions.meta': {}}``.
|
The ``extensions`` option will be automatically computed from the
|
||||||
(Note that the dictionary defined in your settings file will
|
``extension_configs`` option.
|
||||||
update this default one.)
|
Default is ``{'extension_configs': {'markdown.extensions.codehilite':
|
||||||
|
{'css_class': 'highlight'},'markdown.extensions.extra': {},
|
||||||
|
'markdown.extensions.meta': {},}, 'output_format': 'html5',}``.
|
||||||
``OUTPUT_PATH = 'output/'`` Where to output the generated files.
|
``OUTPUT_PATH = 'output/'`` Where to output the generated files.
|
||||||
``PATH`` Path to content directory to be processed by Pelican. If undefined,
|
``PATH`` Path to content directory to be processed by Pelican. If undefined,
|
||||||
and content path is not specified via an argument to the ``pelican``
|
and content path is not specified via an argument to the ``pelican``
|
||||||
|
|
|
||||||
|
|
@ -246,8 +246,16 @@ class MarkdownReader(BaseReader):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(MarkdownReader, self).__init__(*args, **kwargs)
|
super(MarkdownReader, self).__init__(*args, **kwargs)
|
||||||
self.extensions = self.settings['MD_EXTENSIONS']
|
# make sure 'extension_configs' exists and
|
||||||
self.extensions.setdefault('markdown.extensions.meta', {})
|
# 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
|
self._source_path = None
|
||||||
|
|
||||||
def _parse_metadata(self, meta):
|
def _parse_metadata(self, meta):
|
||||||
|
|
@ -283,8 +291,7 @@ class MarkdownReader(BaseReader):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""Parse content and metadata of markdown files"""
|
||||||
|
|
||||||
self._source_path = source_path
|
self._source_path = source_path
|
||||||
self._md = Markdown(extensions=self.extensions.keys(),
|
self._md = Markdown(**self.settings['MARKDOWN'])
|
||||||
extension_configs=self.extensions)
|
|
||||||
with pelican_open(source_path) as text:
|
with pelican_open(source_path) as text:
|
||||||
content = self._md.convert(text)
|
content = self._md.convert(text)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,10 +101,13 @@ DEFAULT_CONFIG = {
|
||||||
'PELICAN_CLASS': 'pelican.Pelican',
|
'PELICAN_CLASS': 'pelican.Pelican',
|
||||||
'DEFAULT_DATE_FORMAT': '%a %d %B %Y',
|
'DEFAULT_DATE_FORMAT': '%a %d %B %Y',
|
||||||
'DATE_FORMATS': {},
|
'DATE_FORMATS': {},
|
||||||
'MD_EXTENSIONS': {
|
'MARKDOWN': {
|
||||||
'markdown.extensions.codehilite': {'css_class': 'highlight'},
|
'extension_configs': {
|
||||||
'markdown.extensions.extra': {},
|
'markdown.extensions.codehilite': {'css_class': 'highlight'},
|
||||||
'markdown.extensions.meta': {},
|
'markdown.extensions.extra': {},
|
||||||
|
'markdown.extensions.meta': {},
|
||||||
|
},
|
||||||
|
'output_format': 'html5',
|
||||||
},
|
},
|
||||||
'JINJA_EXTENSIONS': [],
|
'JINJA_EXTENSIONS': [],
|
||||||
'JINJA_FILTERS': {},
|
'JINJA_FILTERS': {},
|
||||||
|
|
@ -368,13 +371,11 @@ def configure_settings(settings):
|
||||||
PATH_KEY)
|
PATH_KEY)
|
||||||
settings[PATH_KEY] = DEFAULT_CONFIG[PATH_KEY]
|
settings[PATH_KEY] = DEFAULT_CONFIG[PATH_KEY]
|
||||||
|
|
||||||
# Save people from declaring MD_EXTENSIONS as a list rather than a dict
|
# Deprecated warning of MD_EXTENSIONS
|
||||||
if not isinstance(settings.get('MD_EXTENSIONS', {}), dict):
|
if 'MD_EXTENSIONS' in settings:
|
||||||
logger.warning('The format of the MD_EXTENSIONS setting has '
|
logger.warning('MD_EXTENSIONS is deprecated use MARKDOWN '
|
||||||
'changed. It should now be a dict mapping '
|
'instead. Falling back to the default.')
|
||||||
'fully-qualified extension names to their '
|
settings['MARKDOWN'] = DEFAULT_CONFIG['MARKDOWN']
|
||||||
'configurations. Falling back to the default.')
|
|
||||||
settings['MD_EXTENSIONS'] = DEFAULT_CONFIG['MD_EXTENSIONS']
|
|
||||||
|
|
||||||
# Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES
|
# Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES
|
||||||
mutually_exclusive = ('ARTICLE', 'PAGE')
|
mutually_exclusive = ('ARTICLE', 'PAGE')
|
||||||
|
|
|
||||||
|
|
@ -208,18 +208,17 @@ class TestPelican(LoggedTestCase):
|
||||||
msg="Writing .*",
|
msg="Writing .*",
|
||||||
level=logging.INFO)
|
level=logging.INFO)
|
||||||
|
|
||||||
def test_md_extensions_list_deprecation(self):
|
def test_md_extensions_deprecation(self):
|
||||||
"""Test that a warning is issued if MD_EXTENSIONS is a list"""
|
"""Test that a warning is issued if MD_EXTENSIONS is used"""
|
||||||
settings = read_settings(path=None, override={
|
settings = read_settings(path=None, override={
|
||||||
'PATH': INPUT_PATH,
|
'PATH': INPUT_PATH,
|
||||||
'OUTPUT_PATH': self.temp_path,
|
'OUTPUT_PATH': self.temp_path,
|
||||||
'CACHE_PATH': self.temp_cache,
|
'CACHE_PATH': self.temp_cache,
|
||||||
'MD_EXTENSIONS': ['meta'],
|
'MD_EXTENSIONS': {},
|
||||||
})
|
})
|
||||||
pelican = Pelican(settings=settings)
|
pelican = Pelican(settings=settings)
|
||||||
mute(True)(pelican.run)()
|
mute(True)(pelican.run)()
|
||||||
self.assertIsInstance(pelican.settings['MD_EXTENSIONS'], dict)
|
|
||||||
self.assertLogCountEqual(
|
self.assertLogCountEqual(
|
||||||
count=1,
|
count=1,
|
||||||
msg="The format of the MD_EXTENSIONS setting has changed",
|
msg="MD_EXTENSIONS is deprecated use MARKDOWN instead.",
|
||||||
level=logging.WARNING)
|
level=logging.WARNING)
|
||||||
|
|
|
||||||
|
|
@ -405,20 +405,20 @@ class MdReaderTest(ReaderTest):
|
||||||
_path('article_with_markdown_and_footnote.md'))
|
_path('article_with_markdown_and_footnote.md'))
|
||||||
expected_content = (
|
expected_content = (
|
||||||
'<p>This is some content'
|
'<p>This is some content'
|
||||||
'<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" '
|
'<sup id="fnref-1"><a class="footnote-ref" href="#fn-1"'
|
||||||
'rel="footnote">1</a></sup>'
|
'>1</a></sup>'
|
||||||
' with some footnotes'
|
' with some footnotes'
|
||||||
'<sup id="fnref:footnote"><a class="footnote-ref" '
|
'<sup id="fnref-footnote"><a class="footnote-ref" '
|
||||||
'href="#fn:footnote" rel="footnote">2</a></sup></p>\n'
|
'href="#fn-footnote">2</a></sup></p>\n'
|
||||||
|
|
||||||
'<div class="footnote">\n'
|
'<div class="footnote">\n'
|
||||||
'<hr />\n<ol>\n<li id="fn:1">\n'
|
'<hr>\n<ol>\n<li id="fn-1">\n'
|
||||||
'<p>Numbered footnote '
|
'<p>Numbered footnote '
|
||||||
'<a class="footnote-backref" href="#fnref:1" rev="footnote" '
|
'<a class="footnote-backref" href="#fnref-1" '
|
||||||
'title="Jump back to footnote 1 in the text">↩</a></p>\n'
|
'title="Jump back to footnote 1 in the text">↩</a></p>\n'
|
||||||
'</li>\n<li id="fn:footnote">\n'
|
'</li>\n<li id="fn-footnote">\n'
|
||||||
'<p>Named footnote '
|
'<p>Named footnote '
|
||||||
'<a class="footnote-backref" href="#fnref:footnote" rev="footnote"'
|
'<a class="footnote-backref" href="#fnref-footnote"'
|
||||||
' title="Jump back to footnote 2 in the text">↩</a></p>\n'
|
' title="Jump back to footnote 2 in the text">↩</a></p>\n'
|
||||||
'</li>\n</ol>\n</div>')
|
'</li>\n</ol>\n</div>')
|
||||||
expected_metadata = {
|
expected_metadata = {
|
||||||
|
|
@ -482,10 +482,12 @@ class MdReaderTest(ReaderTest):
|
||||||
# expected
|
# expected
|
||||||
page = self.read_file(
|
page = self.read_file(
|
||||||
path='article_with_markdown_markup_extensions.md',
|
path='article_with_markdown_markup_extensions.md',
|
||||||
MD_EXTENSIONS={
|
MARKDOWN={
|
||||||
'markdown.extensions.toc': {},
|
'extension_configs': {
|
||||||
'markdown.extensions.codehilite': {},
|
'markdown.extensions.toc': {},
|
||||||
'markdown.extensions.extra': {}
|
'markdown.extensions.codehilite': {},
|
||||||
|
'markdown.extensions.extra': {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
expected = ('<div class="toc">\n'
|
expected = ('<div class="toc">\n'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue