I have a string returned from a 3rd party API, that contains fully formed anchor tags (on most occasions). The html appears to be fully formed and correct.
I want to decode this and output into an MVC view as a valid anchor tag, however HTMLDecode does not seem to convert the anchor tag into a link.
I am simply outputting the text as such;
<p>#HttpUtility.HtmlDecode(Model.Description)</p>
but the text comes out with anchor tag included, like this;
This is a test description. Check here - New York Times for more information
Am I expecting to much of HtmlDecode?
Use #Html.Raw()
<p>#Html.Raw(Model.Description)</p>
http://msdn.microsoft.com/en-us/library/gg480740%28v=vs.118%29.aspx
Related
I have a need for the user to select text in another (external) web page, and copy/paste it to a html textarea txaQuote (which has a runat server attribute).
I then capture the value as:
string quote = txaQuote.Value;
This however captures only the "text" - any html tags (if for example the source has any <a> tags or spans <p></p> tags) aren't preserved. is there any way to do so?
string quote = txaQuote.InnerHtml
and
string quote = txaQuote.InnerText
don't work, so I'm guessing the html is actually lost in the copy/paste process itself. Is there a way to preserve it?
So, it seems to me the problem is with the textarea control itself, it's not rich text. By using the menulabs rich text box I can preserve the html.
I recently asked a couple of questions on here related to two subjects
1) Stopping HTML that may be posted by a user in a text field to then render as HTMl on a web page
2) Detect links in a string and where they start and end
I am having problems trying to put the two together.
Over all, I have a text box that a user can type into. They are allowed to type in anything they want.
When posted to the server, I want to seek out all links that are in that text and save them to a database table. Then show on the webpage the text they have typed without any HTML except that I put in myself
So if they type www.google.com, i will turn it to http://www.google.com
I can do that no problem. However if they type something like <p style="margin-left:50px">www.google.com</p> it will find the link, change the link, but the web page will turn the margin bit into actual HTML.
I was recommended to use HTML encoding, however if I do it AFTER I have saved the links into the database, the indices are off (start and length of where the links are in the text).
If I do the HTML encoding BEFORE I save the links, the links may get messed up. If they type in
www.google.com
It will encode the text and the link my regex expression will find is
www.google.com">www.google.com</a>
I either need to improve my regex, or find another way
For reference my regex is
#"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:#=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])"
If I understood this correctly, you need to display any other html tag the user may type in as-is. Try replacing the < and > characters with < and > respectively.
If you do this before you run the regex replace, it should sort out your issue.
I am trying to parse a HTML page (The page isn't known and changes often, however they are always news sites). Basically, I need to pull the news out of a bunch of code downloaded from the site, which i'm trying to do with a regex like this:
Match m = Regex.Match(x.Result, #"<p>(.+?)</p>");
Obvious bad idea - it pulls down anything tagged as a paragraph.
Any better ways to pull a news article or large body of text, separated from the code, from a website?
Well, this may not be exactly what you want (you haven't provided a lot of detail), but you can strip all tags from a page with a pair of simple regex's.
Remove javascript and CSS:
<(script|style).*?</\1>
Remove tags
<.*?>
Credit goes to this existing answer. What you will be left with is the "plain text" from the page.
I have strings of HTML markup along with normal text written between it, what I want to do is to remove all HTML tags except hyperlinks and line breaks so that it will look like normal notepad style text but formatted (i.e with line breaks so it remains readable) and hyperlinks to ensure all external links remain visible for user to click.
I have tried some regex solutions but they completely eliminate all HTML markup which I don't want.
Thanks.
Use Html Agility Pack. it seems be useful for your issue.
i have a description of a product who fill by ckeditor. i show a part of the description on the page. the problem is that they create a problem.
suppose ckeditor created <p>blahblah</p> and i cut the text to the limit code have then logically p tag is not closed. so here is something i can do.
close the tag. are i can get the text from them and append inside the div i create. well how i can do that.
So the issues is that you need to display a excerpt of the full description? Is it feasible, in that case, to just strip HTML and just display a certain amount of characters?
If you need extract text from html or fix the html you can try using Html Agility Pack