Skip to content

Instantly share code, notes, and snippets.

@MattMS MattMS/paragraphs.js
Last active Jun 25, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.