From 9d388a8ee26934c7b4685374ed7afbf5219d1995 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 29 Aug 2014 14:11:57 -0400 Subject: More updates to test configs. The last few extensions were updated to accept dicts/**kwargs as configs and more tests were updated. Also updated extra to actually accept configs. Note that extra requires an extra level of dicts. First you need to indicate tha the settings are for extra, then, which extension extra wraps. I'm not crazy abount this, bit not sur ehow else to do it without making all the configs a global attribute on the Markdown class to that any extention can access any other extensions config settings. I don't think we wnat to do that. Also updated extra to use dot notation for the sub-extensions. --- markdown/__init__.py | 4 ++-- markdown/extensions/extra.py | 22 ++++++++++++++-------- markdown/extensions/headerid.py | 5 ++--- tests/extensions/extra/extra_config.html | 9 +++++++++ tests/extensions/extra/extra_config.txt | 5 +++++ tests/extensions/extra/test.cfg | 8 ++++++++ tests/test_apis.py | 4 ++-- 7 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 tests/extensions/extra/extra_config.html create mode 100644 tests/extensions/extra/extra_config.txt diff --git a/markdown/__init__.py b/markdown/__init__.py index 28f30c8..0fdcd97 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -218,11 +218,11 @@ class Markdown(object): if class_name: # Load given class name from module. - return getattr(module, class_name)(configs.items()) + return getattr(module, class_name)(configs=configs) else: # Expect makeExtension() function to return a class. try: - return module.makeExtension(configs.items()) + return module.makeExtension(configs=configs) except AttributeError as e: message = e.args[0] message = "Failed to initiate extension " \ diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py index c5526d1..4044a87 100644 --- a/markdown/extensions/extra.py +++ b/markdown/extensions/extra.py @@ -36,19 +36,25 @@ from ..blockprocessors import BlockProcessor from .. import util import re -extensions = ['smart_strong', - 'fenced_code', - 'footnotes', - 'attr_list', - 'def_list', - 'tables', - 'abbr', - ] +extensions = [ + 'markdown.extensions.smart_strong', + 'markdown.extensions.fenced_code', + 'markdown.extensions.footnotes', + 'markdown.extensions.attr_list', + 'markdown.extensions.def_list', + 'markdown.extensions.tables', + 'markdown.extensions.abbr' +] class ExtraExtension(Extension): """ Add various extensions to Markdown class.""" + def __init__(self, *args, **kwargs): + """ config is just a dumb holder which gets passed to actual ext later. """ + self.config = kwargs.pop('configs', {}) + self.config.update(kwargs) + def extendMarkdown(self, md, md_globals): """ Register extension instances. """ md.registerExtensions(extensions, self.config) diff --git a/markdown/extensions/headerid.py b/markdown/extensions/headerid.py index 9af94df..f7b7805 100644 --- a/markdown/extensions/headerid.py +++ b/markdown/extensions/headerid.py @@ -117,7 +117,7 @@ class HeaderIdTreeprocessor(Treeprocessor): class HeaderIdExtension(Extension): - def __init__(self, configs): + def __init__(self, *args, **kwargs): # set defaults self.config = { 'level' : ['1', 'Base level for headers.'], @@ -126,8 +126,7 @@ class HeaderIdExtension(Extension): 'slugify' : [slugify, 'Callable to generate anchors'], } - for key, value in configs: - self.setConfig(key, value) + super(HeaderIdExtension, self).__init__(*args, **kwargs) def extendMarkdown(self, md, md_globals): md.registerExtension(self) diff --git a/tests/extensions/extra/extra_config.html b/tests/extensions/extra/extra_config.html new file mode 100644 index 0000000..0143145 --- /dev/null +++ b/tests/extensions/extra/extra_config.html @@ -0,0 +1,9 @@ +
+
+
    +
  1. +

    A Footnote. 

    +
  2. +
+
+

Some text with a footnote1.

\ No newline at end of file diff --git a/tests/extensions/extra/extra_config.txt b/tests/extensions/extra/extra_config.txt new file mode 100644 index 0000000..2d29819 --- /dev/null +++ b/tests/extensions/extra/extra_config.txt @@ -0,0 +1,5 @@ +~~~placemarker~~~ + +Some text with a footnote[^1]. + +[^1]: A Footnote. diff --git a/tests/extensions/extra/test.cfg b/tests/extensions/extra/test.cfg index ed3e8df..d956e2a 100644 --- a/tests/extensions/extra/test.cfg +++ b/tests/extensions/extra/test.cfg @@ -26,3 +26,11 @@ tables_and_attr_list: extensions: - markdown.extensions.tables - markdown.extensions.attr_list + +extra_config: + extensions: + - markdown.extensions.extra + extension_configs: + markdown.extensions.extra: + markdown.extensions.footnotes: + PLACE_MARKER: ~~~placemarker~~~ diff --git a/tests/test_apis.py b/tests/test_apis.py index b8597e8..010bf70 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -320,11 +320,11 @@ def _create_fake_extension(name, has_factory_func=True, is_wrong_type=False, use # mod_name must be bytes in Python 2.x mod_name = bytes(mod_name) ext_mod = types.ModuleType(mod_name) - def makeExtension(configs=None): + def makeExtension(*args, **kwargs): if is_wrong_type: return object else: - return markdown.extensions.Extension(configs=configs) + return markdown.extensions.Extension(*args, **kwargs) if has_factory_func: ext_mod.makeExtension = makeExtension # Warning: this brute forces the extenson module onto the system. Either -- cgit v1.2.3