Thymeleaf: replace newline characters with <br>
I have a field (
<textarea name="desc" />) that may contain newlines and I want to replace them with their HTML counterpart:
<br />. How can I do this? I'm using Thymeleaf 2.1.4.RELEASE.
As stated by dominik,
\n for newline does not work. However, you can use
Or with escaping to prevent code injection:
General Usage - replacete new line into <br /> - Thymeleaf, Hello, I want to let users in comment field (textarea) enter new line. You'll have to process the user input first, replacing \n with <br/> where exception is being thrown as the Thymeleaf underlying XML parser does not allow to put < and > inside expressions; The solution I found for the first problem is to set newline character in a controller and pass it to view. To address the second problem you need to use < instead of < and > instead of >.
Thymeleaf: replace newline characters with <br>, Thymeleaf: replace newline characters with <br>. Question. I have a field ( <textarea name="desc" /> ) that may contain newlines and I want to replace them with When render the above HTML on Web Browser(Chrome, Firefox, Safari, IE ), first new line character is removed from User Interface. On an Web Browser,"<CRLF>input value" is render same with "input value" (without <CRLF>).
java - Thymeleaf: replace newline characters with <br>, i have field ( <textarea name="desc" /> ) may contain newlines , want replace them html counterpart: <br /> . how can this? i'm using thymeleaf 2.1.4.release. Well, there a number of ways to specify a new line in different areas in python. Python New Line Character. For most of the purposes, the newline character can be used to specify a new line. You can put this character within Python Strings. An example of using character in a string to display output to the console screen is given below.
- Am I missing something if I understand this as replacing text characters in some model attribute (not rendered HTML)? If so, then why don't you just do it in the controller using plain Java?
- See also stackoverflow.com/q/37765352/883073
- @HalleKnast: This kind of job is view-specific. What would happen if you added another view implementation that renders *.doc files? You would end up with model attribute exposing string with "<br />"s that are invalid in .doc format - that's why it's not a job for controllers.
- Just to help people. is the ASCII of the LineFeed character. It worked like a charm :)
- really? this does not work for me and looks like so complicated to do something trivial