Rendering newlines in escaped html

北城以北 提交于 2019-12-05 17:32:27

What you're doing is more or less fine, except for you should put \n character (newline), not the escape sequence in your html (and what Prinzhorn says also makes perfect sense, so I'll go upvote him).

Escape the HTML, and then replace \n with <br>.

In case you want to use \n, I fix your fiddle for you http://jsfiddle.net/hr3bg/

Your theory's sound, but \n is a not an HTML-recognised way of inserting a new line. It either comes in explicitly (as I've inserted in a new .linebreaks element) as a literal return in the markup, or, if you're using some intermediary scripting language that does recognise \n (like JS), do that (as I've done to your first .linebreaks with the jQuery code I inserted.

See my tweak to your example: http://jsfiddle.net/barney/7L932/2/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!