Convert html into string - html

How can I convert Html into string. For example I have html: <p>This is Test</p><p></p><p>Test</p>. I want to convert html into this:
This is a test
Test
I don't want the <p> tag to be printed on the screen but I want them to behave as actual paragraphs.
I have tried HtmlDecode but that doesn't work either. I am getting the string from mvc telerik editor.
Any help would be appreciated. Thanks :)
Update:
I did partially solve my problem by using HTML.Raw in my view which converted the html into string. I was wondering if there is any equivalent to Html.Raw that I can use on the server side too i.e. in my controller??

You need to use a parser. HTMLAgility pack is a tool that is constantly recommended here.

Related

How to output string as HTML when using html encode in view

I am wondering how to get html markup language to be displayed in a web page when using Html Encode which is being used to replace some string like in the example below.
#(Html.Raw(Html.Encode(Model.Test).Replace("\n", "<br />")))
Of course, just using
#(Html.Raw(Model.Name)) e.g.<b>test/b> = test
Will achieve what I am asking for but then I will lose the replace code.
I could do this replacing functionality in the controller which may be the best method. However, I am intrigued to whether this can be done just in the view.
Thanks
You can use
#Html.Raw("<b>test</b>")
for this.
Html.Encode(Model.Test)
actually changes the string <b> to
<b>
so in fact I think this should be enough
#(Html.Raw(Model.Test.Replace("\n", "<br />")))

My backbone marionette model contains a field with escaped html in it. How do I render that field's contents as HTML and not text?

Classic problem. Want to see html rendered but I'm seeing text in the browser. Whether I tell handlebars js to decode it or not in template ( three curly braces vs two - {{{myHtmlData}}} vs {{myHtmlData}} ) doesn't get me there. Something about the JSON being returned via the model.fetch() has this html data wrapped up in such a way that it is resistant to the notion of displaying as HTML. It's always considered a string whether encoded or decoded so it always displays as text.
Is this just something backbone isn't meant to do?
The technologies involved here are:
backbone.marionette
handlebars.js
.NET Web API
Your data is being escaped automatically. It's a good thing, but since you're sure the data is a safe HTML. Use {{{}}} as in this other question Insert html in a handlebar template without escaping .

How to parse these html string in objective c

I'm getting an string from json response. In the string there are HTML tags,
<ul class='video-list-container'><li><a href='?page_id=6602&playid=6'>مكتبة الفيديو</a></li><li><a href='?page_id=6602&playid=10'>الزكاة</a></li><li><a href='?page_id=6602&playid=11'>الصلاة</a></li></ul>\n
Now all I want to do is to do is, get the arabic string with the href link and display in the UITableviewcell. And when selected row should move to next viewcontroller.
How can do this. I'm struck in parsing the string.
Can anyone help me.
Thanks In advance.
I think this tutorials might help you ,
AFNetworking is smart enough to load and process structured data over the network, as well as plain old HTTP requests. In particular, it supports JSON, XML and Property Lists (plists).
you can follow the tutorial given below for more clarification
http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial
You should try using the library "hpple" which is a wrapper around "libxml2". You can find hpple here.
Hpple allows you to parse HTML in Obj-C using XPath expressions. With XPath selectors you will be able to select what content you want to extract out of your HTML. You can read and learn more about XPath here.
Hope it helps. :)
Cheers!

How would I tell a browser to render a string, not display it

I have this extension method I created and it returns a string of all the categories in my database as hyperlinks. Great!
#Html.MyMenu()
The problem is that the links are being displayed as text and not rendered as hyperlinks.
When viewing the source code I see:
<div id="menucontainer">
<a href="/Anuncio/Electronics">Electronics</a><a href="/Anuncio/Clothes">Clothes</a><a href="/Anuncio/Domestic">Domestic</a><a href="/Anuncio/Garden">Garden</a>
</div>
I think I may be wrong but I remember that in MVC2 (using the default view engine) you had:
<%: this is rendered, right? %>
Or am I mistaken? Anyways, I'm using MVC3 and the Razor engine. Thanks a lot for your help guys. I'm really enjoying learning as much as I can about this.
Razor escapes HTML by default.
To avoid that, please do something like this:
Writing/outputting HTML strings unescaped
In RC2 a new method called #HTml.Raw should to this.
Or you can change MyMenu to return HtmlString or MvcString rather than just string.
well your extension method should be returning an MvcHtmlString in order to properly display on your page using the <%: %> If it returns a string, all angle brackets and other html special characters will be html-encoded.
RC2 supports #Html.Raw() to output raw HTML
From Scott Guthrie's RC2 anouncement
With RC2 we are adding a Html.Raw() helper method that you can use to explicitly indicate that you do not want to HTML encode your output, and instead want to render the content “as-is”

Perl AJAX stripping html characters out of string?

I have a Perl program that is reading html tags from a text file. (im pretty sure this is working because when i run the perl program on the command line it prints out the HTML like it should be.)
I then pass that "html" to the web page as the return to an ajax request. I then use innerHTML to stick that string into a div.
Heres the problem:
all the text information is getting to where it needs to be. but the "<" ">" and "/" are getting stripped.
any one know the answer to this?
The question is a bit unclear to me without some code and data examples, but if it is what it vaguely sounds like, you may need to HTML-encode your text (e.g. using HTML::Entities).
I'm kind of surprized that's an issue with inserting into innerHTML, but without specific example, that's the first thing which comes to mind
There could be a mod on the server that is removing special characters. Are you running Apache? (I doubt this is what's happening).
If something is being stripped on the client-side, it is most likely in the response handler portion of the AJAX call. Show your code where you stick the string in the div.