summaryrefslogtreecommitdiff
path: root/src/HTML5/Parser/TreeBuildingRules.php
blob: 33d46b1b5449573071bfbebf610be6010eb91b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace HTML5\Parser;

use HTML5\Elements;

/**
 * Handles special-case rules for the DOM tree builder.
 *
 * Many tags have special rules that need to be accomodated on an 
 * individual basis. This class handles those rules.
 *
 * See section 8.1.2.4 of the spec.
 */
class TreeBuildingRules {

  protected static $tags = array(
    'li' => 1,
  );

  /**
   * Build a new rules engine.
   *
   * @param \DOMDocument $doc
   *   The DOM document to use for evaluation and modification.
   */
  public function __construct($doc) {
    $this->doc = $doc;
  }

  /**
   * Returns TRUE if the given tagname has special processing rules.
   */
  public function hasRules($tagname) {
    return isset(self::$tags[$tagname]);
  }

  /**
   * Evaluate the rule for the current tag name.
   *
   * This may modify the existing DOM.
   *
   * @return \DOMElement
   *   The new Current DOM element.
   */
  public function evaluate($new, $current) {

    switch($new->tagName) {
    case 'li':
      return $this->handleLI($new, $current);

    }

    return $current;
  }

  protected function handleLI($ele, $current) {
    if ($current->tagName == 'li') {
      $current->parentNode->appendChild($ele);
      return $ele;
    }
    // XXX FINISH

    $current->appendChild($ele);
    return $current;

  }
}