HTML5 and still wanting self-closing tags (aka XHTML5)

92 views
Skip to first unread message

Bill Turner

unread,
Sep 23, 2009, 10:50:34 AM9/23/09
to Haml
Hi folks,

I'm relatively new to HAML, but I'm really liking it (and SASS). I
have a peculiar issue that I'm trying to work out for my sinatra app.

I have the format set to html5, via:

set :haml, { :format => :html5 }

but is there a way to have the option for self-closing tags with HTML5
along with the new HTML5 doctype? Even if I add the :autoclose to the
set command, those tags (like link) don't self close.

set :haml, { :format => :html5, :autoclose => ['meta', 'img', 'link',
'br', 'hr', 'input', 'area', 'param', 'col', 'base'] }

Also, possibly related, on my .haml templates for XML files, the !!!
no longer will give me an XML header, none of these work:
!!!
!!! XML
!!! xml

Any ideas for either of these?
Many thanks!
Bill

Nathan Weizenbaum

unread,
Sep 23, 2009, 2:26:32 PM9/23/09
to ha...@googlegroups.com
There is no doctype defined for XHTML5; see
http://www.whatwg.org/specs/web-apps/current-work/#writing-xhtml-documents.
What doctype are you trying to use?

As for the XML header, the only reason I could imagine for it not being
displayed is if you're rendering the templates in HTML mode.

Bill Turner

unread,
Sep 23, 2009, 6:17:16 PM9/23/09
to Haml
The new doctype for HTML5 is this:

<!DOCTYPE html>

And haml correctly displays this (with no code changes from me), when
using set :haml, { :format => :html5 }, and using !!! at the top of my
haml layout file. That part works fine, but I'd like to combine that
doctype with xhtml syntax - which is essentially xhtml5.

As for the second item, is there a way to force the rendering mode to
be XML? I'm using:

haml :sitemap, :layout => false

and the !!! seems to be simply ignored.

Here's a little more info on the html5/xhtml5 doctype (and syntax):
http://www.hagenburger.net/2009/03/html5-xhtml5-with-css-for-safari-firefox-opera-ie

Thanks
Bill

On Sep 23, 2:26 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:
> There is no doctype defined for XHTML5; seehttp://www.whatwg.org/specs/web-apps/current-work/#writing-xhtml-docu....

Nathan Weizenbaum

unread,
Sep 23, 2009, 8:24:45 PM9/23/09
to ha...@googlegroups.com
So you want to use the HTML5 doctype with XHTML syntax? That's not required in the specification, but I'll consider adding support for it. I may add it as "!!! 5" with the normal :xhtml format, rather than a new :xhtml5 format, though.

As for the XML header, I'm still not sure why that isn't working. What framework are you using? Are you sure you aren't rendering the Haml with :format set to :html5?

Norman Clarke

unread,
Sep 23, 2009, 9:04:02 PM9/23/09
to ha...@googlegroups.com
Rather than "!!! 5" it might be better to have something like
:self_closing => true which is always false for HTML4, always true for
XHTML, but can be set to true or false for HTML5.

Regards,

Norman

Bill Turner

unread,
Sep 23, 2009, 10:39:38 PM9/23/09
to Haml
On Sep 23, 9:04 pm, Norman Clarke <com...@gmail.com> wrote:
> Rather than "!!! 5" it might be better to have something like
> :self_closing => true which is always false for HTML4, always true for
> XHTML, but can be set to true or false for HTML5.

I think this is a better option. Since there may be fewer that want to
use the self-closing tags. Would it make it easier to add this type of
option?

> > As for the XML header, I'm still not sure why that isn't working. What
> > framework are you using? Are you sure you aren't rendering the Haml with
> > :format set to :html5?

