Skip to main content

Generate a table of contents markdown file

Project description

mkdocs-toc-md

mkdocs-toc-md is a plugin for mkdocs that generates a table of contents in markdown format. To render the table of contents as HTML, the markdown file must be generated before running mkdocs build.

Sample

File
Site

Usage

Generates toc markdown file.

  1. Install plugin.

    pip install mkdocs-toc-md
    
  2. Add plugin config to mkdocs.yml.

    plugins:
      - toc-md
    
  3. Run mkdocs serve to output the toc md file.

  4. Check docs/index.md.

Adds description.

If you use metadata (front matter), set the value with toc_md_description as a key.

---
toc_md_description: pickup target value
---

or use options pickup_description_meta pickup_description_class.

Options

Minimum

plugins:
  - toc-md:

Full

plugins:
  - toc-md:
      toc_page_title: Contents
      toc_page_description: Usage mkdocs-toc-md
      header_level: 3
      pickup_description_meta: false
      pickup_description_class: false
      output_path: index.md
      output_log: false
      ignore_page_pattern: index.*.md$
      remove_navigation_page_pattern: index.*.md$
      template_dir_path: custom_template
      integrate_mkdocs_static_i18n: true
      languages:
        en:
          toc_page_title: Contents
          toc_page_description: Usage mkdocs-toc-md
        ja:
          toc_page_title: 目次
          toc_page_description: mkdocs-toc-mdプラグインの使い方
      shift_header: after_h1_of_index
      extend_module: true
      output_comment: html

toc_page_title: str

h1 text in the table of contents markdown file.

default: Contents

toc_page_description: str

The description will be rendered below the h1 tag in the table of contents.

default: None

header_level: int

Header level (depth) to render.
h1→1, h2→2, ...

default: 3

pickup_description_meta: bool

The plugin renders the description after the h2 header in the table of contents markdown file. If you use metadata (front matter), there is no need to set this option.

<mata name="description" content="pickup target value" />

default: False

pickup_description_class: bool

The plugin renders the description after the h2 header in the table of contents markdown file. If you use metadata (front matter), there is no need to set this option.

# mkdocs-toc-md

<div class="toc-md-description">
pickup target value
</div>

default: False

output_path: str

Path to save rendered toc md file.
index.md → docs/index.md

default: index.md

output_log: bool

Output contents of markdown file to console.

default: False

ignore_page_pattern: str

Regular expression pattern of markdown file names to be excluded from toc markdown file.
To prevent the table of contents page from listing itself, set the same value as the output file name (output_path).

default: ''

remove_navigation_page_pattern: str

Regular expression pattern of markdown file names to remove navigation items.
To hide the navigation on the table of contents page, set the same value as the output file name (output_path).

default: ''

template_dir_path: str

Path of template dir. Put toc.md.j2 in your custom template dir.

default: ''

beautiful_soup_parser: str

Parser used in BeautifulSoup. Default is html.parser.
If using html5lib or lxml, you need to install additional dependencies.

default: html.parser

integrate_mkdocs_static_i18n: bool

With mkdocs-static-i18n

default: False

languages: dict

Use with integrate_mkdocs_static_i18n option. Set toc_page_title, toc_page_description for each language.

languages:
    en:
        toc_page_title: Contents
        toc_page_description: Usage mkdocs-toc-md
    ja:
        toc_page_title: 目次
        toc_page_description: mkdocs-toc-mdプラグインの使い方

default: dict()

shift_header: str (after_index, after_h1_of_index, none)

after_index
Shifts the header level(+1) except for the index file in the directory.

after_h1_of_index
Shifts the header level(+1) after h1 in index file and except for the index file in the directory.

none (default)

extend_module: bool

Some processes can be extended by placing the toc_extend_module.py file in the docs folder.

├─ docs
│  ├─ mkdocs.yml
│  ├─ toc_extend_module.py

Sample/toc_extend_module.py

find_src_elements -> list[bs4.element.Tag]
args

  1. bs_page_soup: bs4.BeautifulSoup
  2. page: mkdocs.structure.pages.Page
  3. toc_config: mkdocs_toc_md.objects.TocConfig

create_toc_items -> list[mkdocs_toc_md.objects.TocItem]
args

  1. page: mkdocs.structure.pages.Page
  2. page_description: str
  3. src_elements: list[bs4.element.Tag]
  4. toc_config: mkdocs_toc_md.objects.TocConfig

on_create_toc_item
args

  1. toc_item: mkdocs_toc_md.objects.TocItem
  2. src_element: bs4.element.Tag
  3. page: mkdocs.structure.pages.Page
  4. toc_config: mkdocs_toc_md.objects.TocConfig

on_before_output
args

  1. nav: mkdocs.structure.nav.Navigation
  2. toc_items: list[mkdocs_toc_md.objects.TocItem]
  3. toc_config: mkdocs_toc_md.objects.TocConfig

output_comment: str (html, metadata, none)

html (default)

<!-- ====================== TOC ====================== -->
<!-- Generated by mkdocs-toc-md plugin -->
<!-- ================================================= -->

metadata

---
toc_output_comment: Generated by mkdocs-toc-md plugin
---

none

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs-toc-md-0.0.9.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_toc_md-0.0.9-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-toc-md-0.0.9.tar.gz.

File metadata

  • Download URL: mkdocs-toc-md-0.0.9.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.2 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.4

File hashes

Hashes for mkdocs-toc-md-0.0.9.tar.gz
Algorithm Hash digest
SHA256 907fa1ed9bc0ddfc3ebb8881acbf8c4bf98ef442964c57906a6cb37f6fd179ef
MD5 121634a072c776252abac633d243c675
BLAKE2b-256 b14f27dfa123019f56a5381c2bf5a261b13593778cb48dc6a9a1e51a3aad0cee

See more details on using hashes here.

File details

Details for the file mkdocs_toc_md-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_toc_md-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.2 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.4

File hashes

Hashes for mkdocs_toc_md-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f2b25ef71efba40d8ba0f5034533c39e2dc00319051e9a037c439dc467fe250e
MD5 8b5ab021f1eebcc799e69b2adaf27f1f
BLAKE2b-256 cdbb41ee7616b03f9937f94605c203fb21c88ed5420da650ce344ede3d481fd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page