diff options
-rw-r--r-- | it_html.class | 10 | ||||
-rwxr-xr-x | tests/it_html.t | 26 |
2 files changed, 29 insertions, 7 deletions
diff --git a/it_html.class b/it_html.class index 7437aed..03a46ea 100644 --- a/it_html.class +++ b/it_html.class @@ -317,13 +317,11 @@ function _tag($name, $args) $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'][0] != 'x') - $result .= ">$newline"; + # close tag according to html dialect + if ($this->p['htmltype'][0] == 'x') # xhtml + $result .= isset($data) || isset($this->alwaysclose[$name]) ? ">$data</$name>$newline" : " />$newline"; else - $result .= " />$newline"; + $result .= isset($data) || !self::$voidtags[$name] ? ">$data</$name>$newline" : ">$newline"; if ($GLOBALS['debug_utf8check'] && $charset == "utf-8") $result = it::any2utf8($result, "error in $name()"); diff --git a/tests/it_html.t b/tests/it_html.t index e863339..0c419b8 100755 --- a/tests/it_html.t +++ b/tests/it_html.t @@ -5,7 +5,7 @@ it::getopt(""); #handle possible --debug parameter # Tests for html.class -# Traditional html generation +# Traditional html5 generation ini_set('default_charset', "utf-8"); new it_html(array('htmltype' => "html")); @@ -22,6 +22,18 @@ is( ); is( + h1(), + "<h1></h1>\n", + "empty h1 tag" +); + +is( + input(), + "<input>", + "no closing tag for void elements" +); + +is( img(array('src' => "foo.png", 'alt' => "ALT")), '<img src="foo.png" alt="ALT">', "img tag with attributes" @@ -118,6 +130,18 @@ is( "xmltest tag with attributes" ); +is( + h1(), + "<h1 />\n", + "empty h1 tag in xml context" +); + +is( + input(), + "<input />", + "empty input tag in xml context" +); + # Inheriting and extending it_html class myhtml extends it_html { |