From 93df3656bbb4b7718a177c257fa44f8c981c4c5a Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 May 2015 10:18:45 +0200 Subject: Improved boolean attribute handling --- src/HTML5/Serializer/OutputRules.php | 15 +++++++-------- test/HTML5/Serializer/OutputRulesTest.php | 10 ++++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index c009698..7a51016 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -73,17 +73,16 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface 'nodeName'=>'img', 'nodeName'=>array('img', 'a'), 'attrName'=>'alt', 'attrName'=>array('title', 'alt'), - - - 'prefixes'=>['xh'=>'http://www.w3.org/1999/xhtml'), - 'xpath' => "@checked[../../xh:input[@type='radio' or @type='checkbox']]", ), */ array( - 'nodeNamespace'=>'http://www.w3.org/1999/xhtml', - 'attrName'=>array('alt', 'title'), + 'nodeNamespace' => 'http://www.w3.org/1999/xhtml', + 'attrName' => array('alt', 'title', 'value', 'type', 'href', 'id', 'style'), + ), + array( + 'nodeNamespace' => 'http://www.w3.org/1999/xhtml', + 'xpath' => 'starts-with(local-name(), \'data-\')', ), - ); const DOCTYPE = ''; @@ -328,7 +327,7 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface $xp->registerNamespace($nsPrefix, $ns); } } - if(!$xp->query($rule['xpath'], $attr->ownerElement)->length){ + if(!$xp->evaluate($rule['xpath'], $attr)){ continue; } } diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php index aa2e0c5..72d1cd3 100644 --- a/test/HTML5/Serializer/OutputRulesTest.php +++ b/test/HTML5/Serializer/OutputRulesTest.php @@ -460,8 +460,10 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase array(''), array(''), array(''), + array(''), + array('
'), array(''), - array('
foo
'), + array('
'), array(''), ); } @@ -482,7 +484,11 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase $m->invoke($r, $node); $content = stream_get_contents($stream, - 1, 0); - $this->assertContains($content, $html); + + $html = preg_replace('~<[a-z]+(.*)>~', '\1', $html); + $html = preg_replace('~<[a-z]+(.*)/?>~', '\1', $html); + + $this->assertEquals($content, $html); } -- cgit v1.2.3 From e36b070ebe68235d489a2b91d1299c8df6be7386 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 May 2015 10:30:56 +0200 Subject: Addex exhaustive list of non boolean html attributes --- src/HTML5/Serializer/OutputRules.php | 72 +++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 7a51016..4ad74f6 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -77,7 +77,77 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface */ array( 'nodeNamespace' => 'http://www.w3.org/1999/xhtml', - 'attrName' => array('alt', 'title', 'value', 'type', 'href', 'id', 'style'), + 'attrName' => array('href', + 'hreflang', + 'http-equiv', + 'icon', + 'id', + 'keytype', + 'kind', + 'label', + 'lang', + 'language', + 'list', + 'maxlength', + 'media', + 'method', + 'name', + 'placeholder', + 'rel', + 'rows', + 'rowspan', + 'sandbox', + 'spellcheck', + 'scope', + 'seamless', + 'shape', + 'size', + 'sizes', + 'span', + 'src', + 'srcdoc', + 'srclang', + 'srcset', + 'start', + 'step', + 'style', + 'summary', + 'tabindex', + 'target', + 'title', + 'type', + 'value', + 'width', + 'border', + 'charset', + 'cite', + 'class', + 'code', + 'codebase', + 'color', + 'cols', + 'colspan', + 'content', + 'coords', + 'data', + 'datetime', + 'default', + 'dir', + 'dirname', + 'enctype', + 'for', + 'form', + 'formaction', + 'headers', + 'height', + 'accept', + 'accept-charset', + 'accesskey', + 'action', + 'align', + 'alt', + 'bgcolor', + ), ), array( 'nodeNamespace' => 'http://www.w3.org/1999/xhtml', -- cgit v1.2.3