Created
August 15, 2019 21:54
-
-
Save mikemcbride/5ad12aa072b0b9706453b1208b8466ec to your computer and use it in GitHub Desktop.
Regex to replace markdown links with their rendered HTML counterpart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convert a string of markdown that has anchor tags into it to have the rendered anchor tags | |
const html = `your markdown goes here` | |
const r = /\[(.*)\]\((.*)\)/gmi | |
function linkReplacer(match, p1, p2) { | |
return `<a href="${p2}" target="_blank" rel="nofollow noreferrer">${p1}</a>` | |
} | |
const newHtml = html.replace(r, linkReplacer) | |
console.log(newHtml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment