Skip to content

Commit 39c8c1c

Browse files
author
Waylan Limberg
committed
Fixed TOC Option parsing.
The new option parser assumes bool values if the default is bool or None. As the "title" option is not a bool value, it should default to an empty string rather than None. Fixes #347.
1 parent 5fa6d0b commit 39c8c1c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

markdown/extensions/toc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def __init__(self, *args, **kwargs):
216216
"slugify" : [slugify,
217217
"Function to generate anchors based on header text - "
218218
"Defaults to the headerid ext's slugify function."],
219-
"title" : [None,
219+
"title" : ["",
220220
"Title to insert into TOC <div> - "
221-
"Defaults to None"],
221+
"Defaults to an empty string"],
222222
"anchorlink" : [0,
223223
"1 if header should be a self link - "
224224
"Defaults to 0"],

tests/test_apis.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def create_config_file(self, config):
590590
with os.fdopen(fd, 'w') as fp:
591591
fp.write(config)
592592

593-
def testExtensonConfigOption(self):
593+
def testExtensionConfigOption(self):
594594
config = {
595595
'markdown.extensions.wikilinks': {
596596
'base_url': 'http://example.com/',
@@ -606,6 +606,19 @@ def testExtensonConfigOption(self):
606606
self.default_options['extension_configs'] = config
607607
self.assertEqual(options, self.default_options)
608608

609+
def textBoolExtensionConfigOption(self):
610+
config = {
611+
'markdown.extensions.toc': {
612+
'title': 'Some Title',
613+
'anchorlink': True,
614+
'permalink': True
615+
}
616+
}
617+
self.create_config_file(config)
618+
options, logging_level = parse_options(['-c', self.tempfile])
619+
self.default_options['extension_configs'] = config
620+
self.assertEqual(options, self.default_options)
621+
609622
def testExtensonConfigOptionAsJSON(self):
610623
config = {
611624
'markdown.extensions.wikilinks': {

0 commit comments

Comments
 (0)