Skip to content

Commit

Permalink
Fragments with rules
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Sep 23, 2014
1 parent ef46469 commit e1e579a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/HTML5/Parser/DOMTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function startTag($name, $attributes = array(), $selfClosing = false)
}

// Some elements have special processing rules. Handle those separately.
if ($this->rules->hasRules($name)) {
if ($this->rules->hasRules($name) && $this->frag !== $this->current) {
$this->current = $this->rules->evaluate($ele, $this->current);
} // Otherwise, it's a standard element.
else {
Expand Down
28 changes: 25 additions & 3 deletions test/HTML5/Parser/TreeBuildingRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,36 @@ class TreeBuildingRulesTest extends \Masterminds\HTML5\Tests\TestCase
protected function parse($string)
{
$treeBuilder = new DOMTreeBuilder();
$input = new StringInputStream($string);
$scanner = new Scanner($input);
$scanner = new Scanner(new StringInputStream($string));
$parser = new Tokenizer($scanner, $treeBuilder);

$parser->parse();

return $treeBuilder->document();
}
/**
* Convenience function for parsing fragments.
*/
protected function parseFragment($string)
{
$events = new DOMTreeBuilder(true);
$scanner = new Scanner(new StringInputStream($string));
$parser = new Tokenizer($scanner, $events);

$parser->parse();
return $events->fragment();
}

public function testTDFragment()
{

$frag = $this->parseFragment("<td>This is a test of the HTML5 parser</td>");

$td = $frag->childNodes->item(0);

$this->assertEquals(1, $frag->childNodes->length);
$this->assertEquals('td', $td->tagName);
$this->assertEquals('This is a test of the HTML5 parser', $td->nodeValue);
}

public function testHasRules()
{
Expand Down

0 comments on commit e1e579a

Please sign in to comment.