A(...) is an object not a string. You can convert it to string with A (...).xml()
When an object is displayed {{=A(...)}} it is not scaped (but the strings within are). When a string is dispalyed {{=A(...).xml()}} it is escaped, unless marked up accordingly {{=XML(A(...).xml())}}. Hope this helps On Mar 11, 10:39 am, Michael Wales <evicera...@gmail.com> wrote: > I have the following function in a module - this function performs a > Regex search and attempts to replace matches with a link (generated > with the A() helper). The regex and replacement is working correctly - > if I change the value of the replace variable to something other than > the A() helper, it works as I expect. Something with the A() helper is > causing the return to not have the link at all (just the innerHTML > from the link). > > The module's function: > > def link_wiki_tags(content, db, request): > import re > from gluon.html import A, URL > pattern = re.compile('\[\[([\w\s:]+)\]\]') > for match in pattern.findall(content): > slug = slugify(match) > if db(db.games.slug == slug).select(): > replace = A(match, _href = URL(r = request, c = > 'games', f = > 'view', args = slug), _title = match) > elif db(db.people.slug == slug).select(): > replace = A(match, _href = URL(r = request, c = > 'people', f = > 'view', args = slug), _title = match) > elif db(db.companies.slug == slug).select(): > replace = A(match, _href = URL(r = request, c = > 'companies', f = > 'view', args = slug), _title = match) > else: > replace = match > content = re.sub('\[\[' + match + '\]\]', replace, content) > return content > > How this module is called from the view: > > {{= link_wiki_tags(person.content, db, request) }} > > Sample Input: > [[John Carmack]] is a developer for [[Quake Live]]. > > Expected Output: > <a href="/shooterhero/people/view/john-carmack" title="John > Carmack">John Carmack</a> is a developer for <a href="/shooterhero/ > games/view/quake-live" title="Quake Live">Quake Live</a>. > > Actual Output: > John Carmack is a developer for Quake Live. > > As I mentioned, if I change the replace lines within the conditional > checking for a database result, it will change the output as expected. > I have change this replace variable to a string, as well as the URL() > helper, both of which worked fine. In other words, I have narrowed > this issue down to the A() helper. > > Any help in getting the module's function to return the intended > output would be appreciated. Is there some sort of filtering placed on > module function returns (something that would strip out tags). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---