Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

markdownscript

zkochan158MIT1.3.0

Creates markdown Abstract Syntax Tree

markdown, ast, markdownscript, script

readme

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