This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var simpleFormatRE1 = /\r\n?/g; | |
var simpleFormatRE2 = /\n\n+/g; | |
var simpleFormatRE3 = /([^\n]\n)(?=[^\n])/g; | |
function simpleFormat(str) { | |
var fstr = str; | |
fstr = fstr.replace(simpleFormatRE1, "\n") // \r\n and \r -> \n | |
fstr = fstr.replace(simpleFormatRE2, "</p>\n\n<p>") // 2+ newline -> paragraph | |
fstr = fstr.replace(simpleFormatRE3, "$1<br/>") // 1 newline -> br | |
fstr = "<p>" + fstr + "</p>"; | |
return fstr; |