diff options
Diffstat (limited to 'markdown/__init__.py')
-rw-r--r-- | markdown/__init__.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index 211e3d5..26314f6 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -182,7 +182,7 @@ class Markdown: def __init__(self, extensions=[], extension_configs={}, - safe_mode = False, + safe_mode = False, output_format=DEFAULT_OUTPUT_FORMAT): """ Creates a new Markdown instance. @@ -200,12 +200,12 @@ class Markdown: * "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1). * "html4": Outputs HTML 4 * "html": Outputs latest supported version of HTML (currently HTML 4). - Note that it is suggested that the more specific formats ("xhtml1" + Note that it is suggested that the more specific formats ("xhtml1" and "html4") be used as "xhtml" or "html" may change in the future - if it makes sense at that time. + if it makes sense at that time. """ - + self.safeMode = safe_mode self.registeredExtensions = [] self.docType = "" @@ -300,9 +300,9 @@ class Markdown: # Map format keys to serializers self.output_formats = { - 'html' : html4.to_html_string, + 'html' : html4.to_html_string, 'html4' : html4.to_html_string, - 'xhtml' : etree.tostring, + 'xhtml' : etree.tostring, 'xhtml1': etree.tostring, } @@ -348,7 +348,8 @@ class Markdown: self.references.clear() for extension in self.registeredExtensions: - extension.reset() + if hasattr(extension, 'reset'): + extension.reset() def set_output_format(self, format): """ Set the output format for the class instance. """ @@ -546,8 +547,8 @@ def load_extension(ext_name, configs = []): # function called makeExtension() try: return module.makeExtension(configs.items()) - except AttributeError: - message(CRITICAL, "Failed to initiate extension '%s'" % ext_name) + except AttributeError, e: + message(CRITICAL, "Failed to initiate extension '%s': %s" % (ext_name, e)) def load_extensions(ext_names): @@ -588,15 +589,15 @@ def markdown(text, * "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1). * "html4": Outputs HTML 4 * "html": Outputs latest supported version of HTML (currently HTML 4). - Note that it is suggested that the more specific formats ("xhtml1" + Note that it is suggested that the more specific formats ("xhtml1" and "html4") be used as "xhtml" or "html" may change in the future - if it makes sense at that time. + if it makes sense at that time. Returns: An HTML document as a string. """ md = Markdown(extensions=load_extensions(extensions), - safe_mode=safe_mode, + safe_mode=safe_mode, output_format=output_format) return md.convert(text) @@ -608,7 +609,7 @@ def markdownFromFile(input = None, safe_mode = False, output_format = DEFAULT_OUTPUT_FORMAT): """Read markdown code from a file and write it to a file or a stream.""" - md = Markdown(extensions=load_extensions(extensions), + md = Markdown(extensions=load_extensions(extensions), safe_mode=safe_mode, output_format=output_format) md.convertFile(input, output, encoding) |