markdown-it-json

1.0.2 • Public • Published

markdown-it-json Build Status npm version

add json syntax to markdown-it

Usage

const md = require('markdown-it')
const mdj = require('markdown-it-json')
 
function validate (obj) {
  if (obj['type'] === 'user' && obj.hasOwnProperty('id')) {
    return true
  }
  return false
}
 
function transform (state, obj) {
  let token = state.push('user_open', 'a', 1)
  token.attrs = [['href', `/user/${obj.id}`]]
  token = state.push('test', '', 0)
  token.content = `@${obj.id}`
  state.push('user_close', 'a', -1)
}
 
md.use(mdj(validate, transform)).render('hello, !{"type": "user", "id": "test"}')
// '<p>hello, <a href="/user/test">@test</a></p>\n'

Readme

Keywords

Package Sidebar

Install

npm i markdown-it-json

Weekly Downloads

28

Version

1.0.2

License

MIT

Unpacked Size

4.65 kB

Total Files

4

Last publish

Collaborators

  • n-inja