diff options
author | Waylan Limberg <waylan@gmail.com> | 2009-03-16 22:20:39 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2009-03-16 22:20:39 -0400 |
commit | cdcfbacb23a5b9bc5a1c1af058d90e61364d61b0 (patch) | |
tree | 85a656e50af04f3e73ef5e50606c947dc8a19e82 | |
parent | 4d324deea73e76a7f5919b693d2f4368803d03fa (diff) | |
download | markdown-cdcfbacb23a5b9bc5a1c1af058d90e61364d61b0.tar.gz markdown-cdcfbacb23a5b9bc5a1c1af058d90e61364d61b0.tar.bz2 markdown-cdcfbacb23a5b9bc5a1c1af058d90e61364d61b0.zip |
Output formats are now listed in a Dict mapped to their respective serializers. Extensions can now easily add their own serializers.
-rw-r--r-- | markdown/__init__.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index 2b5231a..2a2e7cb 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -298,6 +298,14 @@ class Markdown: postprocessors.AndSubstitutePostprocessor() # footnote postprocessor will be inserted with ">amp_substitute" + # Map format keys to serializers + self.output_formats = { + 'html' : html4.to_html_string, + 'html4' : html4.to_html_string, + 'xhtml' : etree.tostring, + 'xhtml1': etree.tostring, + } + self.references = {} self.htmlStash = preprocessors.HtmlStash() self.registerExtensions(extensions = extensions, @@ -342,12 +350,11 @@ class Markdown: def set_output_format(self, format): """ Set the output format for the class instance. """ - if format.lower() in ['html', 'html4']: - self.serializer = html4.to_html_string - elif format.lower() in ['xhtml', 'xhtml1']: - self.serializer = etree.tostring - else: - message(CRITICAL, 'Invalid Output Format: "%s". Use one of "xhtml1" or "html4".' % format) + try: + self.serializer = self.output_formats[format.lower()] + except KeyError: + message(CRITICAL, 'Invalid Output Format: "%s". Use one of %s.' \ + % (format, self.output_formats.keys())) def convert(self, source): """ |