[HTML Utils]  html tags not converting formatted text

Forge Component
(6)
Published on 24 Sep by Justin James
6 votes
Published on 24 Sep by Justin James

Hi,

I am getting a html text from db which is having <pre></pre> html tags, while displaying it on web page using HTMLtoText() method, the format of text is lost. Could you please suggest how it can be handled to display the formatted text with the proper line breaks and spaces.

Eg. 

<pre>

Hi

I am using HTMLUtils

to handle HTML tags.

</pre>


Thanks and regards,

Kunal

That is the expected behavior, HTMLToText removes all HTML tags (which remove the pre tags) then when yoiu display it the browser will choose to render it how it chooses because pre's are gone. You can skip using the HTMLToText tag entirely to make it render right and keep your pre tags. If this is user-generated content that you do not trust to not have malicious HTMLk you can use HTMLToText to get rid of all HTML, then add the pre tags back at the beginning and end to the whole thing will be rendered as-is. Make sure to set the "Escape Content" property on the expression to "No" so that does not force it to display "<pre"> and "</pre>" on the screen.

J.Ja

Thanks for your reply. But applying htmltotext and then putting the text inside <pre></pre> still doesnt maintain the format and all the spaces and line breaks are lost.

well i have put a condition on when to appliy HTMLtoText to fix this issue.


Thanks for your kind help.

Kunal