#content #table #plugin #markdown-it #markdown-tables #create #document

markdown-it-table-of-contents

Creates a table of contents in Markdown documents

1 unstable release

new 0.1.0 Feb 20, 2025

#3 in #markdown-it

BSD-3-Clause

10KB
209 lines

markdown-it-table-of-contents

Plugin for markdown-it.rs which adds a table of contents to the page.

Note that this library does generate its own ids for your headers, but only if there is not already a present id.

Options

The following options are available under the TOCOptions object; however, the defaults are recommended.

TOCOptions {
    allow_titles_in_toc: false,                    // Include title (h1) in table of contents.
    treat_title_as_h2: false,                      // Whether to treat the title as an heading element (h2).
    toc_class: "table_of_contents".to_string(),    // Class given to the table of contents.
                                                   // If wrap_in_nav is true, the class is applied to the nav
                                                   // element, otherwise it's applied to the list (ol) element.
    wrap_in_nav: true,                             // If the table of contents should be wrapped in a nav element
    toc_heading: Some((2, "Contents".to_string())) // Heading placed at the top of the table of contents (but within
                                                   // nav if wrap_in_nav is true).
}

Dependencies

~7–16MB
~219K SLoC