Coder Social home page Coder Social logo

nasa8x / markdown-it-redirect Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 411 KB

Replace / Redirect external links with Markdown-it Plugin

Home Page: https://morioh.com/topic/node-js

License: MIT License

HTML 78.53% JavaScript 21.47%
mardown markdown-it-plugin markdown-it

markdown-it-redirect's Introduction

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>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.