Ticket #2287 (closed enhancement: fixed)
[PATCH] No simple way to make TurboGears 2 produce HTML
|Reported by:||chrisz||Owned by:|
Description (last modified by chrisz) (diff)
In TG 1.0, switching between HTML and XHTML output was the matter of only one config setting, but in TG 2.0 this has become very difficult. By default TG 2.0 produces XHTML (while TG 1.0 produced HTML by default) and there is no clean and simple way to use HTML in TG 2.0.
Note that I'm not against using XHTML as the default, but there are many good reasons to produce HTML instead of XHTML, so people should at least be given the choice.
There are two problems:
- Changing the output method of the default render function (using Genshi) is not as straightforward as it should be (as discussed here).
- Even if you change the default Genshi renderer, the ressource injection of ToscaWidgets will still use XHTML for CSS links, because it uses the string.Template rendering engine with a hardcoded XHTML template (as discussed here).
My current solution is to add the following code to config/environment.py:
# Make Genshi render HTML (instead of XHTML) by default: _load_environment = load_environment def load_environment(*args): _load_environment(*args) render_genshi = base_config.render_functions.genshi def render_genshi_html(*args, **kwargs): return render_genshi(method='html', *args, **kwargs) base_config.render_functions.genshi = render_genshi_html # Monkey-patch ToscaWidget so that it creates a valid HMTL link tag # instead of a XHTML tag when injecting resources: from tw.api import CSSLink CSSLink.template = CSSLink.template.replace('/>', '>')
This solves the problem, but it is really ugly and complicated. Something so basic should have a much simpler solution. I think this is an annoying step backward in TG2 compared with TG1.
- Keywords patch added
- Summary changed from No simple way to make TurboGears 2 produce HTML to [PATCH] No simple way to make TurboGears 2 produce HTML