Skip to content

Instantly share code, notes, and snippets.

@qw3r
Forked from kares/simpleFormat.js
Last active December 11, 2015 12:09
simpleFormat = (text) ->
re1 = /\r\n?/g
re2 = /\n\n+/g
re3 = /([^\n]\n)(?=[^\n])/g
fstr = text
fstr = fstr.replace(re1, "\n") # \r\n and \r -> \n
fstr = fstr.replace(re2, "</p>\n\n<p>") # 2+ newline -> paragraph
fstr = fstr.replace(re3, "$1<br/>") # 1 newline -> br
"<p>#{fstr}</p>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment