Skip to content

Instantly share code, notes, and snippets.

@MattMS
Last active June 25, 2019 09:43
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 MattMS/e35f27c878620dce9acbda32b033fdf1 to your computer and use it in GitHub Desktop.
Save MattMS/e35f27c878620dce9acbda32b033fdf1 to your computer and use it in GitHub Desktop.
Text to HTML conversion.
var split_p_and_br = s => s.trim().split(/\n\n/).map(s => s.replace(/\n/g, '<br />'))
var split_p = s => s.trim().split(/\n\n/).map(s => s.replace(/\n/g, ' '))
var join_p = p => p.join('</p><p>')
var fin = t => `<p>${t}</p>`
var a = `
hello
multi
line
string
oh
yeah
`
var with_breaks = fin(join_p(split_p_and_br(a)))
var without_breaks = fin(join_p(split_p(a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment