Winston Gutkowski wrote:
Leo Li-Fan Chen wrote:I have a requirement to write a function that accepts a String that contains html content (from webpage or email), transform every URL found into hyperlink, and return that String.
Right, just to make your requirements clear:
You want to search a piece of HTML text and convert all strings that are outside <a> tags to something like
<a href="{whatever}">{whatever}</a>
is that right?
Thanks for the prompt response.
Sorry I didn't make it very clear.
My task is to search a piece of HTML text and convert these URLs (www.,
http://,
https://,
rtps://) that is
1. within <body></body>
2. outside any html tags
3. not already enclosed by <a></a>, in other words, not hyperlinked
to
<a href="{whatever}">{whatever}</a>.
The purpose is to make the URLS (www.,
http://,
https://,
rtps://) clickable when the HTML text is ultimately passed to WebView.
I'd prefer not to use any library though, need to minimize our app's footprint.
I believe point number 3 is the most difficult task.
e.g.
If I detect a URL (e.g. www.yahoo.com), how far before that URL should I scan for a possible <a> tag?
Anyone had experience writing this kind of algorithm?