Skip to content

Commit

Permalink
swap old python based set for new golang version.
Browse files Browse the repository at this point in the history
  • Loading branch information
stakiran committed Jun 18, 2019
1 parent 32e824d commit 472bbd0
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 79 deletions.
199 changes: 120 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,210 +5,251 @@ TOC generator for Markdown.
<!-- toc -->
- [intoc](#intoc)
- [Feature](#feature)
- [Install](#install)
- [Requirement](#requirement)
- [CLI](#cli)
- [How to use](#how-to-use)
- [Usage](#usage)
- [Samples](#samples)
- [Basic](#basic)
- [Depth control](#depth-control)
- [Use not hyphen but aasterisk](#use-not-hyphen-but-aasterisk)
- [Use not hyphen but asterisk](#use-not-hyphen-but-asterisk)
- [Direct update](#direct-update)
- [Plain enumeration](#plain-enumeration)
- [No link format but keep list grammer](#no-link-format-but-keep-list-grammer)
- [How to develop](#how-to-develop)
- [Requirement](#requirement)
- [How to run](#how-to-run)
- [How to test](#how-to-test)
- [How to build](#how-to-build)
- [License](#license)
- [Author](#author)

:warning: This intoc is new version based on golang. The old python based version is [here](py).

## Feature

- Python based.
- Golang based.
- No WebAPI use.
- Multiple output ways.
- Output to the stdout
- Direct Update(Insert TOC to the next of `<!-- toc -->` line directly).
- Direct Update(Inserting TOC to the next of `<!-- toc -->` line directly).
- Support sections written in Japanese.

## How to use

```
$ git clone https://github.com/stakiran/intoc
$ cd intoc
$ python intoc.py -i (Target-Markdown-File)
$ intoc -input (Target-Markdown-File)
```

Create an alias if needed.

## Requirement

- Python 3 (Tested on Python 3.6 and Windows 7+)

## CLI

```
$ python intoc.py -h
usage: intoc.py [-h] -i INPUT [--indent-depth INDENT_DEPTH]
[--parse-depth PARSE_DEPTH] [--use-asterisk]
[--use-plain-enum] [--no-linkformat] [--edit]
[--edit-target EDIT_TARGET]
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
A input filename. (default: None)
--indent-depth INDENT_DEPTH
The number of spaces per a nest in TOC. (default: 2)
--parse-depth PARSE_DEPTH
The depth of the TOC list nesting. If minus then no
limit depth. (default: -1)
--use-asterisk Use an asterisk `*` as a list grammer. (default:
False)
--use-plain-enum Not use Markdown grammer, but use simple plain section
name listing. (default: False)
--no-linkformat Not use `- [text](#anochor)`, but use `- text`.
(default: False)
--edit If given then insert TOC to the file from "--input".
(default: False)
--edit-target EDIT_TARGET
A insertion destination label when --edit given. NOT
CASE-SENSITIVE. (default: <!-- TOC)
### Usage

```
$ intoc -h
Usage of intoc:
-debug-print-all
[DEBUG] print all options with name and value.
-edit
If given then insert TOC to the file from '-input'.
-edit-target string
A insertion destination label when '-edit' given. NOT CASE-SENSITIVE. (default "<!-- TOC")
-indent-depth int
The number of spaces per a nest in TOC. (default 2)
-input string
A input filename.
-no-linkformat
Not use '[text](#anochor)', but use 'text'.
-parse-depth int
The depth of the TOC list nesting. If minus then no limit depth. (default -1)
-use-asterisk
Use an asterisk '*' as a list grammer.
-use-plain-enum
Not use Markdown grammer, but use simple plain section name listing.
-version
Show this intoc version.
```


## Samples

### Basic

An option `-i` is required for your input.
`-input` is required option.

```
$ python intoc.py -i README.md
$ intoc -input readme.md
- [intoc](#intoc)
- [Feature](#feature)
- [Install](#install)
- [Requirement](#requirement)
- [CLI](#cli)
- [How to use](#how-to-use)
- [Usage](#usage)
- [Samples](#samples)
- [Basic](#basic)
- [Depth control](#depth-control)
- [Use not hyphen but aasterisk](#use-not-hyphen-but-aasterisk)
- [Direct update](#direct-update)
- [Plain enumeration](#plain-enumeration)
- [No link format but keep list grammer](#no-link-format-but-keep-list-grammer)
- [How to develop](#how-to-develop)
- [Requirement](#requirement)
- [How to run](#how-to-run)
- [How to test](#how-to-test)
- [How to build](#how-to-build)
- [License](#license)
- [Author](#author)
```

### Depth control

`--indent-depth` and `--parse-depth`.
`-indent-depth` and `-parse-depth`.

```
$ python intoc.py -i README.md --indent-depth 4 --parse-depth 2
$ intoc -input readme.md -indent-depth 4 -parse-depth 2
- [intoc](#intoc)
- [Feature](#feature)
- [Install](#install)
- [Requirement](#requirement)
- [CLI](#cli)
- [How to use](#how-to-use)
- [Samples](#samples)
- [How to develop](#how-to-develop)
- [License](#license)
- [Author](#author)
```

### Use not hyphen but aasterisk
### Use not hyphen but asterisk

`--use-asterisk`.
`-use-asterisk`.

```
$ python intoc.py -i README.md --use-asterisk
$ intoc -input readme.md -use-asterisk
* [intoc](#intoc)
* [Feature](#feature)
* [Install](#install)
* [Requirement](#requirement)
* [CLI](#cli)
* [How to use](#how-to-use)
* [Usage](#usage)
* [Samples](#samples)
* [Basic](#basic)
* [Depth control](#depth-control)
* [Use not hyphen but aasterisk](#use-not-hyphen-but-aasterisk)
* [Direct update](#direct-update)
* [Plain enumeration](#plain-enumeration)
* [No link format but keep list grammer](#no-link-format-but-keep-list-grammer)
* [How to develop](#how-to-develop)
* [Requirement](#requirement)
* [How to run](#how-to-run)
* [How to test](#how-to-test)
* [How to build](#how-to-build)
* [License](#license)
* [Author](#author)
```

### Direct update

Write `<!-- toc -->` to your input file and use `--edit`.
Write `<!-- toc -->` to your input file and use `-edit`.

```
$ python intoc.py -i README.md --edit
$ intoc -input readme.md -edit
$ type README.md
$ type readme.md
# intoc
TOC generator for Markdown.
<!-- toc -->
- [intoc](#intoc)
- [Feature](#feature)
- [Install](#install)
- [Requirement](#requirement)
- [CLI](#cli)
- [How to use](#how-to-use)
- [Usage](#usage)
- [Samples](#samples)
- [Basic](#basic)
- [Depth control](#depth-control)
- [Use not hyphen but aasterisk](#use-not-hyphen-but-aasterisk)
- [Use not hyphen but asterisk](#use-not-hyphen-but-asterisk)
- [Direct update](#direct-update)
- [Plain enumeration](#plain-enumeration)
- [No link format but keep list grammer](#no-link-format-but-keep-list-grammer)
- [How to develop](#how-to-develop)
- [Requirement](#requirement)
- [How to run](#how-to-run)
- [How to test](#how-to-test)
- [How to build](#how-to-build)
- [License](#license)
- [Author](#author)
## Feature
...
```

If you want to change edit-string from default `<!-- toc -->` to an another, use `-edit-target` option.

### Plain enumeration

`--use-plain-enum`.
`-use-plain-enum`.

```
$ python intoc.py -i README.md --use-plain-enum
$ intoc -input readme.md -use-plain-enum
intoc
Feature
Install
Requirement
CLI
How to use
Usage
Samples
Basic
Depth control
Use not hyphen but aasterisk
Use not hyphen but asterisk
Direct update
Plain Enumeration
Plain enumeration
No link format but keep list grammer
How to develop
Requirement
How to run
How to test
How to build
License
Author
```

### No link format but keep list grammer

`--no-linkformat`.
`-no-linkformat`.

```
$ python intoc.py -i README.md --no-linkformat
$ intoc -input readme.md -no-linkformat
- intoc
- Feature
- Install
- Requirement
- CLI
- How to use
- Usage
- Samples
- Basic
- Depth control
- Use not hyphen but aasterisk
- Use not hyphen but asterisk
- Direct update
- Plain enumeration
- No link format but keep list grammer.
- No link format but keep list grammer
- How to develop
- Requirement
- How to run
- How to test
- How to build
- License
- Author
```

## How to develop

### Requirement

- Golang
- Developed and Tested on `go version go1.10.3 windows/386` and `go version go1.10.3 windows/amd64`
- github.com/stretchr/testify/assert for unittest

### How to run

See [run.bat](run.bat), but executing `go run` simply.

### How to test

See [test.bat](test.bat), but executing `go test` simply.

### How to build

See [build.bat](build.bat), but executing `go build` simply.

## License

[MIT License](LICENSE)
Expand Down
File renamed without changes.
Loading

0 comments on commit 472bbd0

Please sign in to comment.