I've created a sample blog application using webpy. I used some code here(Replace URL with a link using regex in python) to replace the URL but when I render the page it won't show the hyperlink but just a plain text
In my template:
<p>
<i>$datestr(post.posted_on) by $user</i><br/><br/>
$urlify.formatstring(post.content)
<p>
urlify.py
def formatstring(self, value):
pat1 = re.compile(r"(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
pat2 = re.compile(r"(^|[\n ])(((www|ftp)\.[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
value = pat1.sub(r'\1<a href="\2" target="_blank">\3</a>', value)
value = pat2.sub(r'\1<a href="http://\2" target="_blank">\3</a>', value)
return value
Example text:
This url will make your life sh!t so don't click this one.<a href="http://www.someurl.com">some url</a>.
Expected after the render of the page shoud be:
This url will make your life sh!t so don't click this one.some url.
But the actual is:
This url will make your life sh!t so don't click this one.<a href="http://www.someurl.com">some url</a>.
Url was not change to hyperlink.
EDIT: In my template: Instead of $content, it should be $:content to treat the url as hyperlink.