Skip to content

Commit

Permalink
[Haml] Support the XHTML5 doctype.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Nov 20, 2009
1 parent e1bed36 commit 2cd699f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc-src/HAML_CHANGELOG.md
Expand Up @@ -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"`}
Expand Down
4 changes: 4 additions & 0 deletions doc-src/HAML_REFERENCE.md
Expand Up @@ -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">`
Expand Down
4 changes: 3 additions & 1 deletion lib/haml/precompiler.rb
Expand Up @@ -82,7 +82,7 @@ module Precompiler
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/
Expand Down Expand Up @@ -848,6 +848,8 @@ def text_for_doctype(text)
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">'
Expand Down
1 change: 1 addition & 0 deletions test/haml/engine_test.rb
Expand Up @@ -729,6 +729,7 @@ def test_stop_eval
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">',
Expand Down

0 comments on commit 2cd699f

Please sign in to comment.