I do have set :set haml, :format => :html5 in the configuration for my
sinatra app. And for most of what I'm doing that's perfect, but on two
items (rss/xml feed and xml sitemap, I need XML formatting. Is there a
way to override the :html5 global setting? Something like this:

get '/sitemap.xml' do
haml :sitemap, :layout => false, :format => :xml
end

Thanks for your help and input!
Bill


>
> > On Wed, Sep 23, 2009 at 3:17 PM, Bill Turner <billtur...@gmail.com> wrote:
>
> >> The new doctype for HTML5 is this:
>
> >> <!DOCTYPE html>
>
> >> And haml correctly displays this (with no code changes from me), when
> >> using set :haml, { :format => :html5 }, and using !!! at the top of my
> >> haml layout file. That part works fine, but I'd like to combine that
> >> doctype with xhtml syntax - which is essentially xhtml5.
>
> >> As for the second item, is there a way to force the rendering mode to
> >> be XML? I'm using:
>
> >> haml :sitemap, :layout => false
>
> >> and the !!! seems to be simply ignored.
>
> >> Here's a little more info on the html5/xhtml5 doctype (and syntax):
>
> >>http://www.hagenburger.net/2009/03/html5-xhtml5-with-css-for-safari-f...

Nathan Weizenbaum

unread,
Sep 24, 2009, 12:28:08 AM9/24/09
to ha...@googlegroups.com
I don't like the idea of multiplying the number of options we have without adding new functionality, and I don't think a :self_closing option would be particularly useful. I don't think there's anything wrong with bundling all the syntactic changes between HTML and XHTML in one option.

If I were redesigning the formatting options from scratch, I think I'd just have :html and :xhtml formats, and have the doctype (the only difference between :html4 and :html5) be set explicitly. I may migrate to something like that in the future.

Nathan Weizenbaum

unread,
Sep 24, 2009, 12:28:47 AM9/24/09
to ha...@googlegroups.com
That's more of a Sinatra question... Haml doesn't handle framework configuration. It just gets options passed in on a per-template basis.

E

unread,
Nov 19, 2009, 12:02:01 PM11/19/09
to Haml
Anything new ? XHTML5 is useful since Firefox 2 and other gecko
browsers pre 1.9b5 need pages served as xhtml+xml to correctly render
html5 elements. A XML parsing error is then raised by the browser if
self closing elements have no tailing slash.

Mislav Marohnić

unread,
Nov 19, 2009, 4:21:55 PM11/19/09
to ha...@googlegroups.com
Use XHTML format in Haml options, but write the HTML5 doctype yourself instead of "!!!".
Problem solved

Nathan Weizenbaum

unread,
Nov 20, 2009, 6:08:35 AM11/20/09
to ha...@googlegroups.com
I've just pushed a change to stable that allows you to use "!!! 5" in an XHTML document to produce an HTML5 doctype.

--

You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=.

Eugenol

unread,
Nov 20, 2009, 6:28:12 AM11/20/09
to ha...@googlegroups.com
On Fri, Nov 20, 2009 at 12:08 PM, Nathan Weizenbaum <nex...@gmail.com> wrote:
> I've just pushed a change to stable that allows you to use "!!! 5" in an
> XHTML document to produce an HTML5 doctype.

Sweet ! Thanks !

E

unread,
Nov 20, 2009, 6:50:25 AM11/20/09
to Haml


On 20 nov, 12:08, Nathan Weizenbaum <nex...@gmail.com> wrote:
> I've just pushed a change to stable that allows you to use "!!! 5" in an
> XHTML document to produce an HTML5 doctype.

According to the updated documentation, "!!!" is enough when format is
set to :html5 or is there a mistake ?

Nathan Weizenbaum

unread,
Nov 20, 2009, 6:53:26 AM11/20/09
to ha...@googlegroups.com
No mistake, that's correct. And that's always been the case (since we added HTML5 support).

--

You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.

Bill Turner

unread,
Dec 5, 2009, 3:49:18 PM12/5/09
to Haml
On Nov 20, 6:08 am, Nathan Weizenbaum <nex...@gmail.com> wrote:
> I've just pushed a change to stable that allows you to use "!!! 5" in an
> XHTML document to produce an HTML5 doctype.

Thanks for adding this, Nathan. I really appreciate it. Works
perfectly!

Bill


>
> On Thu, Nov 19, 2009 at 1:21 PM, Mislav Marohnić
> <mislav.maroh...@gmail.com>wrote:
Reply all
Reply to author
Forward
0 new messages