1
0
Fork 0
forked from github/pelican

Merge pull request #2714 from getpelican/skip-md-metadata-parse

Skip Markdown metadata parsing within metadata fields
This commit is contained in:
Justin Mayer 2020-04-12 14:53:59 +02:00 committed by GitHub
commit 0f97f6d488
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View file

@ -302,6 +302,9 @@ class MarkdownReader(BaseReader):
"""Return the dict containing document metadata"""
formatted_fields = self.settings['FORMATTED_FIELDS']
# prevent metadata extraction in fields
self._md.preprocessors.deregister('meta')
output = {}
for name, value in meta.items():
name = name.lower()

View file

@ -0,0 +1,5 @@
Title: Article with markdown and nested summary metadata
Date: 2012-10-30
Summary: Test: This metadata value looks like metadata
This is some content.

View file

@ -239,6 +239,8 @@ class TestArticlesGenerator(unittest.TestCase):
['Article title', 'published', 'Default', 'article'],
['Article with markdown and summary metadata multi', 'published',
'Default', 'article'],
['Article with markdown and nested summary metadata', 'published',
'Default', 'article'],
['Article with markdown and summary metadata single', 'published',
'Default', 'article'],
['Article with markdown containing footnotes', 'published',
@ -554,6 +556,7 @@ class TestArticlesGenerator(unittest.TestCase):
'Article title',
'Article with Nonconformant HTML meta tags',
'Article with an inline SVG',
'Article with markdown and nested summary metadata',
'Article with markdown and summary metadata multi',
'Article with markdown and summary metadata single',
'Article with markdown containing footnotes',

View file

@ -645,6 +645,19 @@ class MdReaderTest(ReaderTest):
}
self.assertDictHasSubset(metadata, expected)
def test_metadata_not_parsed_for_metadata(self):
settings = get_settings()
settings['FORMATTED_FIELDS'] = ['summary']
reader = readers.MarkdownReader(settings=settings)
content, metadata = reader.read(
_path('article_with_markdown_and_nested_metadata.md'))
expected = {
'title': 'Article with markdown and nested summary metadata',
'summary': '<p>Test: This metadata value looks like metadata</p>',
}
self.assertDictHasSubset(metadata, expected)
def test_empty_file(self):
reader = readers.MarkdownReader(settings=get_settings())
content, metadata = reader.read(