'Keep line breaks in Spring + Thymeleaf 3.0.12+

I know there's already a question on converting line breaks to <br> tags in Thymeleaf, but the "#strings.replace" solution from there, relies on getting the line.separator system property to make it platform neutral. Since Thymeleaf 3.0.12 this is now broken (see this GitHub issue) when used with th:utext. Is there a recommended replacement for this, other than just using "\n"? For reference, the current line (which we use all over our codebase) looks something like this:

<div th:utext="*{#strings.replace(#strings.escapeXml(fieldName),T(java.lang.System).getProperty('line.separator'),'&lt;br&gt;')}">


Solution 1:[1]

I made a Thymeleaf dialect that makes it easy to keep the line breaks, if the css white-space property isn't an option. It also bring support for BBCode if you want it. You can either import it as a dependency (it's very light) or just use it as inspiration to make your own. Check it out here : https://github.com/oxayotl/meikik-project

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jean Alexandre