Socket
Book a DemoInstallSign in
Socket

markdown-it-attr-link-replacer

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

markdown-it-attr-link-replacer

markdown-it plugin for replacing links (image & text) in the markdown document.

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

TypeScript

This is a fork of Martin Heidegger's markdown-it-replace-link plugin.

However, I needed it for Ditto website with some more customizations that are probably too heavy for a lot of users of the original library.

What are the differences?

  • Original library only handled links for a and img tags
  • Original will ignore other raw html attributes that may be links.
  • This plugin however allows additional specifications

markdown-it plugin for replacing links (image & text) in the markdown document.

Usage

Installation

npm install markdown-it-attr-link-replacer -S

Enable plugin

var md = require('markdown-it')({
    html: true    
}).use(require('markdown-it-attr-link-replacer'), {
    attributes: ['src', 'href']
    replaceLink: function (link, env) {
        return link + "?c=" + Date.now();
    }
}); // <-- this use(package_name) is required

Example

[Hello](test)

and use this

var md = require('markdown-it')({
    html: true
}).use(require('markdown-it-attr-link-replacer'), {
    replaceLink: function (link, env) {
        return "http://me.com/" + link;
    }
});

This will result in the link prefixed with the http://me.com/ like:

<p><a href="http://me.com/test">Hello</a></p>

Both images and html links will be processed by default

Testing

To run the tests use:

npm run test

License

MIT

Keywords

markdown

FAQs

Package last updated on 19 Feb 2021

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