From: Waylan L. <way...@ic...> - 2014-08-22 19:20:23
|
If you haven't been following along, I have recently made some changes to the config settings code for Python-Markdown extensions. In order to address [#325], the `extension_configs` keyword on the `markdown.Markdown` class now accepts a dict rather than a list of tuples (a list of tuples is still accepted for backward compatibility).[^1] With that change made, it was rather easy to then implement an [`--extension_configs`] option on the command line which takes a file name and parses a YAML or JSON file to get the dict of extension configs which it then passes to the `extension_configs` keyword on the `markdown.Markdown` class. As a reminder, previously, the only way to pass extension configs in from the command line was with this very limited syntax: $ python -m markdown -x "footnotes(PLACE_MARKER=~~~~~~~~,UNIQUE_IDS=1)" input.txt Now that we have a better (more expressive) way to do so, the old way doesn't hold much value. After all, it allowed for no spaces or quotes and passing Boolean values or None was a little tricky. Passing Python objects was impossible (e.g.: one of the WikiLink Extension's options accepts a callable).[^2] So, any objections to deprecating the old syntax? A few things to note: * We would issue a PendingDeprecationWarning with the 2.5 release and a DecrecationWarning with the 2.6 release. The feature would go away with 2.7. * I am aware that some people have also been using this syntax from within python as well (e.g.: `markdown.markdown(text, extensions=['footnotes(PLACE_MARKER=~~~~~~~~,UNIQUE_IDS=1)'])`). Deprecating support would include this as well. * The docs have favored passing in extension instances for a while and lists this feature as the last alternative (with a warning). If we made the change, people following the docs shouldn't be affected. * I realize that the docs didn't always prioritize the various options properly. There could be many users who are using this anyway. [^1]: Extension authors should check out the [new methods added] to the `Extension` class and how the [existing extensions] take advantage of that. No more need to reference `self.config['somekey'][0]` in your code to get or set a config setting. While the underlying data structure is the same, everything can be done through easy to use methods which hides the implementation details. [^2]: I haven't tested it yet, but the PyYaml lib allows you to reference a python [object] through python dot notation. When the YAML file is parsed, the resulting value in the data structure will be that python object. [#325]: https://github.com/waylan/Python-Markdown/issues/325 [`--extension_configs`]: https://github.com/waylan/Python-Markdown/commit/4100336fba3a362ac45def3aa8e79e9af76eed7e [new methods added]: https://github.com/waylan/Python-Markdown/commit/aae373860b5c5cbb40f126bf5acb9693dc577c4a [existing extensions]: https://github.com/waylan/Python-Markdown/commit/47372051cf9724f1355b1c07c63c4beff9a5f626 [object]: http://pyyaml.org/wiki/PyYAMLDocumentation#Objects Waylan Limberg |