You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bloodhound.apache.org by Matevz Bradac <ma...@gmail.com> on 2012/11/25 20:07:13 UTC

Genshi XHTML + HTML 5

Hi,

I've started working on #217 - "Make Bloodhound's layout responsive",
based on Joe's html mockup of the ticket page (#240).
I noticed that the HTML output contains a mix of HTML 5 along with
XHTML 1.0, even though the doctype is XHTML 1.0 strict.
As a consequence (some of) the pages don't validate (e.g.
http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240),
and this may be the cause of browsers (mis)behaving and rendering
things differently.

Is there any general consensus which doctype BH should use? Since
we're using Bootstrap I suppose it would be better to go along
with HTML 5, but I'm not sure how this affects the templating system.
There's a Genshi extension which could be used
(http://code.google.com/p/genshihtml5),
does anyone have any experience with that?

Cheers,
matevz

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
On Tue, Nov 27, 2012 at 5:17 PM, Olemis Lang <ol...@gmail.com> wrote:
> On 11/26/12, Joe Dreimann <jo...@wandisco.com> wrote:
>> On 26 Nov 2012, at 07:03, Peter Koželj <pe...@digiverse.si> wrote:
>>> On 25 November 2012 20:07, Matevz Bradac <ma...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I've started working on #217 - "Make Bloodhound's layout responsive",
>>>> based on Joe's html mockup of the ticket page (#240).
>>>> I noticed that the HTML output contains a mix of HTML 5 along with
>>>> XHTML 1.0, even though the doctype is XHTML 1.0 strict.
>>>> As a consequence (some of) the pages don't validate (e.g.
>>>>
>>>> http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240
>>>> ),
>>>> and this may be the cause of browsers (mis)behaving and rendering
>>>> things differently.
>>>>
>>>> Is there any general consensus which doctype BH should use?
>
> At least I didn't pay attention to this ... and afaicr I saw nothing
> like that in mockup either
>
>>>> Since
>>>> we're using Bootstrap I suppose it would be better to go along
>>>> with HTML 5, but I'm not sure how this affects the templating system.
>
> Should be OK , afaicr . Genshi is about XML
>
>>>> There's a Genshi extension which could be used
>>>> (http://code.google.com/p/genshihtml5),
>>>> does anyone have any experience with that?
>>>>
>
> What's the benefit for using this ?
Basically the extension provides a new serializer which outputs valid
HTML5, the author explains it in detail at
http://genshi.edgewall.org/ticket/108. IMO it's not needed for BH, any
non-HTML5-conformant output can easily be
detected using validation, and if there are any such issues, they'll
most likely be minor and trivial to fix. Hopefully =)

<snip>

>
> --
> Regards,
>
> Olemis.
>
> Blog ES: http://simelo-es.blogspot.com/
> Blog EN: http://simelo-en.blogspot.com/
>
> Featured article:

--
matevz

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
On 11/26/12, Joe Dreimann <jo...@wandisco.com> wrote:
> On 26 Nov 2012, at 07:03, Peter Koželj <pe...@digiverse.si> wrote:
>> On 25 November 2012 20:07, Matevz Bradac <ma...@gmail.com> wrote:
>>> Hi,
>>>
>>> I've started working on #217 - "Make Bloodhound's layout responsive",
>>> based on Joe's html mockup of the ticket page (#240).
>>> I noticed that the HTML output contains a mix of HTML 5 along with
>>> XHTML 1.0, even though the doctype is XHTML 1.0 strict.
>>> As a consequence (some of) the pages don't validate (e.g.
>>>
>>> http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240
>>> ),
>>> and this may be the cause of browsers (mis)behaving and rendering
>>> things differently.
>>>
>>> Is there any general consensus which doctype BH should use?

At least I didn't pay attention to this ... and afaicr I saw nothing
like that in mockup either

>>> Since
>>> we're using Bootstrap I suppose it would be better to go along
>>> with HTML 5, but I'm not sure how this affects the templating system.

Should be OK , afaicr . Genshi is about XML

