[Haml] Support the XHTML5 doctype.

This commit is contained in:
Nathan Weizenbaum 2009-11-20 03:07:21 -08:00
parent e1bed36527
commit 2cd699f932
4 changed files with 11 additions and 1 deletions

View File

@ -10,6 +10,9 @@
* Don't crash when parsing an XHTML Strict doctype in `html2haml`.
* Support the HTML5 doctype in an XHTML document
by using `!!! 5` as the doctype declaration.
## [2.2.13](http://github.com/nex3/haml/commit/2.2.13)
* Allow users to specify {file:HAML_REFERENCE.md#encoding_option `:encoding => "ascii-8bit"`}

View File

@ -655,6 +655,10 @@ the following doctypes are supported:
: XHTML 1.0 Frameset<br/>
`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">`
`!!! 5`
: XHTML 5<br/>
`<!DOCTYPE html>`<br/>
`!!! 1.1`
: XHTML 1.1<br/>
`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">`

View File

@ -82,7 +82,7 @@ module Haml
MID_BLOCK_KEYWORD_REGEX = /^-\s*(#{%w[else elsif rescue ensure when end].join('|')})\b/
# The Regex that matches a Doctype command.
DOCTYPE_REGEX = /(\d\.\d)?[\s]*([a-z]*)/i
DOCTYPE_REGEX = /(\d(?:\.\d)?)?[\s]*([a-z]*)/i
# The Regex that matches a literal string or symbol value
LITERAL_VALUE_REGEX = /:(\w*)|(["'])((?![\\#]|\2).|\\.)*\2/
@ -848,6 +848,8 @@ END
if xhtml?
if version == "1.1"
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
elsif version == "5"
'<!DOCTYPE html>'
else
case type
when "strict"; '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'

View File

@ -729,6 +729,7 @@ HAML
def test_doctypes
assert_equal('<!DOCTYPE html>',
render('!!!', :format => :html5).strip)
assert_equal('<!DOCTYPE html>', render('!!! 5').strip)
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
render('!!! strict').strip)
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',