From 75f214103e208ee4a0d065692d83cafbd2300e26 Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Fri, 10 May 2013 03:50:33 -0400 Subject: [PATCH] Markdown summary should not include content footnote Markdown instance carries state for subsequent uses. Content and summary parsing is done with the same instance. Since footnotes are processed with an extension and stored as state, content footnote is duplicated for summary. This PR adds a ``.reset()`` call before summary parsing to clear the state. It also adds a test case with footnotes. --- pelican/readers.py | 2 + .../article_with_markdown_and_footnote.md | 8 ++++ pelican/tests/test_generators.py | 4 +- pelican/tests/test_readers.py | 37 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 pelican/tests/content/article_with_markdown_and_footnote.md diff --git a/pelican/readers.py b/pelican/readers.py index 797994cb..ca39a1c2 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -166,6 +166,8 @@ class MarkdownReader(Reader): name = name.lower() if name == "summary": summary_values = "\n".join(value) + # reset the markdown instance to clear any state + self._md.reset() summary = self._md.convert(summary_values) output[name] = self.process_metadata(name, summary) else: diff --git a/pelican/tests/content/article_with_markdown_and_footnote.md b/pelican/tests/content/article_with_markdown_and_footnote.md new file mode 100644 index 00000000..dc257d62 --- /dev/null +++ b/pelican/tests/content/article_with_markdown_and_footnote.md @@ -0,0 +1,8 @@ +Title: Article with markdown containing footnotes +Date: 2012-10-31 +Summary: Summary with **inline** markup *should* be supported. + +This is some content[^1] with some footnotes[^footnote] + +[^1]: Numbered footnote +[^footnote]: Named footnote \ No newline at end of file diff --git a/pelican/tests/test_generators.py b/pelican/tests/test_generators.py index 13156d3b..fa57322d 100644 --- a/pelican/tests/test_generators.py +++ b/pelican/tests/test_generators.py @@ -90,7 +90,9 @@ class TestArticlesGenerator(unittest.TestCase): 'TestCategory', 'article'], ['This is a super article !', 'published', 'yeah', 'article'], ['マックOS X 10.8でパイソンとVirtualenvをインストールと設定', - 'published', '指導書', 'article'] + 'published', '指導書', 'article'], + ['Article with markdown containing footnotes', 'published', + 'Default', 'article'] ] self.assertEqual(sorted(articles_expected), sorted(articles)) diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py index 5381a776..9d2ea50a 100644 --- a/pelican/tests/test_readers.py +++ b/pelican/tests/test_readers.py @@ -144,6 +144,43 @@ class MdReaderTest(unittest.TestCase): for key, value in metadata.items(): self.assertEqual(value, expected[key], key) + + @unittest.skipUnless(readers.Markdown, "markdown isn't installed") + def test_article_with_footnote(self): + reader = readers.MarkdownReader({}) + content, metadata = reader.read( + _path('article_with_markdown_and_footnote.md')) + expected_content = ( + '

This is some content' + '1' + ' with some footnotes' + '2

\n' + + '
\n' + '
\n
    \n
  1. \n' + '

    Numbered footnote ' + '

    \n' + '
  2. \n
  3. \n' + '

    Named footnote ' + '

    \n' + '
  4. \n
\n
') + expected_metadata = { + 'title': 'Article with markdown containing footnotes', + 'summary': ( + '

Summary with inline markup ' + 'should be supported.

'), + 'date': datetime.datetime(2012, 10, 31), + 'slug': 'article-with-markdown-containing-footnotes', + } + self.assertEqual(content, expected_content) + for key, value in metadata.items(): + self.assertEqual(value, expected_metadata[key], key) + + @unittest.skipUnless(readers.Markdown, "markdown isn't installed") def test_article_with_file_extensions(self): reader = readers.MarkdownReader({})