Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/11/2012, 09:25
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Agregar Atributos a una Lista de enlaces.

Código Python:
Ver original
  1. import re
  2.  
  3. def urlfy(text):
  4.     url_pattern = re.compile(r'^https?://')
  5.     match = url_pattern.match(text)
  6.     if match:
  7.         return '<a href="%s">%s</a>' % (text, text)
  8.     else:
  9.         return text
  10.  
  11. print urlfy('https://www.google.com')
  12. print urlfy('Some text here')
  13. print urlfy('http://www.forosdelweb.com')
  14. print urlfy('http://gmail.com')

Lo puedes hacer con expresiones regulares, lamentablemente esto no garantiza que no tengas html injection.