diff options
author | Waylan Limberg <waylan@gmail.com> | 2012-01-24 11:48:08 -0800 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2012-01-24 11:48:08 -0800 |
commit | 9e0ec80dc23d1c8d2304b3dfdd25b3f519948f9c (patch) | |
tree | 12138b0b3f9f2cdf113e5ff2c6b8a5b03d6e790d | |
parent | a9cd895467b3caa08d585458fdcbcc5525356493 (diff) | |
parent | f23535ee0b032d97f22552b779a97768f65d7436 (diff) | |
download | markdown-9e0ec80dc23d1c8d2304b3dfdd25b3f519948f9c.tar.gz markdown-9e0ec80dc23d1c8d2304b3dfdd25b3f519948f9c.tar.bz2 markdown-9e0ec80dc23d1c8d2304b3dfdd25b3f519948f9c.zip |
Merge pull request #50 from nud/import-extensions
Allow specifying the full module name for extensions.
-rw-r--r-- | markdown/__init__.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index 4fb3057..013fdc8 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -184,20 +184,21 @@ class Markdown: pairs = [x.split("=") for x in ext_args.split(",")] configs.update([(x.strip(), y.strip()) for (x, y) in pairs]) - # Setup the module names - ext_module = 'markdown.extensions' - module_name_new_style = '.'.join([ext_module, ext_name]) - module_name_old_style = '_'.join(['mdx', ext_name]) + # Setup the module name + module_name = ext_name + if '.' not in ext_name: + module_name = '.'.join(['markdown.extensions', ext_name]) # Try loading the extension first from one place, then another try: # New style (markdown.extensons.<extension>) - module = __import__(module_name_new_style, {}, {}, [ext_module]) + module = __import__(module_name, {}, {}, [module_name.rpartition('.')[0]]) except ImportError: + module_name_old_style = '_'.join(['mdx', ext_name]) try: # Old style (mdx_<extension>) module = __import__(module_name_old_style) except ImportError: logger.warn("Failed loading extension '%s' from '%s' or '%s'" - % (ext_name, module_name_new_style, module_name_old_style)) + % (ext_name, module_name, module_name_old_style)) # Return None so we don't try to initiate none-existant extension return None |