Thursday, April 28, 2011

Transform words into links with regex

Hello. I am using Django 1.3 on Windows XP.
I read a tutorial and the code below transforms the words like MyLink
into a html link.
But the output that I achieved is the HTML markups of the link, not
the link itself.
How to solve that?
Thank you.

wikilink = re.compile("\\b([A-Z][a-z]+[A-Z][a-z]+)\\b")

register = template.Library()

@register.filter
def wikify(value):
return wikilink.sub(r"<a href='/wikicamp/\1/'>\1</a>",value)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment