summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsmir Mustafic <[email protected]>2015-05-17 16:26:11 +0200
committerAsmir Mustafic <[email protected]>2015-05-17 16:26:11 +0200
commitc69bde18fc83cc7166e4c618c4a9260ae22bde91 (patch)
treecf191961112e087cc5314b5618a75af20fa2cb81
parent6222ad4d1e4120a1f154caf8b0e25f4daa921da8 (diff)
parente36b070ebe68235d489a2b91d1299c8df6be7386 (diff)
Merge pull request #84 from Masterminds/boolean-attribiutes
Improved boolean attribute handling
-rw-r--r--src/HTML5/Serializer/OutputRules.php85
-rw-r--r--test/HTML5/Serializer/OutputRulesTest.php10
2 files changed, 85 insertions, 10 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php
index c009698..4ad74f6 100644
--- a/src/HTML5/Serializer/OutputRules.php
+++ b/src/HTML5/Serializer/OutputRules.php
@@ -73,17 +73,86 @@ 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('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',
+ 'xpath' => 'starts-with(local-name(), \'data-\')',
),
-
);
const DOCTYPE = '<!DOCTYPE html>';
@@ -328,7 +397,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('<input type="radio" readonly>'),
array('<input type="radio" checked disabled>'),
array('<input type="checkbox" checked disabled>'),
+ array('<input type="radio" value="" checked disabled>'),
+ array('<div data-value=""></div>'),
array('<select disabled></select>'),
- array('<div ng-app>foo</div>'),
+ array('<div ng-app></div>'),
array('<script defer></script>'),
);
}
@@ -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]+(.*)></[a-z]+>~', '\1', $html);
+ $html = preg_replace('~<[a-z]+(.*)/?>~', '\1', $html);
+
+ $this->assertEquals($content, $html);
}