An open API service indexing awesome lists of open source software.

https://github.com/xinlin-z/toc4github

Generate Table of Contents (TOC) for Github Markdown file (like README.md) automatically
https://github.com/xinlin-z/toc4github

github markdown python toc toc-generator

Last synced: 4 months ago
JSON representation

Generate Table of Contents (TOC) for Github Markdown file (like README.md) automatically

Awesome Lists containing this project

README

        

# toc4github

* [Install](#Install)
* [Usage](#Usage)
* [Showcase](#Showcase)

The `toc4github` is a very tiny tool to automatically generate Table of
Contents (TOC) for Markdown file, especially for README.md in Github.com.
It might also be used for other markdown rendering system, but
I never tested! :)

## Install

``` shell
$ pip install toc4github
$ python -m toc4github -h # inline help
```

## Usage

You should insert a placeholder which is `{toc}` in README.md. The
placeholder ocuppies a whole line. Then:

``` shell
$ python -m toc4github [-d] [-t TITLE]
```

Now, the placeholder is replaced by TOC generated with an optional title,
and your markdown file is updated.

Or, you can call `make_toc` interface in your python code. It returns
the TOC as string in accordance with input, and you can do anything
you want with it.

``` python
# how to import
from toc4github import make_toc
# signature
def make_toc(lines: Iterable[str]|str) -> str: ...
```

## Showcase

![toc4github](/showcase.png)

In addition, All my repos' TOC are generated by toc4github.
Have fun ... ^___^