Skip to main content

Generate a table of contents for a Markdown file.

Project description

Markdown Table of Contents Generator

This tool scans Markdown files to detect headers and subsequently creates a Table of Contents (TOC) with direct links to the respective sections. It either updates an existing TOC or generates a new one if none is found.

toc_markdown

Table of Contents

  1. Features
  2. Installation
  3. Integration with Vim

Features

  • Automatically generates a table of contents for your Markdown files.
  • Either updates an existing TOC or inserts a new one if absent.
  • Supports headers of levels 2 to 3.
  • Provides clickable links leading to the corresponding sections within the document.
  • Preserves the structure and formatting of the Markdown file.

Installation

To install, use pip or pipx:

pipx install toc-markdown

Integration with Vim

For a seamless experience in updating the TOC of your Markdown files through Vim, ensure the toc-markdown tool is either accessible from your PATH or specify its absolute path in the Vim configuration.

  • Include the toc-markdown tool in your PATH environment variable, enabling direct execution from Vim.

    OR

  • If the toc-markdown tool isn't in the PATH, specify its absolute path in the Vim configuration provided below.

Next, add the following line to your .vimrc file:

autocmd FileType markdown nnoremap <buffer> <leader>t :w<cr>:!toc-markdown %:p<cr>:e!<cr>

With this setup, simply press <leader>t in normal mode when editing a Markdown file in Vim. This will save the file, run the toc-markdown tool on it, and then reload the edited file to display the refreshed TOC.

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

toc-markdown-0.0.2.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

toc_markdown-0.0.2-py3-none-any.whl (8.5 kB view hashes)

Uploaded Python 3

Supported by

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