Skip to content

Instantly share code, notes, and snippets.

@hrstt
Created June 25, 2011 13:36
Show Gist options
  • Save hrstt/1046494 to your computer and use it in GitHub Desktop.
Save hrstt/1046494 to your computer and use it in GitHub Desktop.
exchange line break to <br /> tag
# line break exchange to <br />
def newline_to_br(text)
text = html_escape(text.to_s)
text.gsub!(/\r\n?/, "\n")
text.gsub!(/\n\n+/, "\n")
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment