How to preserve line breaks from an Umbraco.TextArea?
c
V13.1.1 I've tried : @Model.Content.OverlayText?.ReplaceLineEndings() but it's still all in one line. This is what the input looks like (below). I've tried soft line endings and hard, both the same. I'd rather not change the control over to an RTE if I can get away with it. Any advice appreciated. Thanks. https://cdn.discordapp.com/attachments/1212812728817680384/1212812729077862441/image.png?ex=65f332df&is=65e0bddf&hm=f6492e7fcb29c69d372317d4d96c58e523aac399e28422178b7b2be68cf3128a&
s
Could you try wrapping the text in
Copy code
<pre>Event and ideas 
& inspiration</pre>
e.g.
Copy code
<h1><pre>@Model.Content.OverlayText</pre></h1>
o/w @Model.Content.OverlayText?.ReplaceLineEndings("") Though you might have to style the br to match a spacing
a
Wouldnt it work with
Html.Raw()
?
m
https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Web.Common/Mvc/HtmlStringUtilities.cs#L20C1-L28C6
Copy code
csharp
    public IHtmlContent ReplaceLineBreaks(string text)
    {
        var value = WebUtility.HtmlEncode(text)
            .Replace("\r\n", "<br />")
            .Replace("\r", "<br />")
            .Replace("\n", "<br />");

        return new HtmlString(value);
    }
m
Yeah, I was going to ask if he was replacing line breaks with HTML breaks. As far as I know the original code will not.
218 Views