>>> There's a Genshi extension which could be used
>>> (http://code.google.com/p/genshihtml5),
>>> does anyone have any experience with that?
>>>

What's the benefit for using this ?

>>>
>> The other thread "Inline editing of objects" (for the Ticket page)
>> suggest
>> fallback mechanism for javascript disabled browsers.
>> Although this is not directly linked I would rather "advertise" BH as
>> HTML5
>> UI experience than a no-javascript capable one.
>>
>> Is anybody aware of any browser that is actually incapable of displaying
>> HTML5 page?
>>
>> Peter
>>
>
> To my knowledge all relevant browsers (including IE6 etc) will display HTML
> 5 pages (using quirks mode), more information here:
> http://stackoverflow.com/questions/3911235/html-5-doctype-and-ie-6
>
> In my opinion this is not an issue, we should be fine to use HTML 5.
>

AFAICS , HTML5 should be ok . It should be rendered in quirks mode by
major browsers .

I'm not sure what'd happen with small navigators like NetSurf but it
claims to just support HTML 4.

{{{
#!sh

$ apt-cache show netsurf
Package: netsurf
Priority: extra
Section: universe/web
Installed-Size: 1248
[...]
Version: 1.2-1build1
[...]
Description: Small portable web browser with CSS and Unicode support
 NetSurf is a multi-platform lightweight web browser. Its aim is to provide
 comprehensive rendering of HTML 4 with CSS 2 in a small resource footprint
 while remaining fast.
[...]

}}}

Once again , it is mandatory to design for disabled JS ... and that's
beyond Netsurf ;)


-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
Thanks. I wanted to avoid monkeypatching render_template(), as it's
not a small/trivial function.
There may be better candidates for this though, such as the Stream.serialize().
Which brings up another question - if we do override trac's functions,
should we keep a list of such
changes somewhere, so that when we introduce a new trac version into
BH things get synced properly?

--
matevz

On Thu, Nov 29, 2012 at 10:53 PM, Branko Čibej <br...@wandisco.com> wrote:
> On 29.11.2012 22:02, Matevz Bradac wrote:
>> Would it be possible to do this in the post processing phase, i.e.
>> IRequestFilter's post_process_request()?
>> If not, is there any way of overriding trac's behaviour without
>> modifying trac itself?
>
> Sure is.
>
> def better_render_template(self, etc...)
>   pass
>
> import chrome
> chrome.Chrome.render_template = better_render_template
>
> This change will persist for the duration of the Python interpreter,
> even across subsequent "import chrome" statements. It's best to do this
> very early during BH intialization.
>
> N.B.: I haven't actually looked at what the names of the modules
> actually are, but you get the idea.
>
> -- Brane
>
> --
> Branko Čibej
> Director of Subversion | WANdisco | www.wandisco.com
>

Re: Genshi XHTML + HTML 5

Posted by Branko Čibej <br...@wandisco.com>.
On 29.11.2012 22:02, Matevz Bradac wrote:
> Would it be possible to do this in the post processing phase, i.e.
> IRequestFilter's post_process_request()?
> If not, is there any way of overriding trac's behaviour without
> modifying trac itself?

Sure is.

def better_render_template(self, etc...)
  pass

import chrome
chrome.Chrome.render_template = better_render_template

This change will persist for the duration of the Python interpreter,
even across subsequent "import chrome" statements. It's best to do this
very early during BH intialization.

N.B.: I haven't actually looked at what the names of the modules
actually are, but you get the idea.

-- Brane

-- 
Branko Čibej
Director of Subversion | WANdisco | www.wandisco.com


Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
Hi,

Below is a patch for the doctype changes in trac and Bloodhound. I
added a new class variable (default_html_doctype)
to trac's Chrome, which defaults to XHTML Strict and is overridden to
HTML5 in the BloodhoundTheme.


Index: bloodhound_theme/bhtheme/theme.py
===================================================================
--- bloodhound_theme/bhtheme/theme.py	(revision 1416651)
+++ bloodhound_theme/bhtheme/theme.py	(working copy)
@@ -18,6 +18,7 @@

 from genshi.builder import tag
 from genshi.filters.transform import Transformer
+from genshi.output import DocType

 from trac.core import *
 from trac.mimeview.api import get_mimetype
@@ -31,7 +32,7 @@
 from trac.versioncontrol.web_ui.browser import BrowserModule
 from trac.web.api import IRequestFilter, IRequestHandler, ITemplateStreamFilter
 from trac.web.chrome import (add_script, add_stylesheet,
INavigationContributor,
-                             ITemplateProvider, prevnext_nav)
+                             ITemplateProvider, prevnext_nav, Chrome)

 from themeengine.api import ThemeBase, ThemeEngineSystem

