Discussion:
Genshi, AddThis and attributes with multiple colons in namespace
dbrattli
2011-09-10 08:08:55 UTC
Permalink
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 -->
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
Simon Cross
2011-09-10 08:52:48 UTC
Permalink
Post by dbrattli
TemplateSyntaxError: not well-formed (invalid token): line 179, column
<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.
Post by dbrattli
Almost gave up but
then I managed to get things working with a little pyattrs trick that
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
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
Loading...