markdown-it-attr-link-replacer
v1.2.0
Published
markdown-it plugin for replacing links (image & text) in the markdown document.
Downloads
8
Maintainers
Readme
markdown-it-attr-link-replacer
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
andimg
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