Automagically generate table of contents from the files in your repository
Install
$ npm install --global files2md
Usage
Example
You will most likely want to use the CLI.
Given the following readme.md
:
This are all the markdown files in this directory: <!-- START files2md --><!-- END files2md -->
Execute:
$ files2md readme.md
And you will obtain:
These are all the markdown files in this directory: <!-- START files2md --><!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN files2md TO UPDATE --> - [fixtures](./fixtures) - [1](./fixtures/1) - [2](./fixtures/1/2) - [fixtures/1/2/c.md](./fixtures/1/2/c.md) - [fixtures/1/b.md](./fixtures/1/b.md) - [fixtures/a.md](./fixtures/a.md)- [readme.md](./readme.md) <!-- END files2md -->
You can see an example at: aymericbeaumet/til.
API
fromFile(filepath: String, options: Object, done: (err: Error, newBuffer: Buffer) => void): void
Modify a file in place with the updated table of contents.
fromBuffer(buffer: Buffer, options: Object, done: (err: Error, newBuffer: Buffer) => void): void
Return a new buffer with the updated table of contents.
CLI
$ files2md --help
Automagically generate file trees in your markdown files
Usage
$ files2md [options] [file]...
Options
--cwd Change the current working directory (default: `process.cwd()`)
--dot Whether the dot files should be matched (default: `false`)
--dry-run Do not write the results to the disk (default: `false`)
--extensions Pipe separated list of extensions to filter, empty string to disable (default: `.md|.markdown`)
--extract-headers Extract the first header matching the given level as the title, `0` to disable (default: `0`)
--follow Whether symlinks should be followed (default: `false`)
--footer Append a files2md footer in the generated table of contents (default: `false`)
--ignore Pipe separated list of glob patterns to ignore (default: `.git|bower_components|node_modules`)
--indent Can be either `space` or `tabs` (default: inferred, fallback to space)
--linebreak Can be either `crlf`, `cr` or `lf` (default: inferred, fallback to lf)
--lint Abort if the contents is outdated
--max-depth The max-depth relatively to the CWD, inclusive (default: `Infinity`)
--min-depth The min-depth relatively to the CWD, inclusive (default: `0`)
Changelog
-
1.0.1
- Fix issue with relative path
-
1.0.0
- Bump stable
License
To the extent possible under law, Aymeric Beaumet has waived all copyright and related or neighboring rights to this work.