@@ -118,6 +119,8 @@
     implements(IRequestFilter, INavigationContributor, ITemplateProvider,
                ITemplateStreamFilter)

+    Chrome.default_html_doctype = DocType.HTML5
+
     # ITemplateStreamFilter methods

     def filter_stream(self, req, method, filename, stream, data):
Index: trac/trac/web/chrome.py
===================================================================
--- trac/trac/web/chrome.py	(revision 1416651)
+++ trac/trac/web/chrome.py	(working copy)
@@ -479,6 +479,9 @@

     templates = None

+    #default doctype for 'text/html' output
+    default_html_doctype = DocType.XHTML_STRICT
+
     # A dictionary of default context data for templates
     _default_context_data = {
         '_': translation.gettext,
@@ -936,8 +939,8 @@

         The `content_type` argument is used to choose the kind of template
         used (`NewTextTemplate` if `'text/plain'`, `MarkupTemplate` otherwise),
-        and tweak the rendering process (use of XHTML Strict doctype if
-        `'text/html'` is given).
+        and tweak the rendering process. Doctype for `'text/html'` can be
+        specified by setting the default_html_doctype (default is XHTML Strict)

         When `fragment` is specified, the (filtered) Genshi stream is
         returned.
@@ -975,7 +978,7 @@
             stream.render('text', out=buffer, encoding='utf-8')
             return buffer.getvalue()

-        doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)
+        doctype = {'text/html': Chrome.default_html_doctype}.get(content_type)
         if doctype:
             if req.form_token:
                 stream |= self._add_form_token(req.form_token)

--
matevz

On Mon, Dec 3, 2012 at 5:01 PM, Olemis Lang <ol...@gmail.com> wrote:
> On 12/3/12, Matevz Bradac <ma...@gmail.com> wrote:
>> Hi,
>>
>> Great, thanks for all the suggestions. =)
>
> :)
>
>> I'll start working on trac changes then,
>
> good
>
>> it would make more sense to
>> make trac itself more configurable
>> than to create workarounds within bloodhound (and possibly other
>> projects based on trac).
>>
>
> In this case you've proven it's worthy .
>
> FWIW I share some ideas for you to consider :
>
>   1. to move doctype selection dict and make it become
>       a class or instance method that can be easily changed
>       at run-time.
>   2. add doctype param to render_template
>
>
> --
> Regards,
>
> Olemis.
>
> Blog ES: http://simelo-es.blogspot.com/
> Blog EN: http://simelo-en.blogspot.com/
>
> Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
On 12/3/12, Matevz Bradac <ma...@gmail.com> wrote:
> Hi,
>
> Great, thanks for all the suggestions. =)

:)

> I'll start working on trac changes then,

good

> it would make more sense to
> make trac itself more configurable
> than to create workarounds within bloodhound (and possibly other
> projects based on trac).
>

In this case you've proven it's worthy .

FWIW I share some ideas for you to consider :

  1. to move doctype selection dict and make it become
      a class or instance method that can be easily changed
      at run-time.
  2. add doctype param to render_template


-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
Hi,

Great, thanks for all the suggestions. =)
I'll start working on trac changes then, it would make more sense to
make trac itself more configurable
than to create workarounds within bloodhound (and possibly other
projects based on trac).

--
matevz

On Mon, Dec 3, 2012 at 12:52 AM, Olemis Lang <ol...@gmail.com> wrote:
> Hi !
>
> On 12/2/12, Matevz Bradac <ma...@gmail.com> wrote:
>> I tried solving this on the stream level, but no luck so far.
>
> However you have been doing an extraordinary research here . Good work .
> :)
>
> [...]
>>
>> Due to the above complications (and those not yet discovered), I'd say
>> it would be easier and less error-prone
>> to just override the genshi.output.get_serializer() with BH's wrapper.
>> The function is pretty trivial and unlikely
>> to change much, so it looks like a safe alternative.
>>
>
> I'm not very aware of the details . Nonetheless I'd just say for the
> moment that there's more chance to accept a patch (i.e. not
> monkeypatching ;) for Chrome.render_template than another for Genshi .
> In the end we are already distributing a modified copy of Trac , so
> patches of this kind are welcome , especially if there's a good reason
> to do so . So at this point don't be afraid of proposing a refactoring
> for that method in order to be able to choose another doctype . Just
> try to keep it as compatible with previous solution as possible ,
> since there is no need to break Trac if e.g. Bloodhound theme is
> disabled
>
> OTOH creating another vendor branch for Genshi is quite unlikely to
> happen soon .
>
> Keep up the good work !
> ;)
>
> --
> Regards,
>
> Olemis.
>
> Blog ES: http://simelo-es.blogspot.com/
> Blog EN: http://simelo-en.blogspot.com/
>
> Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
Hi !

