Skip to content

zkochan/markdownscript

Repository files navigation

markdownscript

Creates markdown Abstract Syntax Tree

npm version Build Status Coverage Status

Installation

npm i -S markdownscript

Usage

'use strict'
var m = require('markdownscript')
var heading = m.heading
var paragraph = m.paragraph

var ast = heading({ depth: 1 }, [
  paragraph(['Hello world!']),
])
console.log(JSON.stringify(ast, null, 2))
//> {
//    "type": "heading",
//    "children": [
//      {
//        "type": "paragraph",
//        "children": [
//          {
//            "type": "text",
//            "value": "Hello world!"
//          }
//        ]
//      }
//    ],
//    "depth": 1
//  }

API

m(type, [attributes], [children]) - create a node

console.log(m('link', { url: 'http://google.com' }, ['Google']))
//> { type: 'link',
//    children: [ { type: 'text', value: 'Google' } ],
//    url: 'http://google.com' }

m.[type]([attributes], [children]) - create a node

var code = m.code
console.log(code({ lang: 'js' }, ['void 0']))
//> { type: 'code',
//    children: [ { type: 'text', value: 'void 0' } ],
//    lang: 'js' }

m.h[depth]([attributes], [children]) - create a heading node of the specified depth

var h3 = m.h3
console.log(h3([paragraph(['Foo bar'])]))
//> { type: 'heading',
//    children: [ { type: 'paragraph', children: [Object] } ],
//    depth: 3 }

License

MIT © Zoltan Kochan