diff options
author | Waylan Limberg <waylan@gmail.com> | 2013-08-07 22:17:30 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2013-08-07 22:17:30 -0400 |
commit | d12d2c95b42c5fc0910b13859001755d71ad3438 (patch) | |
tree | 6f62507415a7c86e71985d07945d89f98607ccca /tests | |
parent | a64592d5f288d0b83b11aa7d4eade728d5d5fb91 (diff) | |
download | python-markdown-d12d2c95b42c5fc0910b13859001755d71ad3438.tar.gz |
Allow extensions to register serializers
Setting output_format must happen after extensions are loaded. Only in that
way can an extension register a serializer so that it will then be available
to be used with the output_format keyword. A test has been added to avoid
this regression from happening again in the future.
Fixes #238, partially reverses commit 41cc055 and provides a better fix for
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_apis.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_apis.py b/tests/test_apis.py index 4a7c7c7..bbe165d 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -358,6 +358,24 @@ class testSerializers(unittest.TestCase): '<MixedCase>not valid <EMPHASIS>html</EMPHASIS><HR /></MixedCase>') + def buildExtension(self): + """ Build an extension which registers fakeSerializer. """ + def fakeSerializer(elem): + # Ignore input and return hardcoded output + return '<div><p>foo</p></div>' + + class registerFakeSerializer(markdown.extensions.Extension): + def extendMarkdown(self, md, md_globals): + md.output_formats['fake'] = fakeSerializer + + return registerFakeSerializer() + + def testRegisterSerializer(self): + self.assertEqual(markdown.markdown('baz', + extensions=[self.buildExtension()], output_format='fake'), + '<p>foo</p>') + + class testAtomicString(unittest.TestCase): """ Test that AtomicStrings are honored (not parsed). """ |