Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Quick Start section #100

Merged
merged 4 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .verb.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Quick Start
Assuming you want to add a TOC to README.md:
1. ```$ npm install -g markdown-toc```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need 1 backtick when the code is inline.

2. Edit README.md and insert the following line where you want the TOC inserted:<br />```<!-- toc -->```
3. ```$ markdown-toc -i README.md```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need 1 backtick when the code is inline.


## CLI

```
Expand Down Expand Up @@ -253,4 +259,4 @@ Type: `Boolean`

Default: `true`

Strip extraneous HTML tags from heading text before slugifying. This is similar to GitHub markdown behavior.
Strip extraneous HTML tags from heading text before slugifying. This is similar to GitHub markdown behavior.
119 changes: 75 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

## Table of Contents

- [Install](#install)
- [CLI](#cli)
- [Highlights](#highlights)
- [Usage](#usage)
- [API](#api)
Expand All @@ -26,13 +24,24 @@
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save markdown-toc
```

Install with [yarn](https://yarnpkg.com):

```sh
$ yarn add markdown-toc
```

## Quick Start
Assuming you want to add a TOC to README.md:
1. ```$ npm install -g markdown-toc```
2. Edit README.md and insert the following line where you want the TOC inserted:<br />```<!-- toc -->```
3. ```$ markdown-toc -i README.md```

## CLI

```
Expand All @@ -41,7 +50,24 @@ Usage: markdown-toc [options] <input>
input: The Markdown file to parse for table of contents,
or "-" to read from stdin.

-i: Edit the <input> file directly, injecting the TOC at <!-- toc -->;
-i: Edit the <input> file directly, injecting the TOC at - [Highlights](#highlights)
- [Usage](#usage)
- [API](#api)
* [toc.plugin](#tocplugin)
* [toc.json](#tocjson)
* [toc.insert](#tocinsert)
* [Utility functions](#utility-functions)
- [Options](#options)
* [options.append](#optionsappend)
* [options.filter](#optionsfilter)
* [options.slugify](#optionsslugify)
* [options.bullets](#optionsbullets)
* [options.maxdepth](#optionsmaxdepth)
* [options.firsth1](#optionsfirsth1)
* [options.stripHeadingTags](#optionsstripheadingtags)
- [About](#about)

_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_;
(Without this flag, the default is to print the TOC to stdout.)

--json: Print the TOC in JSON format
Expand All @@ -65,18 +91,18 @@ Usage: markdown-toc [options] <input>

**Features**

* Can optionally be used as a [remarkable](https://github.com/jonschlinkert/remarkable) plugin
* Returns an object with the rendered TOC (on `content`), as well as a `json` property with the raw TOC object, so you can generate your own TOC using templates or however you want
* Works with [repeated headings](https://gist.github.com/jonschlinkert/ac5d8122bfaaa394f896)
* Uses sane defaults, so no customization is necessary, but you can if you need to.
* [filter](#filter-headings) out headings you don't want
* [Improve](#titleize) the headings you do want
* Use a custom [slugify](#optionsslugify) function to change how links are created
- Can optionally be used as a [remarkable][] plugin
- Returns an object with the rendered TOC (on `content`), as well as a `json` property with the raw TOC object, so you can generate your own TOC using templates or however you want
- Works with [repeated headings](https://gist.github.com/jonschlinkert/ac5d8122bfaaa394f896)
- Uses sane defaults, so no customization is necessary, but you can if you need to.
- [filter](#filter-headings) out headings you don't want
- [Improve](#titleize) the headings you do want
- Use a custom [slugify](#optionsslugify) function to change how links are created

**Safe!**

* Won't mangle markdown in code examples in gfm code blocks that other TOC generators mistake as being actual headings (this happens when markdown headings are show in _examples_, meaning they arent' actually headings that should be in the toc. Also happens with yaml and coffee-script comments, or any comments that use `#`)
* Won't mangle front-matter, or mistake front-matter properties for headings like other TOC generators
- Won't mangle markdown in code examples in gfm code blocks that other TOC generators mistake as being actual headings (this happens when markdown headings are show in _examples_, meaning they arent' actually headings that should be in the toc. Also happens with yaml and coffee-script comments, or any comments that use `#`)
- Won't mangle front-matter, or mistake front-matter properties for headings like other TOC generators

## Usage

Expand All @@ -91,15 +117,15 @@ toc('# One\n\n# Two').content;

To allow customization of the output, an object is returned with the following properties:

* `content` **{String}**: The generated table of contents. Unless you want to customize rendering, this is all you need.
* `highest` **{Number}**: The highest level heading found. This is used to adjust indentation.
* `tokens` **{Array}**: Headings tokens that can be used for custom rendering
- `content` **{String}**: The generated table of contents. Unless you want to customize rendering, this is all you need.
- `highest` **{Number}**: The highest level heading found. This is used to adjust indentation.
- `tokens` **{Array}**: Headings tokens that can be used for custom rendering

## API

### toc.plugin

