Skip to content

Commit

Permalink
Implement reset() for Meta extension (#672)
Browse files Browse the repository at this point in the history
Fixes #671
  • Loading branch information
Glandos authored and waylan committed Jun 20, 2018
1 parent d321e79 commit 2d2183d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions markdown/extensions/meta.py
Expand Up @@ -36,10 +36,15 @@ class MetaExtension (Extension):

def extendMarkdown(self, md, md_globals):
""" Add MetaPreprocessor to Markdown instance. """
md.registerExtension(self)
self.md = md
md.preprocessors.add("meta",
MetaPreprocessor(md),
">normalize_whitespace")

def reset(self):
self.md.Meta = {}


class MetaPreprocessor(Preprocessor):
""" Get Meta-Data. """
Expand Down
14 changes: 14 additions & 0 deletions tests/test_extensions.py
Expand Up @@ -454,6 +454,20 @@ def testMetaDataWithoutNewline(self):
self.assertEqual(self.md.convert(text), '')
self.assertEqual(self.md.Meta, {'title': ['No newline']})

def testMetaDataReset(self):
""" Test that reset call remove Meta entirely """

text = '''Title: A Test Doc.
Author: Waylan Limberg
John Doe
Blank_Data:
The body. This is paragraph one.'''
self.md.convert(text)

self.md.reset()
self.assertEqual(self.md.Meta, {})


class TestWikiLinks(unittest.TestCase):
""" Test Wikilinks Extension. """
Expand Down

0 comments on commit 2d2183d

Please sign in to comment.