Generate table of contents for markdown files
Project description
Markdown Contents Generator
Generate table of contents for markdown files.
Installation
Install via PIP
Install via python pip (python3 required):
pip install markdown-contents-generator --user
Install from Source
Clone git-repository and make setup inside the project directory:
git clone https://github.com/fadich/markdown-contents-generator.git \
&& cd markdown-contents-generator
python3 setup.py install
Usage
Once the package installed, it provides a console command:
md-contents-generator
You can call it with no arguments to view the instructions. The only required parameter is a path to the markdown file which table of contents you're going to generate.
Generate Table of Contents
By proving MARKDOWN_FILEPATH
positional parameter, you can generate its contents and check the console output results. For example:
md-contents-generator README.md
You will see something like that (for this README.md file):
- [Usage](#usage)
- [Generate Table of Contents](#generate-table-of-contents)
- [Insert Table of Contents into a File](#insert-table-of-contents-into-a-file)
- [Replace Contents Tags](#replace-contents-tags)
- [Installation](#installation)
- [Install via PIP](#install-via-pip)
- [Install from Source](#install-from-source)
You can copy-paste it to the file you need or make auto-insertion to your working file (see below).
Insert Table of Contents into a File
Command can be called with optional --insert
flag:
md-contents-generator README.md --insert
This will automatically insert auto-generated contents inside the contents tags. So, before calling this command, add these tags to your markdown file:
...
<contents-start />
<--- Your table of contents will be inserted right here
<contents-finish />
...
Result should be like this:
...
<contents-start />
- [Usage](#usage)
- [Generate Table of Contents](#generate-table-of-contents)
- [Insert Table of Contents into a File](#insert-table-of-contents-into-a-file)
- [Replace Contents Tags](#replace-contents-tags)
- [Installation](#installation)
- [Install via PIP](#install-via-pip)
- [Install from Source](#install-from-source)
<contents-finish />
...
Note, that the insertion replaces everything inside the tags!
That's why, you can call it each time you update your markdown file to automatically update the table of contents. In common, these tags won't be rendered, and you can leave them in the source code if you prefer.
You can also add style="display: none"
(or any other attributes) for your tags if needed. The only necessary is to keep the tags naming and put single tag on a single line (multiline tags do not supported).
Replace Contents Tags
If you'd like to insert table of contents but don't want to leave these contents tags, just call the command with both --insert
and --replace-tags
flags:
md-contents-generator README.md --insert --replace-tags
However, in this case, you will not be able to update you table of contents, and will have to generate and insert the table of contents each time manually.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file markdown_contents_generator-1.0.1.tar.gz
.
File metadata
- Download URL: markdown_contents_generator-1.0.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 384df825e742dad5aba53cf394e79fd337b4c15c2dfbd4e3890b7df853aed030 |
|
MD5 | b5d9d47c30de03010308f91bcb6d35ae |
|
BLAKE2b-256 | d3ecc0b673d29f89d8e4982e5998ad5b6149732e43bd6be13d3f66559d39b4d8 |