Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/markdown-tree
Convert a markdown document into a JSON tree structure.
https://github.com/hughsk/markdown-tree
Last synced: 12 days ago
JSON representation
Convert a markdown document into a JSON tree structure.
- Host: GitHub
- URL: https://github.com/hughsk/markdown-tree
- Owner: hughsk
- License: mit
- Created: 2013-12-16T13:11:17.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-08-20T08:27:49.000Z (about 7 years ago)
- Last Synced: 2024-10-17T16:38:06.844Z (22 days ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 14
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# markdown-tree [![deprecated](http://hughsk.github.io/stability-badges/dist/deprecated.svg)](http://github.com/hughsk/stability-badges) #
**Deprecated: use something like [remark](https://www.npmjs.com/package/remark) instead?**
Convert a markdown document into a JSON tree structure, using
[marked](http://github.com/chjj/marked) under the hood.Should be helpful for cases where you might want to analyse the structure of
the document, e.g. auto-generating sites from GitHub wikis.## Usage ##
[![markdown-tree](https://nodei.co/npm/markdown-tree.png?mini=true)](https://nodei.co/npm/markdown-tree)
### `require('markdown-tree')(src[, options])` ###
`src` should be the Markdown document you want to parse, as a string.
`options` is passed on to
[`marked.lexer`](https://github.com/chjj/marked/blob/abce5d0d6dbad0f7a19f009510a71708f539c4d6/README.md#access-to-lexer-and-parser).Each Node in the resulting tree represents either the document root or a
heading, and should be formatted similarly to this:``` javascript
{
type: "Heading" // or, "Document"
, text: "The Heading Contents"
, children: []
, depth: 2 // e.g. "### hello" would be 3
, tokens: [
{
type: 'paragraph'
, text: 'The tokens from each paragraph...'
},
{
type: 'paragraph'
, text: '...before the next heading go here!'
},
{
type: 'paragraph'
, text: 'This data comes directly from marked.'
}
]
}
```There's also a `parent` property, but that's hidden to make logging the tree a
little cleaner.Note also that the `tokens` array is actually retrieved from the marked module
untouched, so you can run it through `marked.parse` with little trouble to
compile that section to standalone HTML.## License ##
MIT. See [LICENSE.md](http://github.com/hughsk/markdown-tree/blob/master/LICENSE.md) for details.