Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How can I configure genshi?

11 views
Skip to first unread message

Crusty

unread,
Aug 25, 2009, 11:06:56 AM8/25/09
to TurboGears
Hello everyone,

I am having serious trouble with genshi removing ending tags of empty
html tags.
I want to configure it like so :
http://genshi.edgewall.org/wiki/Documentation/0.5.x/plugin.html#configuration-options
but I simply cannot find the spot where genshi is imported to TG and
options are being passed.

How can I configure it to serialize to XHTML instead of XML?

Thanks,

Tom

Roland

unread,
Sep 3, 2009, 4:58:54 AM9/3/09
to TurboGears
Hi,

I'm having the same problem - did you find any solution?

Roland

On 25 Aug., 17:06, Crusty <crust...@gmail.com> wrote:
> Hello everyone,
>
> I am having serious trouble with genshi removing ending tags of empty
> html tags.
> I want to configure it like so :http://genshi.edgewall.org/wiki/Documentation/0.5.x/plugin.html#confi...

Simon King

unread,
Sep 3, 2009, 5:54:16 AM9/3/09
to TurboGears
Assuming you are using TG2, you are running across this issue:

http://trac.turbogears.org/ticket/2287

In my project I've used something similar to the solution presented in
that ticket. My config/environment.py function looks like this:


# -*- coding: utf-8 -*-
"""WSGI environment setup for wicc3."""
import pylons

from wicc3.config.app_cfg import base_config

__all__ = ['load_environment']

#Use base_config to setup the environment loader function
_load_environment = base_config.make_load_environment()

# Make Genshi render HTML rather than XHTML. Unfortunately TG makes
# this very awkward.
def load_environment(*args, **kwargs):
_load_environment(*args, **kwargs)

# This is the signature of the pylons.templating.render_genshi
# function. I'm going to ignore most of the parameters
def render_genshi(template_name, extra_vars=None, cache_key=None,
cache_type=None, cache_expire=None,
method='xhtml'):
globs = extra_vars or {}
globs.update(pylons.templating.pylons_globals())
template = globs['app_globals'].genshi_loader.load
(template_name)
return (template.generate(**globs).render(method='html',
doctype='html',
encoding=None))

base_config.render_functions.genshi = render_genshi


I've had to copy the pylons.templating.render_genshi function because
the original doesn't have any way of passing the 'doctype' parameter.
I'm also ignoring any of the caching features because I don't actually
use them. If you need them, you'll probably want to copy the pylons
version more closely.

It's a shame that this isn't easier to do. I was under the impression
that (at least for "web sites" rather than "web services"), HTML is
preferred over XHTML. In fact, I think the default for TG2 is to serve
XHTML with a content type of text/html, which seems wrong.

Hope that helps,

Simon

Christoph Zwerschke

unread,
Sep 3, 2009, 8:56:37 AM9/3/09
to turbo...@googlegroups.com
Simon King schrieb:

> It's a shame that this isn't easier to do. I was under the impression
> that (at least for "web sites" rather than "web services"), HTML is
> preferred over XHTML. In fact, I think the default for TG2 is to serve
> XHTML with a content type of text/html, which seems wrong.

No, it's not wrong (at least for XHTML 1.0); it's a concession to MSIE's
badness - I think even the latest MSIE 8 doesn't support real XHTML.

http://www.w3.org/MarkUp/2004/xhtml-faq#texthtml
http://blog.deconcept.com/2004/11/03/why-its-ok-to-send-xhtml-as-text-html/

One possible solution that has been discussed for TG1 already is to use
content negotiation, making an exception for MSIE. But this solution has
several drawbacks, too.

Anyway, TG2 should be improved to make switching between XHTML and HTML
much easier (as easy as it was in TG1), and I think we should also start
supporting HTML5.

-- Christoph

Simon King

unread,
Sep 3, 2009, 12:08:34 PM9/3/09
to TurboGears
On Sep 3, 1:56 pm, Christoph Zwerschke <c...@online.de> wrote:
> Simon King schrieb:
>
> > It's a shame that this isn't easier to do. I was under the impression
> > that (at least for "web sites" rather than "web services"), HTML is
> > preferred over XHTML. In fact, I think the default for TG2 is to serve
> > XHTML with a content type of text/html, which seems wrong.
>
> No, it's not wrong (at least for XHTML 1.0); it's a concession to MSIE's
> badness - I think even the latest MSIE 8 doesn't support real XHTML.
>
> http://www.w3.org/MarkUp/2004/xhtml-faq#texthtml
> http://blog.deconcept.com/2004/11/03/why-its-ok-to-send-xhtml-as-text-html/

Oh OK. I had a problem a few days ago where an empty textarea was
being output as <textarea /> rather than <textarea></textarea>.
Firefox was then taking the rest of the page source and displaying it
inside the textarea.

Here's an example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XHTML Test</title>
</head>
<body>
<form action="">
<p>
<textarea rows="7" cols="50" />
</p>
</form>
</body>
</html>


In Firefox (3.5.2 on Windows, in case it makes any difference), I see
a textarea containing the closing p, form, body and html tags.

I guess this is because I violated point C.3. in the guidelines you
referenced. In my case I was using the ToscaWidgets textarea, which
generated the minimised version.

Thanks for the links - I won't worry so much about the XHTML in the
future!

Cheers,

Simon

Crusty

unread,
Sep 7, 2009, 6:24:06 AM9/7/09
to turbo...@googlegroups.com
Yea, I found a bug in Toscawidgets, opened a ticket there with a fix and hacked in my suggested changes locally in my TW until it gets included.
They had a regression error, this problem was fixed in a previous version and returned again in the current one.
Reply all
Reply to author
Forward
0 new messages