Re: Silva 1.o / Unicode problem

Guido Wesdorp <[email protected]>
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <[email protected]>
Bas Leeflang wrote:

> I worked around the problem initially by replacing the '&' by the word 
> 'and'. I just converted it back. So have a look at:
>
So I noticed. ;)

> When I inspect the source it seems that Silva is working fine in 
> converting '&' to '&amp;' The problem actually occurs in the 
> navigation tree structure on the left side of the page. This is a 
> constructed in a python script that includes the title.
>    title = item.get_title()
>    if item.get_short_title() == item.get_title():
>        item_id = item.getId()
>    else:
>        item_id = item.get_short_title()
>          url    = item.absolute_url()
>
> This is the relevant section from the script where I use 
> 'get_title()'. Furthermore the 'item_id' (displayed in the tree 
> structure) is either the object ID or its SHORT-title.

I see the ampersands in the source and I guess I understand the issue: 
your sidebar code probably generates HTML, so you have to use 
'structure' in the PageTemplate to present it. Usually omitting 
'structure' makes the PT machinery convert the four basic problem chars 
(&, <, > and ") to their XML entities, but in this case you'll have to 
do it yourself. I think there's probably some function to do that 
somewhere in Python's standard library, although since you're in a 
Python script you probably want to just do it yourself:

def xml_entitize(input):
    input = input.replace('&', '&amp;')
    input = input.replace('"', '&quot;')
    input = input.replace('<', '&lt;')
    input = input.replace('>', '&gt;')
    return input

Make sure this gets called not only for textual elements inside your 
HTML but also for attributes, right now what breaks is actually the 
'title' attribute on some of your <a> elements.

Cheers,

Guido
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.