Matthew Russell wrote: > I'm trying desperately to get into some html that I'm > transforming, but must be doing something terribly wrong. > > An example: > > >>> import kid > >>> > kid.Template(source='<div> </div>').serialize(encoding='utf-8',output='html') > '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " > http://www.w3.org/TR/html4/loose.dtd">\n<DIV>\xc2\xa0</DIV>' > > Ok, so I didn't expect to see the initial \xc2 portion, ...
This output is correct. You asked kid to produce utf-8 encoding, where is indeed represented by the byte sequence '\xc2\xa0'. > and that, in > fact, gives me an A with a hat over it that shows up in my rendered > html, which I definitely do not want. That happens if you display the above utf-8 sequence as latin-1 (iso-8859-1) where '\xc2' is the A with a hat. Where do you see that A with a hat? In the browser? This would indicate that the output is missing the line <meta content="text/html; charset=utf-8" http-equiv="content-type"> telling the brwoser to use utf-8. However, that line should be automatically inserted by TurboGears. You don't need to do anything. Maybe you have another meta tag in your own template with a wrong encoding of iso-8859-1? You should remove that or add a py:replace="''" attribute so that it does not go to the output. > Using ascii or even iso-8859-1 as the encoding produces   > and \xa0 respectively. That would be also correct. You must decide which encoding you want to deliver to the browser and tell the browser properly using the meta tag above. Note: I think there is a bug in TurboGears so that kid.encoding is ignored and utf-8 is always used instead. > But my master template needs to have this line in it: > <meta content="text/html; charset=utf-8" http-equiv="content-type" > py:replace="''"/> This line is only there so that the master template is displayed correctly when viewed directly in the browser. It has no effect otherwise since the py:replace removes it completely when the tempalte is processed. I think TurboGears uses kid's feature to insert the meta tag with the kid.encoding automatically. > To sum it all up, all I want to do is have an in my kid > template and get back that same in my rendered html. > I must be making this way too hard? You can force kid to produce   using the ascii encoding (or with the new format option of Kid 0.9.4). But if your output is utf-8, then kid will always produce the above UTF-8 sequence no matter how it had been coded in the input file. -- Christoph ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ kid-template-discuss mailing list kid-template-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kid-template-discuss