0.4.0 • Published 9 years ago

markdown-it-regexp v0.4.0

Weekly downloads
1,944
License
MIT
Repository
github
Last release
9 years ago

Make simple markdown-it plugins easier.

Usage:

var md     = require('markdown-it')
var Plugin = require('markdown-it-regexp')

var plugin = Plugin(
  // regexp to match
  /@(\w+)/,

  // this function will be called when something matches
  function(match, utils) {
    var url = 'http://example.org/u/' + match[1]

    return '<a href="' + utils.escape(url) + '">'
         + utils.escape(match[1])
         + '</a>'
  }
)

md()
  .use(plugin)
  .render("hello @user")

// prints out:
// <p>hello <a href="http://example.org/u/user">user</a></p>

Fair warning:

  1. it could be slower than you expect
  2. it is a draft, breaking changes might happen