On 12/2/12, Matevz Bradac <ma...@gmail.com> wrote:
> I tried solving this on the stream level, but no luck so far.

However you have been doing an extraordinary research here . Good work .
:)

[...]
>
> Due to the above complications (and those not yet discovered), I'd say
> it would be easier and less error-prone
> to just override the genshi.output.get_serializer() with BH's wrapper.
> The function is pretty trivial and unlikely
> to change much, so it looks like a safe alternative.
>

I'm not very aware of the details . Nonetheless I'd just say for the
moment that there's more chance to accept a patch (i.e. not
monkeypatching ;) for Chrome.render_template than another for Genshi .
In the end we are already distributing a modified copy of Trac , so
patches of this kind are welcome , especially if there's a good reason
to do so . So at this point don't be afraid of proposing a refactoring
for that method in order to be able to choose another doctype . Just
try to keep it as compatible with previous solution as possible ,
since there is no need to break Trac if e.g. Bloodhound theme is
disabled

OTOH creating another vendor branch for Genshi is quite unlikely to
happen soon .

Keep up the good work !
;)

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
I tried solving this on the stream level, but no luck so far. First I
implemented a test wrapper for the stream:
class BloodhoundStream(Stream):
    # Stream is using __slots__, so the subclass should as well
    __slots__ = []

    def render(self, method=None, encoding='utf-8', out=None, **kwargs):
        kwargs['doctype'] = DocType.HTML5
        super(BloodhoundStream, self).render(method, encoding, out, **kwargs)

and in the filter stream I changed the stream's type using:
  stream.__class__ = BloodhoundStream

The Stream however defines an __or__ operator (for chaining purposes)
and that one returns back
a Stream object. So I defined and __or__ in the BloodhoundStream as well:
    def __or__(self, function):
        return BloodhoundStream(_ensure(function(self)),
serializer=self.serializer)

This still doesn't work, because Chrome's render_template() uses
Template.generate() for the initial
stream, and that one returns Stream as well. Since this is the first
Stream in line, all the subsequent
BloodhoundStream objects also become Stream (Stream | BloodhoundStream
| BloodhoundStream
produces a Stream in the end).

Due to the above complications (and those not yet discovered), I'd say
it would be easier and less error-prone
to just override the genshi.output.get_serializer() with BH's wrapper.
The function is pretty trivial and unlikely
to change much, so it looks like a safe alternative.

--
matevz

On Sat, Dec 1, 2012 at 6:13 PM, Olemis Lang <ol...@gmail.com> wrote:
> On 12/1/12, Matevz Bradac <ma...@gmail.com> wrote:
>> Thanks for the suggestion, but unfortunately it won't work on the
>> instance level. =/
>
> :'(
>
>> The Stream class is using __slots__, so most instance attributes are
>> read-only, e.g. this:
>>     import types
>>     stream.render = types.MethodType(new_render, stream)
>> doesn't work - AttributeError exception.
>>
>
> I see .
>
>> Brane suggested monkeypatching on a class/module level, so maybe
>> genshi.core.Stream.serialize(),
>> or even genshi.output.get_serializer() would be good candidates.
>>
>
> that's risky . I'd really suggest to try to solve this at stream level
> since monkey patching at module level may be a serious matter .
>
> FWIW ... most of the time I advocate for wrapping rather than monkey
> patching , because it's easier to deal with the impact and scope of
> the changes .
>
> --
> Regards,
>
> Olemis.
>
> Blog ES: http://simelo-es.blogspot.com/
> Blog EN: http://simelo-en.blogspot.com/
>
> Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
On 12/1/12, Matevz Bradac <ma...@gmail.com> wrote:
> Thanks for the suggestion, but unfortunately it won't work on the
> instance level. =/

:'(

> The Stream class is using __slots__, so most instance attributes are
> read-only, e.g. this:
>     import types
>     stream.render = types.MethodType(new_render, stream)
> doesn't work - AttributeError exception.
>

