Genshi, AddThis and attributes with multiple colons in namespace

66 views
Skip to first unread message

dbrattli

unread,
Sep 10, 2011, 4:08:55 AM9/10/11
to Genshi
Hi,

I tried to add some AddThis (http://www.addthis.com) code to my
webpage and got into problems with Genshi. When trying to render the
following HTML code:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_google_plusone" g:plusone:size="medium"></
a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/
addthis_widget.js#pubid=ra-4e6b0c632bea7f8f"></script>
<!-- AddThis Button END -->

I get the error:

TemplateSyntaxError: not well-formed (invalid token): line 179, column
52 (/view.html, line 179). The line of problem is the:

<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>

Looks like Genshi does not like attributes such as g:plusone:size. I
don't know if the code is valid xhtml. I tried adding namespaces such
as g, g:plusone or g:plusone:size without any luck. Almost gave up but
then I managed to get things working with a little pyattrs trick that
I want to share it in case others run into the same problem:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_google_plusone"
py:attrs="{'g:plusone:size' : 'medium'}"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/
addthis_widget.js#pubid=ra-4e6b0c632bea7f8f"></script>
<!-- AddThis Button END -->

Simon Cross

unread,
Sep 10, 2011, 4:52:48 AM9/10/11
to gen...@googlegroups.com
On Sat, Sep 10, 2011 at 10:08 AM, dbrattli <dbra...@gmail.com> wrote:
> TemplateSyntaxError: not well-formed (invalid token): line 179, column
> 52 (/view.html, line 179). The line of problem is the:
>
> <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>

I think the raising of TemplateSyntaxError here is correct -- this
does not appear to be valid XML.

http://www.w3.org/TR/xml/#sec-starttags reads:

"""
The Namespaces in XML Recommendation [XML Names] assigns a meaning to
names containing colon characters. Therefore, authors should not use
the colon in XML names except for namespace purposes, but XML
processors must accept the colon as a name character.
"""

and http://www.w3.org/TR/xml-names/#ns-qualnames reads:

"""
[7] QName ::= PrefixedName | UnprefixedName
[8] PrefixedName ::= Prefix ':' LocalPart
[9] UnprefixedName ::= LocalPart
[10] Prefix ::= NCName
[11] LocalPart ::= NCName
"""

and http://www.w3.org/TR/xml-names/#NT-NCName reads:

"""[4] NCName ::= Name - (Char* ':' Char*) /* An XML Name, minus
the ":" */"""

So attribute names may contain only one colon.

> Almost gave up but
> then I managed to get things working with a little pyattrs trick that
> I want to share it in case others run into the same problem:

I'm tempted to say that Genshi should reject attribute names
containing multiple colons but I'm certainly not going to change the
current behaviour any time soon (too much possibility of breaking
users' templates for minimal gain). Another (and more sanctioned way)
of inserting invalid XML is to use the Markup() class.

Schiavo
Simon

Reply all
Reply to author
Forward
0 new messages