Skip to main content

Generate a table of contents for a Markdown file.

Project description

Markdown Table of Contents Generator

This Python script automates the generation and management of a Table of Contents (TOC) for your Markdown files. It scans the Markdown file for headers and creates a TOC with clickable links to the respective sections. The script can update an existing TOC or insert a new one if none exists.

toc_markdown

Table of Contents

  1. Features
  2. Getting Started
    1. Prerequisites
    2. Installation
  3. Integration with Vim

Features

  • Automatic generation of a table of contents for your Markdown files.
  • Updates an existing TOC or inserts a new one if not present.
  • Supports headers of levels 2 to 3.
  • Generates clickable links to the corresponding sections within the document.
  • Maintains the structure and formatting of the Markdown file.

Getting Started

Prerequisites

  • Python 3.6

Installation

git clone https://github.com/sderev/toc-markdown.git

Integration with Vim

To streamline the process of updating the TOC in your Markdown files, ensure that the toc-markdown script is either accessible from your PATH or provide its absolute path in the Vim configuration.

  • Add the toc-markdown script to your PATH environment variable. This step allows Vim to execute the script directly.

    OR

  • If the toc-markdown script is not in the PATH, provide its absolute path in the Vim configuration below.

Then, open your .vimrc file and add the following line:

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

With the above configuration, you can press <leader>t while in normal mode within a Markdown file in Vim. It will save the file, execute the toc-markdown script on it, and reload the updated file, displaying the updated 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.1.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distribution

toc_markdown-0.0.1-py3-none-any.whl (8.4 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