Changing doctypes via the Buffet interface

3 views
Skip to first unread message

Christoph Zwerschke

unread,
Sep 23, 2008, 6:32:49 AM9/23/08
to gen...@googlegroups.com
In TurboGears, we're on the verge of releasing version 1.1 where Kid has
been replaced with Genshi as the default templating engine.

TurboGears 1.x is using the Buffet API, and we're facing one serious
problem here when making the switch to Genshi, namely that it's
impossible to produce different doctype on different pages, e.g. when
you have part of your application that uses HTML, and a different part
that uses XHTML, or some pages using framesets or quirks mode.

The problem is that the doctype can only be passed to the buffet plugin
as an option at startup time, but at render time you can't overwrite
options any more, you can only overwrite the "format" (which corresponds
to Genshi's "method" parameter). If you set up the plugin with "html" as
the default method, and a html doctype, though you can later render
templates with an "xhtml" method, they still get the wrong html doctype.

We did not have this problem with Kid, since you can pass a doctype by
specifying e.g. "html-frameset", or "xhtml-strict" as the Buffet format
parameter; the format name in Kid always indirectly determines the
doctype as well. In Genshi however, you can only pass "html" or "xhtml"
here, and the doctype is chosen separately beforehand.

Also, in Kid you can pass serializer instances in the Buffet format
parameter, which have a suiting doctype already set, but in Genshi, you
can pass only serializer *classes* which are later initialized with the
default doctype that the plugin has been initialized with.

Here are some ideas how this problem could be solved in Genshi:

1) Let all serializer classes have their own default doctypes which will
be used when initialized with no doctype or an incompatible doctype.

2) Allow not only the names 'html', 'xhtml', 'xml', 'text' as rendering
methods, but also all names of doctypes such as 'html-transitional',
'html-frameset' etc. to specify method plus doctype in one parameter.

3) Add a parameter "options" to the Buffet API render method allowing to
overwrite any default parameters (particularly, the doctype parameter)
at rendering time.

Let me know how you think about this or if there are any better ideas.

-- Christoph

Jeroen Ruigrok van der Werven

unread,
Sep 24, 2008, 4:30:26 AM9/24/08
to gen...@googlegroups.com
-On [20080923 12:33], Christoph Zwerschke (ci...@online.de) wrote:
>2) Allow not only the names 'html', 'xhtml', 'xml', 'text' as rendering
>methods, but also all names of doctypes such as 'html-transitional',
>'html-frameset' etc. to specify method plus doctype in one parameter.

Perhaps I am missing or misunderstanding something, but I am using this:

self.stream.render('xhtml', doctype=DocType.XHTML_STRICT)

with Geshi which allows me to precisely specify which doctype of XHTML I
want.

--
Jeroen Ruigrok van der Werven <asmodai(-at-)in-nomine.org> / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
He who knows, does not speak. He who speaks, does not know...

Christoph Zwerschke

unread,
Sep 24, 2008, 5:08:25 AM9/24/08
to gen...@googlegroups.com
Jeroen Ruigrok van der Werven schrieb:

> Perhaps I am missing or misunderstanding something, but I am using this:
>
> self.stream.render('xhtml', doctype=DocType.XHTML_STRICT)
>
> with Geshi which allows me to precisely specify which doctype of XHTML I
> want.

That's right, this is no problem if you're using Genshi directly. But
I'm talking about using Genshi via the Genshi Buffet interface (as used
by e.g. TurboGears 1.x). There is currently no way of passing in the
doctype parameter via Buffet at render time.

-- Christoph

Matt Good

unread,
Oct 4, 2008, 8:40:37 PM10/4/08
to Genshi
On Sep 23, 3:32 am, Christoph Zwerschke <c...@online.de> wrote:
> In TurboGears, we're on the verge of releasing version 1.1 where Kid has
> been replaced with Genshi as the default templating engine.
>
> TurboGears 1.x is using the Buffet API, and we're facing one serious
> problem here when making the switch to Genshi, namely that it's
> impossible to produce different doctype on different pages, e.g. when
> you have part of your application that uses HTML, and a different part
> that uses XHTML, or some pages using framesets or quirks mode.
>
> The problem is that the doctype can only be passed to the buffet plugin
> as an option at startup time, but at render time you can't overwrite
> options any more, you can only overwrite the "format" (which corresponds
> to Genshi's "method" parameter). If you set up the plugin with "html" as
> the default method, and a html doctype, though you can later render
> templates with an "xhtml" method, they still get the wrong html doctype.
>
> We did not have this problem with Kid, since you can pass a doctype by
> specifying e.g. "html-frameset", or "xhtml-strict" as the Buffet format
> parameter; the format name in Kid always indirectly determines the
> doctype as well. In Genshi however, you can only pass "html" or "xhtml"
> here, and the doctype is chosen separately beforehand.

Provide a patch to MarkupTemplateEnginePlugin._get_render_options to
map extended format names like those to the expected doctype and I'll
make sure it gets in.

http://genshi.edgewall.org/browser/trunk/genshi/template/plugin.py#L142

-- Matt
Reply all
Reply to author
Forward
0 new messages