Datatable containing HTML string - html

In a Winforms application, I have a datatable in which one of its columns contain HTML string. I want to render the whole datatable contents on the form or in HTML where the inner HTML contents should also get rendered.
I am using C# to do this. The reason I want the HTML is that the datatable contains a report and the inner HTML contains links to images.
Can someone please help?

I cannot tell what language you're using but you'll need to HTML encode the HTML string from the datatable. Most languages will contain a method for this that takes a string as a parameter.

Why do you want to put HTML in a windows application? Do you have an HTML Editor?
With regards to web, the normal procedure would be to store the data, in a normal table, and when you load you place the HTML in a <div>. If you put runat="server" in the div, you can set the innerhtml attribute from the server side.

Related

Developer used HTML form tag as XML root tag. Can't escape

I'm pulling data from a url string thats converting to XML. I have it placed on my webpage and most of it is displaying as expected. But the developer in their wisdom used an HTML tag as an XML tag <option>.
I can't share the whole thing but it's basically this url string displaying the xml below:
http://private.com/webservice6.asp?c=00000000&p=Int0000000&stock_symbols=AAPL,GE&classes=BOD,,OPTION&from=5/1/2021&to=6/1/2021&v=2&o=EVENTS
Its outputting like this:
<option>
<event_id>4ICO1KYD</event_id>
<company_id>1084</company_id>
</option>
So the browser thinks its an HTML webform select option. It's displaying the data but as one option block and I can't target the sub tags.
I have no control of the xml markup.
Is there any way of escaping or wrapping the whole thing to tell the browser to treat it as xml vs html?

How to show rendered template as raw source code block?

I want to provide a rendered HTML block that shows an email signature - what it looks like with user data from the context - and also displays the populated HTML code as raw src to be copied for pasting into customers email signature. What would be the best (dry) way to do this?
I have tried render_to_string as a variable in the context but the HTML is rendered.
I solved this by following this answer:
How do I perform HTML decoding/encoding using Python/Django?
The rendered django template HTML needs to be decoded before it can be shown in the pre tag otherwise it will be marked up by the browser.

Getting HTML as plain text

I am taking HTML as input from a page using Tinymce(Rich Text editor), and saving input to SQL server , While retrieving the data form database and passing it to view ,all html tags and content are showing as plain text.
I am using asp.net core MVC.
This is where you would want to use Html.Raw()
Html.Raw() with render the HTML string you pass to it as markup on the page.

How to save html content in mongodb via SpringBoot form

I am working on a SpringBoot based MVC application which uses mongoDB to store the data. I am using thymeleaf as the template engine. In one of the scenarios, the user needs to fill a form which is then displayed on some view.
The problem I am facing is that the user can use html tags to format the data while writing in the textArea of the form (code snippets, tabular format etc). But when I am displaying that text, the html is not being parsed and is displayed as is.
For Ex: <b>String</b> should be displayed as String but is being displayed as <b>String</b> only. When I check the source code of the page, the html tags are displayed as encoded i.e. < is showing as &lt ; etc and hence the parsing is not happening.
Can someone please help
You can output unescaped text with th:utext. From the official turorial
If we want Thymeleaf to respect our XHTML tags and not escape them, we will have to use a different attribute: th:utext (for “unescaped text”):
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
The tutorial assumes that home.welcome is a string with html-tags:
home.welcome=Welcome to our <b>fantastic</b> grocery store!.
It goes without saying that this needs very careful validation so that only safe (whatever safe is for the particular use case) HTML is stored into the database (and no possibly malicious code like <script/> tags).

How to stop tinymce converting html tags from database

I can create my content fine using tinymce , it also uploads correctly to the database. here is an example of what stores in the database.
<p>Content goes in here</p>
When I choose to edit this it converts my p tags in the database to <p>
and then wraps the content in another set of p tags.
in source code of tinymce it looks like this
<p><p>this is a test message</p></p>
How do I stop this ?
as I just want it to render exactly as it is in the database.
I want to still store correct html tags in my database but I do not want tinymce to keep stripping/converting them.
Thanks in advance for your help.
Adam
Are you looking for somethink like that
tinymce.init({
...
entity_encoding : "raw"
});
tinymce encode the content before passing it to the server and hence the content is stored as: <p>This is text;/p> but the html tage are still passed like <p><p>This is text;/p></p>
While saving it to the database encode the values so that the html/xml tags are stored encoded. Like; Server.HtmlEncode(_propertyShopAdvertDetails.MarketingInformation);
and similarly while retrieving and displaying in the tinymce control the vaue needs to be decoded;
Server.HtmlDecode(_propertyShopAdvertDetails.MarketingInformation);
while retrieving the content and displaying it in the control, it decodes it and displays it correctly. Since it is displaying the content fine so I believe you have the right class on the control and used the correct mode for the plugin.
Now if you want to display the content in an HTML page and not inside tinymce control the you need to decode it. Something like: #Html.Raw(System.Web.HttpUtility.HtmlDecode(Model.PropertyFullDescription))