833
Views
6
Comments
[HTML Utils]  html tags not converting formatted text
Question
icon-png
Web icon
Forge asset by Rodrigo Castelo

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

2019-11-12 17-31-26
Justin James
 
MVP

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

UserImage.jpg
Kunal Priyadarshi

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

UserImage.jpg
May Zin Linn

Hi Kunal Priyadarshi

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

Thanks and apologize.

UserImage.jpg
Kunal Priyadarshi

Hi May Zin Linn,


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


Thanks,

Kunal

2020-10-19 05-14-26
Huyen IT

Hi Kunal and May Zin Linn,

Maybe use EncodeHtml() function will help you.

Regards,

UserImage.jpg
May Zin Linn

Thanks everyon for reply.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.