1.0.2 • Published 5 years ago

markdown-it-json v1.0.2

Weekly downloads
117
License
MIT
Repository
github
Last release
5 years ago

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'