From 2d2183d1beaf0fb2a86461bceb6599f1bcb02605 Mon Sep 17 00:00:00 2001 From: Glandos Date: Wed, 20 Jun 2018 02:14:29 +0200 Subject: Implement reset() for Meta extension (#672) Fixes #671 --- markdown/extensions/meta.py | 5 +++++ tests/test_extensions.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/markdown/extensions/meta.py b/markdown/extensions/meta.py index cafad4a..2c2c8e3 100644 --- a/markdown/extensions/meta.py +++ b/markdown/extensions/meta.py @@ -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. """ diff --git a/tests/test_extensions.py b/tests/test_extensions.py index aee9bac..35eaf1d 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -454,6 +454,20 @@ The body. This is paragraph one.''' 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. """ -- cgit v1.2.3