Socket
Book a DemoInstallSign in
Socket

@hongminhee/markdown-it-regexp

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hongminhee/markdown-it-regexp

plugin that makes regexp replacement simple

latest
Source
npmnpm
Version
0.6.0
Version published
Maintainers
1
Created
Source

Make simple markdown-it plugins easier.

Usage:

import md from 'markdown-it';
import createPlugin from '@hongminhee/markdown-it-regexp';

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

  // this function will be called when something matches
  function(match, utils, env) {
    if (!env.userExists(match[1])) return '@' + match[1];
    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", { userExists: (u) => u === "user" })

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

Fair warning:

  • it could be slower than you expect
  • it is a draft, breaking changes might happen

Keywords

markdown-it-plugin

FAQs

Package last updated on 24 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts