diff options
author | Waylan Limberg <waylan@gmail.com> | 2014-07-31 22:40:33 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2014-07-31 22:40:33 -0400 |
commit | 47372051cf9724f1355b1c07c63c4beff9a5f626 (patch) | |
tree | 82130393bfa7118cab45a80579fbed2eeed05261 /markdown/util.py | |
parent | aae373860b5c5cbb40f126bf5acb9693dc577c4a (diff) | |
download | markdown-47372051cf9724f1355b1c07c63c4beff9a5f626.tar.gz markdown-47372051cf9724f1355b1c07c63c4beff9a5f626.tar.bz2 markdown-47372051cf9724f1355b1c07c63c4beff9a5f626.zip |
Update extensions for Extension.__init__ refactor
Fixes #325. All extensions can now accept a dict of configs or
**kwargs, not just a list of tuples. Third party extensions may want
to follow suite. Extensions may only accept keyword arguments
in the future. These changes still need to be documented.
A couple things of note:
The CodeHilite extension previously issued a DeprecationWarning
if the old config key `force_linenos` was used. With thins change,
a KeyError will now be raised.
The `markdown.util.parseBoolValue` function gained a new argument:
`preserve_none` (defaults to False), which when set to True, will
pass None through unaltered (will not convert it to False).
Diffstat (limited to 'markdown/util.py')
-rw-r--r-- | markdown/util.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/markdown/util.py b/markdown/util.py index cdad775..d5deaba 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -86,16 +86,21 @@ def isBlockLevel(tag): # Some ElementTree tags are not strings, so return False. return False -def parseBoolValue(value, fail_on_errors=True): +def parseBoolValue(value, fail_on_errors=True, preserve_none=False): """Parses a string representing bool value. If parsing was successful, - returns True or False. If parsing was not successful, raises - ValueError, or, if fail_on_errors=False, returns None.""" + returns True or False. If preserve_none=True, returns True, False, + or None. If parsing was not successful, raises ValueError, or, if + fail_on_errors=False, returns None.""" if not isinstance(value, string_type): + if preserve_none and value is None: + return value return bool(value) elif value.lower() in ('true', 'yes', 'y', 'on', '1'): return True elif value.lower() in ('false', 'no', 'n', 'off', '0'): return False + elif preserve_none and value.lower() == 'none': + return None elif fail_on_errors: raise ValueError('Cannot parse bool value: %r' % value) |