I see .

> Brane suggested monkeypatching on a class/module level, so maybe
> genshi.core.Stream.serialize(),
> or even genshi.output.get_serializer() would be good candidates.
>

that's risky . I'd really suggest to try to solve this at stream level
since monkey patching at module level may be a serious matter .

FWIW ... most of the time I advocate for wrapping rather than monkey
patching , because it's easier to deal with the impact and scope of
the changes .

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
Thanks for the suggestion, but unfortunately it won't work on the
instance level. =/
The Stream class is using __slots__, so most instance attributes are
read-only, e.g. this:
    import types
    stream.render = types.MethodType(new_render, stream)
doesn't work - AttributeError exception.

Brane suggested monkeypatching on a class/module level, so maybe
genshi.core.Stream.serialize(),
or even genshi.output.get_serializer() would be good candidates.

--
matevzb


On Fri, Nov 30, 2012 at 7:49 AM, Olemis Lang <ol...@gmail.com> wrote:
> On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
>> On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
>>> On 11/29/12, Matevz Bradac <ma...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>
>>> :)
>>>
> [...]
>>
>> I suggest you to consider this approach
>>
>> 1. BH theme already implements IRequestFilter
>> 2. implement a stream wrapper overriding render
>>     method in such a way that DocType.HTML5
>>     (or something more accurate , your choice ;)
>>     is used instead of HTML strict *if appropriate*
>>     e.g. bloodhound theme enabled , etc, etc ...
>
> ... and an elegant solution without wrappers consists of overriding
> access to class' render method using instance attribute , like this
>
> {{{
> #!py
>
> new_doctype = DocType.HTML5
>
> def new_render(method, doctype, out, encoding, [...] ):
>     return stream.render(method, doctype=new_doctype, out=out,
>                            encoding=encoding)
>
> stream.render = new_render
>
> [...]
>
> }}}
>
> [...]
>
> --
> Regards,
>
> Olemis.
>
> Blog ES: http://simelo-es.blogspot.com/
> Blog EN: http://simelo-en.blogspot.com/
>
> Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
> On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
>> On 11/29/12, Matevz Bradac <ma...@gmail.com> wrote:
>>> Hi,
>>>
>>
>> :)
>>
[...]
>
> I suggest you to consider this approach
>
> 1. BH theme already implements IRequestFilter
> 2. implement a stream wrapper overriding render
>     method in such a way that DocType.HTML5
>     (or something more accurate , your choice ;)
>     is used instead of HTML strict *if appropriate*
>     e.g. bloodhound theme enabled , etc, etc ...

... and an elegant solution without wrappers consists of overriding
access to class' render method using instance attribute , like this

{{{
#!py

new_doctype = DocType.HTML5

def new_render(method, doctype, out, encoding, [...] ):
    return stream.render(method, doctype=new_doctype, out=out,
                           encoding=encoding)

stream.render = new_render

[...]

}}}

[...]

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
oops!

On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
> On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
>> On 11/29/12, Matevz Bradac <ma...@gmail.com> wrote:
>>> Hi,
>>>
>>
>> :)
>>
>> [...]
>>>
>>> I tried to override this behaviour by prepending a DocTypeInserter
>>> filter to the stream, but that doesn't
>>> work either - the doctype from trac always comes first in line, and
>>> any subsequent doctypes are ignored
>>> by the serializer.
>>>
>>
>> :(
>>
> [...]
>>> If not, is there any way of overriding trac's behaviour without
>>> modifying trac itself?
>>>
>>
>> Yes , I'll take a look in a while and follow with some suggestion
>> ;)
>>
>
> I analyzed the code in trac.web.chrome.Chrome.render_template . I'll
> paste all the relevant parts of the source code below and suggest
> something after that .
>
> {{{
> #!py
>
>         if self.stream_filters:
>             stream |= self._filter_stream(req, method, filename,
> stream, data)
>
> [...]
>
>         doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)
>
> [...]
>             buffer = StringIO()
>             stream.render(method, doctype=doctype, out=buffer,
>                           encoding='utf-8')
>
> }}}
>
> Notice how doctype is selected (second statement) . Afterwards
> DocType.XHTML_STRICT is passed in to stream.render method , and that's
> the reason why you are always obtaining HTML strict doctype over and
> over
>
> :-/
>
> The good news is that all this happens after the stream has been
> filtered (first statement) . Considering the first paragraph in your
> original message it seems to me that you are inserting the DOCTYPE at
> the beginning of the stream (cmiiw) and that's not the way to go ...
>
> I suggest you to consider this approach
>
> 1. BH theme already implements IRequestFilter

