markdown-it-redirect
v0.1.6
Published
Replace / Redirect external links with Markdown-it Plugin
Downloads
2
Maintainers
Readme
Replace / Redirect external links with Markdown-it Plugin
Markdown-it Plugin repalce external links with redirect link.
If you don't know Node.js
Node.js Tutorial for Beginners in 2020
How To Build a Blog with Nest.js, MongoDB, and Vue.js
Machine Learning In Node.js With TensorFlow.js
Install
npm i markdown-it-redirect --save
Example
var redirect = require('markdown-it-redirect');
var md = require('markdown-it')({ html: true}).use(redirect, {
// default option
redirect: 'https://l.morioh.com/b0a3f595aa?r=',
regex: {
link: /((http|https):\/\/(?!([^/]+\.)?morioh.com)[\w\.\/\-=?#]+)/i,
html: /(<a.*href=)[\"']((http(s)?):\/\/(?!([^/]+\.)?morioh.com)[\w\.\/\-=?#]+)[\"']/gm
}
});
var html = md.render('[https://morioh.com/p/e446a15a1022](https://morioh.com/p/e446a15a1022)\
[https://learnstartup.net/p/rJHeJJdk6l](https://learnstartup.net/p/rJHeJJdk6l)\
<a href="https://morioh.com/p/e446a15a1022">https://morioh.com/p/e446a15a1022</a>\
<a href="https://learnstartup.net/p/rJHeJJdk6l">https://learnstartup.net/p/rJHeJJdk6l</a>');
// result
<p><a href="https://morioh.com/p/e446a15a1022">https://morioh.com/p/e446a15a1022</a>
<a href="https://l.morioh.com/b0a3f595aa?r=https://learnstartup.net/p/rJHeJJdk6l" rel="nofollow" target="_blank">https://learnstartup.net/p/rJHeJJdk6l</a>
<a href="https://morioh.com/p/e446a15a1022">https://morioh.com/p/e446a15a1022</a>
<a href="https://l.morioh.com/b0a3f595aa?r=https://learnstartup.net/p/rJHeJJdk6l" rel="nofollow" target="_blank">https://learnstartup.net/p/rJHeJJdk6l</a></p>