markdownscript

1.3.0 • Public • Published

markdownscript

Creates markdown Abstract Syntax Tree

npm version Build Status Coverage Status

Installation

npm i -S markdownscript

Usage

'use strict'
const m = require('markdownscript')
const heading = m.heading
const paragraph = m.paragraph
 
const 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

const 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

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

License

MIT © Zoltan Kochan


Dependencies dependency status

Dev Dependencies devDependency status

Package Sidebar

Install

npm i markdownscript

Weekly Downloads

35

Version

1.3.0

License

MIT

Last publish

Collaborators

  • zkochan