Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.8k stars 862 forks source link

TOC extension: ignore headers above [TOC] marker #1457

Closed pozitron57 closed 7 months ago

pozitron57 commented 7 months ago

Is it possible to ignore headers that are located above the [TOC] marker?

Example:

# Name of the page (header not shown in TOC)

[TOC]

## Header 1

## Header 2

### Header 2.1

## Header 3
waylan commented 7 months ago

Not directly, no. However, you may be able to get that result with the toc_depth setting. For example, in the example document you provided setting toc_depth='2-6' would have that effect. However, if you happened to have any h1 level heading after the marker, those would also be excluded.

pozitron57 commented 7 months ago

Thanks, it works for my use cases. Actually I knew about the toc_depth option but it didn't come to my mind that it fits my situation.