Removing HTML url tags in iOS - ios

I am writing an iOS app that downloads some data from a server that's not under my control. I am not using custom data detectors. The strings in the returned JSON still contain their HTML url tags, and I want to remove them because I want to display the strings in a UITextView, and these kind of strings
<strong>Instagram</strong> / <strong>Behance</strong>
<strong>Live Now</strong>
What I really want is this:
Instagram Behance
Live Now
What is the best way to go about this?
Should I strip the url tags from the text using regex?
Would I lose the link "descriptions" (in the above example, "Instagram" and "Behance") when I do that?
Would this be way easier using a UIWebView?
If this would be too hard/impossible, it'd be okay to only have the urls, without their descriptions.
Thank you!

Should I strip the url tags from the text using regex?
No. HTML is too complex to be properly parsed using a RegEx. You'll need an XML parser.
Would I lose the link "descriptions" (in the above example, "Instagram" and "Behance") when I do that?
You wouldn't have to using an XML parser. Using a RegEx, you might, especially if you can't control exactly what's returned.
Would this be way easier using a UIWebView?
Yep. That's what I would do, unless you have a good reason not to.

Related

React Native, how to turn a comment into a URL?

I was wondering how I can turn a comment (such as stackoverflow.com) to a post as a URL so that when clicked, it will go straight to the website?
Thanks for your help in advance
You can pre-process your text and look for things that might be a URL. Look at this answer here: Regex to match URL.
You'd want to take your text, split it by white-space, then for each white-space-separated word, check if it's a URL. If it's a URL, then output a proper <a> tag surrounding it. If not, just output the word.

Replace URL in Text Body with an Image Tag for that URL

As the title suggests I would like to find a way to replace URLs within a body text (for a blog) with image tags for those URLs. I suspect I will need to do some form of regex. Has anyone done something like this before?
EDIT:
To describe the use case a bit more, I have a blog-esque site I am building. I would like blog writers to be able to 'drop' urls into text posts (separated by newlines), and have rails intelligently parse the string and replace any urls with images (perhaps in a helper method).
The sanest approach is to use something like Markdown (or exactly like it) and ensure that your posts are marked up correctly. This seems to be the most up-to-date gem for Markdown, https://github.com/vmg/redcarpet.
Alternatively, if you want to do this by yourself, it would still be prudent to mark up a link in some way. For example, {image src=link_to_the_image_here}.
This will make finding images within the body of text easier.

Is it possible to have tags with spaces?

I am using the ng-tags-input library, however, when my responses come back with spaces they are replaced with hyphens in the tag. Is there a way to prevent this? At a minimum can I get the original value?
Looks like I need replaceSpacesWithDashes on tags input trying now.

How to replace Mandrill's *| |* symbols?

Is there any chance to replace the mandrill's *| |* symbols?
The CMS i'm using (MODX) has its own symbols to enclose the tags, eg: [[+ ]]
The case is that I also have "read on web" link, where the page on the web needs to generate dynamic content as well.
I have googled and searched on http://help.mandrill.com but still no luck.
Any hint will be appreciated.
You wouldn't be able to use different symbols in your emails - those are how Mandrill's system recognizes merge tags and to replace them in the HTML and/or text of your email. You'd need to convert any placeholders you have or want for the email to that format, so you can pass the data to Mandrill as expected. If it's going to mirror what you're putting on the web, then you probably just want to have something that transforms strings, for example, to convert your CMS tags to Mandrill tags specifically for the emails.
#kaitlin-mandrill,
Exactly,
I just figured it out.
I need to replace it right before it is sent.
More or less, this is the code.
Hopefully it's useful for anyone else.

Any problems with using a period in URLs to delimiter data?

I have some easy to read URLs for finding data that belongs to a collection of record IDs that are using a comma as a delimiter.
Example:
http://www.example.com/find:1%2C2%2C3%2C4%2C5
I want to know if I change the delimiter from a comma to a period. Since periods are not a special character in a URL. That means it won't have to be encoded.
Example:
http://www.example.com/find:1.2.3.4.5
Are there any browsers (Firefox, Chrome, IE, etc) that will have a problem with that URL?
There are some related questions here on SO, but none that specific say it's a good or bad practice.
To me, that looks like a resource with an odd query string format.
If I understand correctly this would be equal to something like:
http://www.example.com/find?id=1&id=2&id=3&id=4&id=5
Since your filter is acting like a multi-select (IDs instead of search fields), that would be my guess at a standard equivalent.
Browsers should not have any issues with it, as long as the application's route mechanism handles it properly. And as long as you are not building that query-like thing with an HTML form (in which case you would need JS or some rewrites, ew!).
May I ask why not use a more standard URL and querystring? Perhaps something that includes element class (/reports/search?name=...), just to know what is being queried by find. Just curious, I knows sometimes standards don't apply.

Resources