Skip to content

Instantly share code, notes, and snippets.

@mikemcbride
Created August 15, 2019 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemcbride/5ad12aa072b0b9706453b1208b8466ec to your computer and use it in GitHub Desktop.
Save mikemcbride/5ad12aa072b0b9706453b1208b8466ec to your computer and use it in GitHub Desktop.
Regex to replace markdown links with their rendered HTML counterpart
// 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