Created
June 25, 2011 13:36
-
-
Save hrstt/1046494 to your computer and use it in GitHub Desktop.
exchange line break to <br /> tag
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
# 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