Skip to content

Commit 367270c

Browse files
committed
Rename from max_level to link_depth
1 parent b0bd292 commit 367270c

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

docs/extensions/toc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ The following options are provided to configure the output:
252252
included in the Table of Contents. To exclude this first level, you
253253
have to set `toc_depth` to `"4-6"`.
254254

255-
* **`max_level`**
256-
Define the highest heading level (deepest `<hN>`) for which to add anchor links or permalinks.
255+
* **`link_depth`**
256+
Add anchors/permalinks only to headings up to this depth (`h1``hN`).
257257
Defaults to `6`.
258258

259-
For example, setting max_level to `2` adds anchors only to `<h1>` and `<h2>` elements.
259+
For example, setting `link_depth` to `2` adds anchors only to `<h1>` and `<h2>` elements.
260260

261261
A trivial example:
262262

markdown/extensions/toc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def __init__(self, md: Markdown, config: dict[str, Any]):
257257
self.permalink_class: str = config["permalink_class"]
258258
self.permalink_title: str = config["permalink_title"]
259259
self.permalink_leading: bool | None = parseBoolValue(config["permalink_leading"], False)
260-
self.header_rgx = re.compile(f'[Hh][1-{config["max_level"]}]')
260+
self.header_rgx = re.compile(f'[Hh][1-{config["link_depth"]}]')
261261
if isinstance(config["toc_depth"], str) and '-' in config["toc_depth"]:
262262
self.toc_top, self.toc_bottom = [int(x) for x in config["toc_depth"].split('-')]
263263
else:
@@ -466,9 +466,10 @@ def __init__(self, **kwargs):
466466
'separated by a hyphen in between (`2-5`) defines the top (t) and the bottom (b) (<ht>..<hb>). '
467467
'Default: `6` (bottom).'
468468
],
469-
'max_level': [
469+
'link_depth': [
470470
6,
471-
'Define the max heading level for which to add anchors/permalinks.'
471+
'Add anchors/permalinks only to headings up to this depth (`h1`–`hN`). '
472+
'For example, `link_depth: 2` adds them to `h1` and `h2` only. '
472473
'Default: `6`'
473474
]
474475
}

tests/test_syntax/extensions/test_toc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def testAnchorLinkWithDoubleInlineCode(self):
555555
extensions=[TocExtension(anchorlink=True)]
556556
)
557557

558-
def testAnchorLinkWithMaxLevel(self):
558+
def testAnchorLinkWithLinkDepth(self):
559559
self.assertMarkdownRenders(
560560
self.dedent(
561561
'''
@@ -570,7 +570,7 @@ def testAnchorLinkWithMaxLevel(self):
570570
<h2>Header <em>2</em></h2>
571571
'''
572572
),
573-
extensions=[TocExtension(anchorlink=True, max_level=1)]
573+
extensions=[TocExtension(anchorlink=True, link_depth=1)]
574574
)
575575

576576
def testPermalink(self):

0 commit comments

Comments
 (0)