Skip to content

Instantly share code, notes, and snippets.

@s-melnikov
Created January 31, 2019 13:09
Show Gist options
  • Save s-melnikov/5ce238eda67e7d9b0e44f70366597203 to your computer and use it in GitHub Desktop.
Save s-melnikov/5ce238eda67e7d9b0e44f70366597203 to your computer and use it in GitHub Desktop.
MD
text
.replace(/\n{3,}/, '\n\n')
.replace(/\n+$/, '\n\n')
.replace(/(#+)(.+?)\n/gm, (p, h, m) => `\n<h${h.length}>${m.trim()}</h${h.length}>\n`)
.replace(/^([^\n<][\S\s]+?)\n\n/gm, (p, m) => `<p>${m.trim()}</p>\n\n`)
.replace(/\*\*([\S ]+?)\*\*|__([\S ]+?)__/g, (p, m1, m2) => `<b>${m1||m2}</b>`)
.replace(/\*([\S ]+?)\*|_([\S ]+?)_/g, (p, m1, m2) => `<em>${m1||m2}</em>`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment