0

i'm building a simple site where users can post comments about "things".

What I want to do is in some way "analyze" the comment they post to detect Links (and provide tags) images (maybe display previews), videos, etc.

I'm building the site with django. I think there must be some kind of library to do that server side, and must be some plugin for JQuery.

What do you recommend? Do you know something that can help me with that? Is it better to do it client side or server side?

Thanks a lot!

EDIT:

I'll use an example. Suppose a user post this comment:

"Hello guys, i love this new site: example.com"

That should be translated to:

"Hello guys, i love this new site: <a href='http://example.com'>example.com</a>"

Plase note that i don't want to use a WYSIWYG editor!

santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
  • I think this link does what you are looking for : http://stackoverflow.com/questions/247479/jquery-text-to-link-script [1]: http://stackoverflow.com/questions/247479/jquery-text-to-link-script – tpbowden Apr 23 '12 at 17:03
  • Actually, I'd like something serverside. But i'm not very sure and wanted some thoughts about that. Thanks for the link BTW. – santiagobasulto Apr 23 '12 at 17:05

2 Answers2

1

Depending on how flexible you want to make this, you're might have to write up some regular expressions. If you don't know what they are or how to use them, they allow you to search for patterns in strings and manipulate them. For more information, take a look here:

http://www.regular-expressions.info/tutorial.html

If you decided to do this on the client side, in a similar way to how Stack Overflow does things, you could use something like this:

post = "Hello guys, I love this new site: example.com"
post = post.replace(/([\w0-9-]+\.)+(com|net|org|info)/, '<a href="http://$&/">$&</a>');

Which comes out as

Hello guys, I love this new site: <a href="http://example.com/">example.com</a>

(Note that that won't grab every possible URL, just a few common ones)

LukeGT
  • 2,324
  • 1
  • 21
  • 20
0

Have a look at Django markup module. I use markdown's safe mode becouse of security.

ArturM
  • 683
  • 1
  • 5
  • 15