This is a project fork. Note that some documentation might not have been brought up to date yet.
Generating your Markdown Table of Contents
markdown-toc
is a small application written in Go that helps you generate a
Table of Contents (ToC) for your Markdown file. There are already a number of
scripts etc doing this, but I failed to find one that suited my needs.
In short the features of markdown-toc
are:
- Cross platform (OS X, Linux, Windows)
- Replacement of an existing ToC
- The new file can be written to
stdout
or overwritten on disk
- The new file can be written to
- Able to skip
n
number of initial headers - Configurable depth of headers to include
- Customizable header for the table of contents
Please star the project if you like it!
- Table of Contents
- Installation
- Example usage
- Helping out!
- Releasing new versions
- Contributors
- License
The project has a Docker image that you can use easily:
docker run -v $(pwd)":/app" -w /app --rm -it sebdah/markdown-toc README.md
The above will mount your current directory into the Docker container. Just
modify the -v
flag according to your needs if you need to modify some other
folder.
markdown-toc
is the ENTRYPOINT
in the Dockerfile
, which means that it's
the default command.
Currently the easiest way is to clone the repository and run:
make install
You will end up having a binary called markdown-toc
in your system afterwards.
Command:
markdown-toc README.md
Output:
<!-- ToC start -->
# Table of Contents
- [`markdown-toc` - Generate your Table of Contents](#`markdown-toc`---generate-your-table-of-contents)
- [Example usage](#example-usage)
- [Generating a ToC to `stdout`](#generating-a-toc-to-`stdout`)
- [License](#license)
<!-- ToC end -->
Using the --depth
flag you can control how many labels of headers to include
in the output. If the --depth
is set to 1
, only level 1 headers are
included. Set this value to 0
(default) to include any depth of headers.
Command:
markdown-toc --depth 1 README.md
Output:
<!-- ToC start -->
# Table of Contents
- [`markdown-toc` - Generate your Table of Contents](#`markdown-toc`---generate-your-table-of-contents)
- [Example usage](#example-usage)
- [License](#license)
<!-- ToC end -->
By default we print a header like # Table of Contents
above the table of
contents. You can change the header to suit your project using the --header
flag.
Command:
markdown-toc --header "# ToC" README.md
Output:
<!-- ToC start -->
# ToC
- [`markdown-toc` - Generate your Table of Contents](#`markdown-toc`---generate-your-table-of-contents)
- [Example usage](#example-usage)
- [Generating a ToC to `stdout`](#generating-a-toc-to-`stdout`)
- [License](#license)
<!-- ToC end -->
By default we print a header like # Table of Contents
above the table of
contents. You can remove the header by providing --no-header
to the command.
Command:
markdown-toc --no-header README.md
Output:
<!-- ToC start -->
- [`markdown-toc` - Generate your Table of Contents](#`markdown-toc`---generate-your-table-of-contents)
- [Example usage](#example-usage)
- [Generating a ToC to `stdout`](#generating-a-toc-to-`stdout`)
- [License](#license)
<!-- ToC end -->
If you do not want to include n
number of initial headers in your ToC, you can
use the --skip-headers=1
flag. This is useful if you have your project name as
the first header and you don't really want that in the ToC for example.
Command:
markdown-toc --skip-headers=1 README.md
Output:
<!-- ToC start -->
- [Example usage](#example-usage)
- [Generating a ToC to `stdout`](#generating-a-toc-to-`stdout`)
- [License](#license)
<!-- ToC end -->
markdown-toc --replace README.md
This will print the full Markdown of README.md
and a table of contents section
will be injected into the Markdown based on the following rules:
- If no ToC was found, the ToC will be injected on top of the file
- If a section starting with
<!-- ToC start -->
and ending with<!-- ToC end -->
is found, it will be replaced with the new ToC.
markdown-toc --replace --inline README.md
This will overwrite the README.md
file on disk with the full Markdown of
README.md
and a table of contents section will be injected into the Markdown
based on the following rules:
- If no ToC was found, the ToC will be injected on top of the file
- If a section starting with
<!-- ToC start -->
and ending with<!-- ToC end -->
is found, it will be replaced with the new ToC.
There are many ways to help out with this project. Here are a few:
- Answer questions here
- Enhance the documentation
- Spread the good word on Twitter or similar places
- Implement awesome features. Some of the suggested features can be found here
make test
make build
From the master
branch run make release
. You will need to have access to
pushing to the GitHub project as well as Docker Hub.
- Sebastian Dahlgren (maintainer)
MIT license