`. Defaults to `None`.
+* **`title_class`**:
+ CSS class used for the title contained in the Table of Contents. Defaults to `toctitle`.
+
* **`toc_class`**:
CSS class(es) used for the `
` containing the Table of Contents. Defaults to `toc`.
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py
index 33746d5e6..6d080deb7 100644
--- a/markdown/extensions/toc.py
+++ b/markdown/extensions/toc.py
@@ -161,6 +161,7 @@ def __init__(self, md, config):
self.slugify = config["slugify"]
self.sep = config["separator"]
self.toc_class = config["toc_class"]
+ self.title_class = config["title_class"]
self.use_anchors = parseBoolValue(config["anchorlink"])
self.anchorlink_class = config["anchorlink_class"]
self.use_permalinks = parseBoolValue(config["permalink"], False)
@@ -251,7 +252,8 @@ def build_toc_div(self, toc_list):
# Add title to the div
if self.title:
header = etree.SubElement(div, "span")
- header.attrib["class"] = "toctitle"
+ if self.title_class:
+ header.attrib["class"] = self.title_class
header.text = self.title
def build_etree_ul(toc_list, parent):
@@ -335,6 +337,9 @@ def __init__(self, **kwargs):
"title": ["",
"Title to insert into TOC
- "
"Defaults to an empty string"],
+ "title_class": ['toctitle',
+ 'CSS class used for the title. '
+ 'Defaults to "toctitle"'],
"toc_class": ['toc',
'CSS class(es) used for the link. '
'Defaults to "toclink"'],
diff --git a/tests/test_syntax/extensions/test_toc.py b/tests/test_syntax/extensions/test_toc.py
index d64c6d391..797643643 100644
--- a/tests/test_syntax/extensions/test_toc.py
+++ b/tests/test_syntax/extensions/test_toc.py
@@ -629,3 +629,45 @@ def testTOCWithCustomClasses(self):
),
extensions=[TocExtension(toc_class="custom1 custom2")]
)
+
+ def testTOCWithEmptyTitleClass(self):
+
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ [TOC]
+ # Header
+ '''
+ ),
+ self.dedent(
+ '''
+
+
+ '''
+ ),
+ extensions=[TocExtension(title_class="", title='ToC')]
+ )
+
+ def testTOCWithCustomTitleClass(self):
+
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ [TOC]
+ # Header
+ '''
+ ),
+ self.dedent(
+ '''
+
+
+ '''
+ ),
+ extensions=[TocExtension(title_class="tocname", title='ToC')]
+ )