aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/util.py6
-rw-r--r--tests/test_apis.py5
2 files changed, 8 insertions, 3 deletions
diff --git a/markdown/util.py b/markdown/util.py
index d5deaba..0541e7b 100644
--- a/markdown/util.py
+++ b/markdown/util.py
@@ -95,12 +95,12 @@ def parseBoolValue(value, fail_on_errors=True, preserve_none=False):
if preserve_none and value is None:
return value
return bool(value)
+ elif preserve_none and value.lower() == 'none':
+ return None
elif value.lower() in ('true', 'yes', 'y', 'on', '1'):
return True
- elif value.lower() in ('false', 'no', 'n', 'off', '0'):
+ elif value.lower() in ('false', 'no', 'n', 'off', '0', 'none'):
return False
- elif preserve_none and value.lower() == 'none':
- return None
elif fail_on_errors:
raise ValueError('Cannot parse bool value: %r' % value)
diff --git a/tests/test_apis.py b/tests/test_apis.py
index e99f606..a5e0d73 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -455,6 +455,11 @@ class TestConfigParsing(unittest.TestCase):
self.assertParses('yES', True)
self.assertParses('FALSE', False)
self.assertParses(0., False)
+ self.assertParses('none', False)
+
+ def testPreserveNone(self):
+ self.assertTrue(markdown.util.parseBoolValue('None', preserve_none=True) is None)
+ self.assertTrue(markdown.util.parseBoolValue(None, preserve_none=True) is None)
def testInvalidBooleansParsing(self):
self.assertRaises(ValueError, markdown.util.parseBoolValue, 'novalue')