mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #635 from michaelreneer/markdown-summary-metadata
Updated markdown reader to parse summary metadata as markup.
This commit is contained in:
commit
92c085c28e
5 changed files with 43 additions and 4 deletions
|
|
@ -133,16 +133,27 @@ class MarkdownReader(Reader):
|
||||||
file_extensions = ['md', 'markdown', 'mkd']
|
file_extensions = ['md', 'markdown', 'mkd']
|
||||||
extensions = ['codehilite', 'extra']
|
extensions = ['codehilite', 'extra']
|
||||||
|
|
||||||
|
def _parse_metadata(self, meta):
|
||||||
|
"""Return the dict containing document metadata"""
|
||||||
|
md = Markdown(extensions=set(self.extensions + ['meta']))
|
||||||
|
output = {}
|
||||||
|
for name, value in meta.items():
|
||||||
|
name = name.lower()
|
||||||
|
if name == "summary":
|
||||||
|
summary_values = "\n".join(str(item) for item in value)
|
||||||
|
summary = md.convert(summary_values)
|
||||||
|
output[name] = self.process_metadata(name, summary)
|
||||||
|
else:
|
||||||
|
output[name] = self.process_metadata(name, value[0])
|
||||||
|
return output
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""Parse content and metadata of markdown files"""
|
||||||
text = pelican_open(filename)
|
text = pelican_open(filename)
|
||||||
md = Markdown(extensions=set(self.extensions + ['meta']))
|
md = Markdown(extensions=set(self.extensions + ['meta']))
|
||||||
content = md.convert(text)
|
content = md.convert(text)
|
||||||
|
|
||||||
metadata = {}
|
metadata = self._parse_metadata(md.Meta)
|
||||||
for name, value in md.Meta.items():
|
|
||||||
name = name.lower()
|
|
||||||
metadata[name] = self.process_metadata(name, value[0])
|
|
||||||
return content, metadata
|
return content, metadata
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
Title: Article with markdown and summary metadata multi
|
||||||
|
Date: 2012-10-31
|
||||||
|
Summary:
|
||||||
|
A multi-line summary should be supported
|
||||||
|
as well as **inline markup**.
|
||||||
|
|
||||||
|
This is some content.
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
Title: Article with markdown and summary metadata single
|
||||||
|
Date: 2012-10-30
|
||||||
|
Summary: A single-line summary should be supported as well as **inline markup**.
|
||||||
|
|
||||||
|
This is some content.
|
||||||
|
|
@ -71,6 +71,8 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
articles = self.distill_articles(generator.articles)
|
articles = self.distill_articles(generator.articles)
|
||||||
articles_expected = [
|
articles_expected = [
|
||||||
[u'Article title', 'published', 'Default', 'article'],
|
[u'Article title', 'published', 'Default', 'article'],
|
||||||
|
[u'Article with markdown and summary metadata single', 'published', u'Default', 'article'],
|
||||||
|
[u'Article with markdown and summary metadata multi', 'published', u'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'Rst with filename metadata', 'published', u'yeah', 'article'],
|
[u'Rst with filename metadata', 'published', u'yeah', 'article'],
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,20 @@ class MdReaderTest(unittest.TestCase):
|
||||||
for key, value in expected.items():
|
for key, value in expected.items():
|
||||||
self.assertEquals(value, metadata[key], key)
|
self.assertEquals(value, metadata[key], key)
|
||||||
|
|
||||||
|
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
|
||||||
|
def test_article_with_summary_metadata(self):
|
||||||
|
reader = readers.MarkdownReader({})
|
||||||
|
content, metadata = reader.read(
|
||||||
|
_filename('article_with_markdown_and_summary_metadata_single.md'))
|
||||||
|
expected_summary = u'<p>A single-line summary should be supported'\
|
||||||
|
u' as well as <strong>inline markup</strong>.</p>'
|
||||||
|
self.assertEquals(expected_summary, metadata['summary'], 'summary')
|
||||||
|
content, metadata = reader.read(
|
||||||
|
_filename('article_with_markdown_and_summary_metadata_multi.md'))
|
||||||
|
expected_summary = u'<p>A multi-line summary should be supported'\
|
||||||
|
u'\nas well as <strong>inline markup</strong>.</p>'
|
||||||
|
self.assertEquals(expected_summary, metadata['summary'], 'summary')
|
||||||
|
|
||||||
class AdReaderTest(unittest.TestCase):
|
class AdReaderTest(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed")
|
@unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue