Navigation Menu

Skip to content

hughsk/markdown-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markdown-tree deprecated

Deprecated: use something like remark instead?

Convert a markdown document into a JSON tree structure, using 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

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.

Each Node in the resulting tree represents either the document root or a heading, and should be formatted similarly to this:

{
    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 for details.

About

Convert a markdown document into a JSON tree structure.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published