Metadata-Version: 2.1
Name: toc4github
Version: 0.16
Summary: Generate Table of Contents (TOC) for Markdown file (like README.md) automatically
Project-URL: homepage, https://github.com/xinlin-z/toc4github
Author-email: xinlin-z <xinlin.zhang@hotmail.com>
License: MIT License
        
        Copyright (c) 2020 xinlin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: README.md,TOC,github,markdown
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# Table of Contents

* [Intro](#Intro)
* [Install](#Install)
* [Command Line Usage](#Command-Line-Usage)
* [API](#API)
* [Showcase](#Showcase)

# Intro

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

# Install

``` shell
$ pip3 install toc4github
```

# Command Line Usage

You should insert a line of placeholder with content `{toc}` in README.md.

The placeholder itself must be single line, and it most likely be
at the beginning of markdown file. This is the start position
of TOC section.

When the placeholder line is ready:

``` shell
$ python3 -m toc4github [--dryrun|-d] [--title|-t] <path/to/README.md>
```

Now, the placeholder line is replaced and expanded by TOC generated,
your markdown file is updated.

You can use `--dryrun(-d)` to check the generated TOC first, this option
would only print out TOC, file is intact and nothing is changed.

`--title(-t)` option is used if you need a title for TOC section.
The title is fixed with `Table of Contents`, just like this README.md file.

Different languages can be mixed, but I only tested English and Chinese.

Here is an example:

``` shell
$ python3 -m toc4github -dt text.txt
# Table of Contents

* [Hello](#Hello)
    * [Past 过去](#Past-过去)
    * [Present 现在](#Present-现在)
        * [Item-1](#Item-1)
        * [Item-2](#Item-2)
        * [Item-3](#Item-3)
        * [Item-4](#Item-4)
    * [Future 未来](#Future-未来)
    * [中英文can mix哦](#中英文can-mix哦)
```

# API

Or, you can call `make_toc` interface in your python code like:

``` python
>>> from toc4github import make_toc
>>>
>>> with open('text.txt') as f:
...     lines = f.read()
...
>>> print(lines)  # show original content
{toc}

# Hello

Hi, here is a test.

## Past 过去

Past is full of bloody experiences and cheerful memories.

## Present 现在

Present is the only thing you have.

### Item-1

TODO

### Item-2

### Item-3

### Item-4

## Future 未来

Future is created by your imagination.

## 中英文can mix哦

>>> print(make_toc(lines))  # show TOC
* [Hello](#Hello)
    * [Past 过去](#Past-过去)
    * [Present 现在](#Present-现在)
        * [Item-1](#Item-1)
        * [Item-2](#Item-2)
        * [Item-3](#Item-3)
        * [Item-4](#Item-4)
    * [Future 未来](#Future-未来)
    * [中英文can mix哦](#中英文can-mix哦)
>>>
```

Interface `make_toc` only return the generated TOC, you should
insert it to your file anywhere you like by yourself. And this
is the only interface toc4github provides.

# Showcase

![toc4github](/showcase.png)

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