Use as a [remarkable](https://github.com/jonschlinkert/remarkable) plugin.
Use as a [remarkable][] plugin.

```js
var Remarkable = require('remarkable');
Expand Down Expand Up @@ -128,7 +154,7 @@ Results in:

### toc.json

Object for creating a custom TOC.
Object for creating a custom TOC.

```js
toc('# AAA\n## BBB\n### CCC\nfoo').json;
Expand All @@ -141,7 +167,7 @@ toc('# AAA\n## BBB\n### CCC\nfoo').json;

### toc.insert

Insert a table of contents immediately after an _opening_ `<!-- toc -->` code comment, or replace an existing TOC if both an _opening_ comment and a _closing_ comment (`<!-- tocstop -->`) are found.
Insert a table of contents immediately after an _opening_ `<!-- toc -->` code comment, or replace an existing TOC if both an _opening_ comment and a _closing_ comment (`<!-- tocstop -->`) are found.

_(This strategy works well since code comments in markdown are hidden when viewed as HTML, like when viewing a README on GitHub README for example)._

Expand Down Expand Up @@ -183,11 +209,10 @@ As a convenience to folks who wants to create a custom TOC, markdown-toc's inter
```js
var toc = require('markdown-toc');
```

* `toc.bullets()`: render a bullet list from an array of tokens
* `toc.linkify()`: linking a heading `content` string
* `toc.slugify()`: slugify a heading `content` string
* `toc.strip()`: strip words or characters from a heading `content` string
- `toc.bullets()`: render a bullet list from an array of tokens
- `toc.linkify()`: linking a heading `content` string
- `toc.slugify()`: slugify a heading `content` string
- `toc.strip()`: strip words or characters from a heading `content` string

**Example**

Expand Down Expand Up @@ -216,15 +241,15 @@ Type: `Function`

Default: `undefined`

Params:
Params:

* `str` **{String}** the actual heading string
* `ele` **{Objecct}** object of heading tokens
* `arr` **{Array}** all of the headings objects
- `str` **{String}** the actual heading string
- `ele` **{Objecct}** object of heading tokens
- `arr` **{Array}** all of the headings objects

**Example**

From time to time, we might get junk like this in our TOC.
From time to time, we might get junk like this in our TOC.

```
[.aaa([foo], ...) another bad heading](#-aaa--foo--------another-bad-heading)
Expand Down Expand Up @@ -286,25 +311,23 @@ Default: `true`
Strip extraneous HTML tags from heading text before slugifying. This is similar to GitHub markdown behavior.

## About

### Related projects

* [gfm-code-blocks](https://www.npmjs.com/package/gfm-code-blocks): Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string. | [homepage](https://github.com/jonschlinkert/gfm-code-blocks "Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string.")
* [markdown-link](https://www.npmjs.com/package/markdown-link): Micro util for generating a single markdown link. | [homepage](https://github.com/jonschlinkert/markdown-link "Micro util for generating a single markdown link.")
* [markdown-utils](https://www.npmjs.com/package/markdown-utils): Micro-utils for creating markdown snippets. | [homepage](https://github.com/jonschlinkert/markdown-utils "Micro-utils for creating markdown snippets.")
* [pretty-remarkable](https://www.npmjs.com/package/pretty-remarkable): Plugin for prettifying markdown with Remarkable using custom renderer rules. | [homepage](https://github.com/jonschlinkert/pretty-remarkable "Plugin for prettifying markdown with Remarkable using custom renderer rules.")
* [remarkable](https://www.npmjs.com/package/remarkable): Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in… [more](https://github.com/jonschlinkert/remarkable) | [homepage](https://github.com/jonschlinkert/remarkable "Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in one.")
- [gfm-code-blocks](https://www.npmjs.com/package/gfm-code-blocks): Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string. | [homepage](https://github.com/jonschlinkert/gfm-code-blocks "Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string.")
- [markdown-link](https://www.npmjs.com/package/markdown-link): Micro util for generating a single markdown link. | [homepage](https://github.com/jonschlinkert/markdown-link "Micro util for generating a single markdown link.")
- [markdown-utils](https://www.npmjs.com/package/markdown-utils): Micro-utils for creating markdown snippets. | [homepage](https://github.com/jonschlinkert/markdown-utils "Micro-utils for creating markdown snippets.")
- [pretty-remarkable](https://www.npmjs.com/package/pretty-remarkable): Plugin for prettifying markdown with Remarkable using custom renderer rules. | [homepage](https://github.com/jonschlinkert/pretty-remarkable "Plugin for prettifying markdown with Remarkable using custom renderer rules.")
- [remarkable](https://www.npmjs.com/package/remarkable): Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in… [more](https://github.com/jonschlinkert/remarkable) | [homepage](https://github.com/jonschlinkert/remarkable "Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in one.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Contributors

| **Commits** | **Contributor** |
| --- | --- |
| 196 | [jonschlinkert](https://github.com/jonschlinkert) |
| 5 | [doowb](https://github.com/doowb) |
| 4 | [stefanwalther](https://github.com/stefanwalther) |
| 3 | [sapegin](https://github.com/sapegin) |
| 3 | [Marsup](https://github.com/Marsup) |
| 2 | [dvcrn](https://github.com/dvcrn) |
| 2 | [maxogden](https://github.com/maxogden) |
Expand All @@ -324,8 +347,9 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea
| 1 | [sethvincent](https://github.com/sethvincent) |
| 1 | [lu22do](https://github.com/lu22do) |

### Building docs
### Release history

### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:
Expand All @@ -343,17 +367,24 @@ $ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 19, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 24, 2017._

[gfm-code-blocks]: https://github.com/jonschlinkert/gfm-code-blocks
[markdown-link]: https://github.com/jonschlinkert/markdown-link
[markdown-utils]: https://github.com/jonschlinkert/markdown-utils
[pretty-remarkable]: https://github.com/jonschlinkert/pretty-remarkable
[remarkable]: https://github.com/jonschlinkert/remarkable
[verb-readme-generator]: https://github.com/verbose/verb-readme-generator
[verb]: https://github.com/verbose/verb