typo ... BH theme already implements ITemplateStreamFilter

> 2. implement a stream wrapper overriding render
>     method in such a way that DocType.HTML5
>     (or something more accurate , your choice ;)
>     is used instead of HTML strict *if appropriate*
>     e.g. bloodhound theme enabled , etc, etc ...
> 3. return stream wrapper rather than the original
>     stream so that your brand new render method
>     is invoked and the content type you want is
>     used instead.
>
> ... you might need to take some extra precautions though ... but I'm
> confident you'll figure them out along the way
> ;)
>
> PS: ... if you need more precise help in real-time I'll connect
> tomorrow to #bloodhound @ freenode IRC channel . More people will be
> there too .
>
> PS: PS: BTW , even if something else is done , in the end we
> definitely have to improve current implementation of filter_stream
> method . It turns out that transformations (i.e. inclusion of default
> Bootstrap classes et al. ) are happening even if bloodhound theme is
> not activated . That's not right because under such circumstances
> Bootstrap won't be there and our template swapping trick won't be
> happening at all .
>

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
On 11/29/12, Olemis Lang <ol...@gmail.com> wrote:
> On 11/29/12, Matevz Bradac <ma...@gmail.com> wrote:
>> Hi,
>>
>
> :)
>
> [...]
>>
>> I tried to override this behaviour by prepending a DocTypeInserter
>> filter to the stream, but that doesn't
>> work either - the doctype from trac always comes first in line, and
>> any subsequent doctypes are ignored
>> by the serializer.
>>
>
> :(
>
[...]
>> If not, is there any way of overriding trac's behaviour without
>> modifying trac itself?
>>
>
> Yes , I'll take a look in a while and follow with some suggestion
> ;)
>

I analyzed the code in trac.web.chrome.Chrome.render_template . I'll
paste all the relevant parts of the source code below and suggest
something after that .

{{{
#!py

        if self.stream_filters:
            stream |= self._filter_stream(req, method, filename,
stream, data)

[...]

        doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)

[...]
            buffer = StringIO()
            stream.render(method, doctype=doctype, out=buffer,
                          encoding='utf-8')

}}}

Notice how doctype is selected (second statement) . Afterwards
DocType.XHTML_STRICT is passed in to stream.render method , and that's
the reason why you are always obtaining HTML strict doctype over and
over

:-/

The good news is that all this happens after the stream has been
filtered (first statement) . Considering the first paragraph in your
original message it seems to me that you are inserting the DOCTYPE at
the beginning of the stream (cmiiw) and that's not the way to go ...

I suggest you to consider this approach

1. BH theme already implements IRequestFilter
2. implement a stream wrapper overriding render
    method in such a way that DocType.HTML5
    (or something more accurate , your choice ;)
    is used instead of HTML strict *if appropriate*
    e.g. bloodhound theme enabled , etc, etc ...
3. return stream wrapper rather than the original
    stream so that your brand new render method
    is invoked and the content type you want is
    used instead.

... you might need to take some extra precautions though ... but I'm
confident you'll figure them out along the way
;)

PS: ... if you need more precise help in real-time I'll connect
tomorrow to #bloodhound @ freenode IRC channel . More people will be
there too .

PS: PS: BTW , even if something else is done , in the end we
definitely have to improve current implementation of filter_stream
method . It turns out that transformations (i.e. inclusion of default
Bootstrap classes et al. ) are happening even if bloodhound theme is
not activated . That's not right because under such circumstances
Bootstrap won't be there and our template swapping trick won't be
happening at all .

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Olemis Lang <ol...@gmail.com>.
On 11/29/12, Matevz Bradac <ma...@gmail.com> wrote:
> Hi,
>

:)

[...]
>
> I tried to override this behaviour by prepending a DocTypeInserter
> filter to the stream, but that doesn't
> work either - the doctype from trac always comes first in line, and
> any subsequent doctypes are ignored
> by the serializer.
>

