Skip to main content

MkDocs Plugin to enumerate the headings (h1-h6) across site pages

Project description

Actions Status PyPI - Python Version PyPI PyPI - Downloads codecov GitHub contributors PyPI - License

mkdocs-enumerate-headings-plugin

MkDocs Plugin to enumerate the headings (h1-h6) across site pages

Features :star2:

  • Automatically number all headings and give each page an sequential chapter number
  • Compatible with plugins like awesome-pages and monorepo
  • Compatible with markdown_extensions like pymdownx.snippets
  • Easy to customize styling through CSS

demo screencast

Setup

Install the plugin using pip:

pip3 install mkdocs-enumerate-headings-plugin

Next, add the following lines to your mkdocs.yml:

plugins:
  - search
  - enumerate-headings

If you have no plugins entry in your config file yet, you'll likely also want to add the search plugin. MkDocs enables it by default if there is no plugins entry set.

Usage

There is only one requirement: make sure each markdown page starts with a level 1 header (#). Pages with no headings and pages with multiple level 1 headings are allowed.

Note this plugin only affects your rendered HTML and does not affect the markdown files.

Styling

All heading numbers are wrapped in <span class='enumerate-headings-plugins'></span> and can be styled using CSS. See MkDocs documentation for customizing a theme on how to add an CSS to your theme.

As an example you can make the numbering lighter than the heading title by saving the CSS snippet below to a file and adding it to your MkDocs site using the extra_css setting in your mkdocs.yml file.

/* Extra CSS for mkdocs-enumerate-headings-plugin */ 
.enumerate-headings-plugins {
  /* 100% is baseline so 250% is a lot lighter */
  filter: brightness(250%);
}

Options

You can customize the plugin by setting options in mkdocs.yml:

plugins:
    - enumerate-headings:
        strict: true
  • strict (default true): Raise errors instead of warnings when first heading on a page is not a level one heading (single #). Note that in strict: false mode the heading numbers might be incorrect between pages and before and after a level 1 heading.

Contributing

Contributions are very welcome! Please read CONTRIBUTING.md before putting in any work.

This plugin was inspired by ignorantshr/mkdocs-add-number-plugin, which focuses on enumerating single selected pages.

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-enumerate-headings-plugin-0.2.tar.gz (9.2 kB view hashes)

Uploaded Source

Built Distribution

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