https://github.com/gajus/markdown-contents
Generate table of contents for a markdown document.
https://github.com/gajus/markdown-contents
javascript markdown table-of-contents toc
Last synced: about 1 year ago
JSON representation
Generate table of contents for a markdown document.
- Host: GitHub
- URL: https://github.com/gajus/markdown-contents
- Owner: gajus
- License: other
- Created: 2014-11-17T11:26:49.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-08-30T15:02:00.000Z (almost 8 years ago)
- Last Synced: 2025-03-29T01:34:23.657Z (about 1 year ago)
- Topics: javascript, markdown, table-of-contents, toc
- Language: JavaScript
- Size: 16.6 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Markdown Contents
[](https://travis-ci.org/gajus/markdown-contents)
[](https://coveralls.io/github/gajus/markdown-contents)
[](https://www.npmjs.org/package/markdown-contents)
[](https://github.com/gajus/canonical)
[](https://twitter.com/kuizinas)
Generate table of contents for a markdown document.
The underlying implementation is rendering markdown file into HTML and then use [Contents](https://github.com/gajus/contents).
to generate the table of contents.
## Usage
```js
import MarkdownContents from 'markdown-contents';
const markdown = '';
const markdownContents = MarkdownContents(markdown);
/**
* Generate flat index of the headings.
*
* @return {Array}
*/
markdownContents.articles();
/**
* Generates hierarchical index of the headings from a flat index.
*
* @return {Array}
*/
markdownContents.tree();
/**
* Generate markdown for the table of contents.
*
* @return {string}
*/
markdownContents.markdown();
/**
* Generate markdown contents for an array of contents object definition.
*
* @param {Array} tree [{id: '', name: '', descendants: []}]
* @return {string} markdown
*/
MarkdownContents.treeToMarkdown();
/**
* Makes hierarchical index of the articles from a flat index.
*
* @param {Array} articles Generated using Contents.articles.
* @param {boolean} makeUniqueIDs
* @param {Array} uniqueIDpool
* @return {Array}
*/
MarkdownContents.tree();
```