:(

> Would it be possible to do this in the post processing phase, i.e.
> IRequestFilter's post_process_request()?

No , but just because this is happening at a much lower level (i.e.
template rendering pipeline) . The goal of IRequestFilter
post-processing step is to customize data immediately before expanding
the Genshi template .

> If not, is there any way of overriding trac's behaviour without
> modifying trac itself?
>

Yes , I'll take a look in a while and follow with some suggestion
;)

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
Hi,

I'm having some issues with converting the doctype to HTML5, any help
is appreciated.
Basically I've modified all the BH templates, but the doctype still
came up as XHTML strict.
I've tracked the problem to trac's template rendering, which seems to
force XHTML without any
regard to what's actually specified in the template - the offending
function is Chrome's render_template()
in web/chrome.py.

I tried to override this behaviour by prepending a DocTypeInserter
filter to the stream, but that doesn't
work either - the doctype from trac always comes first in line, and
any subsequent doctypes are ignored
by the serializer.

Would it be possible to do this in the post processing phase, i.e.
IRequestFilter's post_process_request()?
If not, is there any way of overriding trac's behaviour without
modifying trac itself?

--
matevz

On Mon, Nov 26, 2012 at 9:51 AM, Matevz Bradac <ma...@gmail.com> wrote:
> So I suppose we should first focus on cleaning up the current
> situation and then move on to #217.
> If agreed, I'll open a new ticket for the cleanup and start working on
> that first.
>
> --
> matevz
>
> On Mon, Nov 26, 2012 at 9:46 AM, Joe Dreimann
> <jo...@wandisco.com> wrote:
>> To my knowledge all relevant browsers (including IE6 etc) will display HTML 5 pages (using quirks mode), more information here:
>> http://stackoverflow.com/questions/3911235/html-5-doctype-and-ie-6
>>
>> In my opinion this is not an issue, we should be fine to use HTML 5.
>>
>> Joe
>>
>> ________________________
>> @jdreimann - Twitter
>> Sent from my phone
>>
>> On 26 Nov 2012, at 07:03, Peter Koželj <pe...@digiverse.si> wrote:
>>
>>> The other thread "Inline editing of objects" (for the Ticket page) suggest
>>> fallback mechanism for javascript disabled browsers.
>>> Although this is not directly linked I would rather "advertise" BH as HTML5
>>> UI experience than a no-javascript capable one.
>>>
>>> Is anybody aware of any browser that is actually incapable of displaying
>>> HTML5 page?
>>>
>>> Peter
>>>
>>> On 25 November 2012 20:07, Matevz Bradac <ma...@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I've started working on #217 - "Make Bloodhound's layout responsive",
>>>> based on Joe's html mockup of the ticket page (#240).
>>>> I noticed that the HTML output contains a mix of HTML 5 along with
>>>> XHTML 1.0, even though the doctype is XHTML 1.0 strict.
>>>> As a consequence (some of) the pages don't validate (e.g.
>>>>
>>>> http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240
>>>> ),
>>>> and this may be the cause of browsers (mis)behaving and rendering
>>>> things differently.
>>>>
>>>> Is there any general consensus which doctype BH should use? Since
>>>> we're using Bootstrap I suppose it would be better to go along
>>>> with HTML 5, but I'm not sure how this affects the templating system.
>>>> There's a Genshi extension which could be used
>>>> (http://code.google.com/p/genshihtml5),
>>>> does anyone have any experience with that?
>>>>
>>>> Cheers,
>>>> matevz
>>>>

Re: Genshi XHTML + HTML 5

Posted by Matevz Bradac <ma...@gmail.com>.
So I suppose we should first focus on cleaning up the current
situation and then move on to #217.
If agreed, I'll open a new ticket for the cleanup and start working on
that first.

--
matevz

On Mon, Nov 26, 2012 at 9:46 AM, Joe Dreimann
<jo...@wandisco.com> wrote:
> To my knowledge all relevant browsers (including IE6 etc) will display HTML 5 pages (using quirks mode), more information here:
> http://stackoverflow.com/questions/3911235/html-5-doctype-and-ie-6
>
> In my opinion this is not an issue, we should be fine to use HTML 5.
>
> Joe
>
> ________________________
> @jdreimann - Twitter
> Sent from my phone
>
> On 26 Nov 2012, at 07:03, Peter Koželj <pe...@digiverse.si> wrote:
>
>> The other thread "Inline editing of objects" (for the Ticket page) suggest
>> fallback mechanism for javascript disabled browsers.
>> Although this is not directly linked I would rather "advertise" BH as HTML5
>> UI experience than a no-javascript capable one.
>>
>> Is anybody aware of any browser that is actually incapable of displaying
>> HTML5 page?
>>
>> Peter
>>
>> On 25 November 2012 20:07, Matevz Bradac <ma...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I've started working on #217 - "Make Bloodhound's layout responsive",
>>> based on Joe's html mockup of the ticket page (#240).
>>> I noticed that the HTML output contains a mix of HTML 5 along with
>>> XHTML 1.0, even though the doctype is XHTML 1.0 strict.
>>> As a consequence (some of) the pages don't validate (e.g.
>>>
>>> http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240
>>> ),
>>> and this may be the cause of browsers (mis)behaving and rendering
>>> things differently.
>>>
>>> Is there any general consensus which doctype BH should use? Since
>>> we're using Bootstrap I suppose it would be better to go along
>>> with HTML 5, but I'm not sure how this affects the templating system.
>>> There's a Genshi extension which could be used
>>> (http://code.google.com/p/genshihtml5),
>>> does anyone have any experience with that?
>>>
>>> Cheers,
>>> matevz
>>>

Re: Genshi XHTML + HTML 5

Posted by Joe Dreimann <jo...@wandisco.com>.
To my knowledge all relevant browsers (including IE6 etc) will display HTML 5 pages (using quirks mode), more information here:
http://stackoverflow.com/questions/3911235/html-5-doctype-and-ie-6

In my opinion this is not an issue, we should be fine to use HTML 5.

Joe

________________________
@jdreimann - Twitter
Sent from my phone

On 26 Nov 2012, at 07:03, Peter Koželj <pe...@digiverse.si> wrote:

> The other thread "Inline editing of objects" (for the Ticket page) suggest
> fallback mechanism for javascript disabled browsers.
> Although this is not directly linked I would rather "advertise" BH as HTML5
> UI experience than a no-javascript capable one.
> 
> Is anybody aware of any browser that is actually incapable of displaying
> HTML5 page?
> 
> Peter
> 
> On 25 November 2012 20:07, Matevz Bradac <ma...@gmail.com> wrote:
> 
>> Hi,
>> 
>> I've started working on #217 - "Make Bloodhound's layout responsive",
>> based on Joe's html mockup of the ticket page (#240).
>> I noticed that the HTML output contains a mix of HTML 5 along with
>> XHTML 1.0, even though the doctype is XHTML 1.0 strict.
>> As a consequence (some of) the pages don't validate (e.g.
>> 
>> http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240
>> ),
>> and this may be the cause of browsers (mis)behaving and rendering
>> things differently.
>> 
>> Is there any general consensus which doctype BH should use? Since
>> we're using Bootstrap I suppose it would be better to go along
>> with HTML 5, but I'm not sure how this affects the templating system.
>> There's a Genshi extension which could be used
>> (http://code.google.com/p/genshihtml5),
>> does anyone have any experience with that?
>> 
>> Cheers,
>> matevz
>> 

Re: Genshi XHTML + HTML 5

Posted by Peter Koželj <pe...@digiverse.si>.
The other thread "Inline editing of objects" (for the Ticket page) suggest
fallback mechanism for javascript disabled browsers.
Although this is not directly linked I would rather "advertise" BH as HTML5
UI experience than a no-javascript capable one.

Is anybody aware of any browser that is actually incapable of displaying
HTML5 page?

Peter

On 25 November 2012 20:07, Matevz Bradac <ma...@gmail.com> wrote:

> Hi,
>
> I've started working on #217 - "Make Bloodhound's layout responsive",
> based on Joe's html mockup of the ticket page (#240).
> I noticed that the HTML output contains a mix of HTML 5 along with
> XHTML 1.0, even though the doctype is XHTML 1.0 strict.
> As a consequence (some of) the pages don't validate (e.g.
>
> http://validator.w3.org/check?uri=https://issues.apache.org/bloodhound/ticket/240
> ),
> and this may be the cause of browsers (mis)behaving and rendering
> things differently.
>
> Is there any general consensus which doctype BH should use? Since
> we're using Bootstrap I suppose it would be better to go along
> with HTML 5, but I'm not sure how this affects the templating system.
> There's a Genshi extension which could be used
> (http://code.google.com/p/genshihtml5),
> does anyone have any experience with that?
>
> Cheers,
> matevz
>