[HTML Utils]  html tags not converting formatted text

Forge Component
Published on 2019-09-24 by Justin James
8 votes
Published on 2019-09-24 by Justin James


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.




I am using HTMLUtils

to handle HTML tags.


Thanks and regards,


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.


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.


Hi Kunal Priyadarshi

Now I am facing the same issuse.You can solved this problem.If you can, please guide me.

Thanks and apologize.

Hi May Zin Linn,

I have done as below. Applied condition and then used HTMLToText along with <div></div> tags.



Hi Kunal and May Zin Linn,

Maybe use EncodeHtml() function will help you.


Thanks everyon for reply.