Auto-recognize links?

J

Josh Pigford

In PHP I've got a few functions that will turn data into links based on
if it recognizes "http://", "www." etc etc.

How can I do this with Ruby?

For instance, in a forums setting if a user posted a link to something
like http://example.com

It'd basically turn it into a clickable link:
<a
href="http://example.com">http://example.com</a>
 
L

lrlebron

I think everything you'd need to do to validate and produce links should
be in the core URI class:http://www.ruby-doc.org/core/classes/URI.html

Interesting, did not know that. Seems bad though:
URI.extract("Visithttp://google.com/.")  # => ["http://google.com/."]

You could borrow code from Rails' auto_link() which handles that kind
of stuff better:http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html...



- Show quoted text -

Have you looked at hpricot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top