diff options
author | Christian Schneider | 2014-02-21 13:54:54 +0100 |
---|---|---|
committer | Christian Schneider | 2014-02-21 13:54:54 +0100 |
commit | 698066659774331dadd9cb0c1dab0aba795588b0 (patch) | |
tree | 51a664ee85b6b966f193b4ba5afc5ec745c43909 | |
parent | 723d9d7382e37cac06d9c1ebc00ded066ee0810b (diff) | |
download | itools-698066659774331dadd9cb0c1dab0aba795588b0.tar.gz itools-698066659774331dadd9cb0c1dab0aba795588b0.tar.bz2 itools-698066659774331dadd9cb0c1dab0aba795588b0.zip |
Added support for htmltype 'html5' to it_html
-rw-r--r-- | it_html.class | 11 | ||||
-rwxr-xr-x | tests/it_html.t | 8 |
2 files changed, 14 insertions, 5 deletions
diff --git a/it_html.class b/it_html.class index 4b9dcf5..fbab0db 100644 --- a/it_html.class +++ b/it_html.class @@ -69,7 +69,7 @@ function it_html($p = array()) 'charset' => ini_get('default_charset') ?: 'iso-8859-1', 'doctype' => null, # Custom doctype (will usually be calculated from htmltype) 'head' => '', # Code to put into head() section - 'htmltype' => 'xhtml', # 'html' (=old-style), 'xhtml' or 'xhtml-mobile' + 'htmltype' => 'html5', # 'html5', 'html' (=old-style), 'xhtml' or 'xhtml-mobile' 'lang' => 'de', # Language code to use in <html lang="..."> tag 'ie_png_fix' => false, # To enable, supply URL of a transparent gif (like /images/0.gif) 'moretags' => '', # Comma-separated list of tag-functions to generate additionally to 'tags' @@ -90,6 +90,7 @@ function it_html($p = array()) # We know these doctypes. If you need something else, supply 'doctype' in p $this->doctypes = array( + 'html5' => '<!DOCTYPE html>', 'html' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', 'xhtml' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 'xhtml-mobile' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">' @@ -181,7 +182,7 @@ function head($args = array()) $p += $this->p; $this->p = ($p += array('content-type' => "text/html; charset={$p['charset']}")); - $header = $p['show_content_type'] ? meta(array('http-equiv' => "Content-Type", 'content' => $p['content-type'])) : ""; + $header = $p['show_content_type'] ? meta($p['htmltype'] == "html5" ? array('charset' => $p['charset']) : array('http-equiv' => "Content-Type", 'content' => $p['content-type'])) : ""; # Enable latest IE mode if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) @@ -305,13 +306,13 @@ function _tag($name, $args) $result .= " $key=\"$value\""; } else # true: tag without value - $result .= ($this->p['htmltype'] == 'html') ? " $key" : " $key=\"$key\""; + $result .= ($this->p['htmltype'][0] != 'x') ? " $key" : " $key=\"$key\""; } # Apply a kind of magic... this needs further investigation if (isset($data) || isset($this->alwaysclose[$name])) $result .= ">$data</$name>$newline"; - elseif ($this->p['htmltype'] == 'html') + elseif ($this->p['htmltype'][0] != 'x') $result .= ">$newline"; else $result .= " />$newline"; @@ -556,7 +557,7 @@ static function U(/* ... */) */ function js($args) { - if (($this->p['htmltype'] != 'html') && $args[0] && ((array)$args[0] === array_values((array)$args[0]))) + if (($this->p['htmltype'][0] == 'x') && $args[0] && ((array)$args[0] === array_values((array)$args[0]))) { array_unshift($args, "<!--//--><![CDATA[//><!--\n"); $args[] = "\n//--><!]]>"; diff --git a/tests/it_html.t b/tests/it_html.t index b50b3c9..4c06d9d 100755 --- a/tests/it_html.t +++ b/tests/it_html.t @@ -88,6 +88,14 @@ is( "use html entities in attributes but not in normal text", ); +# Test different html types +foreach (array('html5' => "<br flag>", 'html' => "<br flag>", 'xhtml' => "<br flag=\"flag\" />", 'xhtml-mobile' => "<br flag=\"flag\" />") as $type => $value) +{ + unset($GLOBALS['it_html']); + new it_html(array('htmltype' => $type)); + is (trim(br('flag' => true)), $value, "Check empty tag and attribute for $type"); +} + # XML generation unset($GLOBALS['it_html']); new it_html(array('htmltype' => "xhtml", 'tags' => "xmltest")); |