Mercurial > hg > isophonics-drupal-site
comparison vendor/masterminds/html5/src/HTML5/Parser/TreeBuildingRules.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
| author | Chris Cannam |
|---|---|
| date | Thu, 28 Feb 2019 13:21:36 +0000 |
| parents | 4c8ae668cc8c |
| children |
comparison
equal
deleted
inserted
replaced
| 16:c2387f117808 | 17:129ea1e6d783 |
|---|---|
| 1 <?php | 1 <?php |
| 2 | |
| 2 namespace Masterminds\HTML5\Parser; | 3 namespace Masterminds\HTML5\Parser; |
| 3 | 4 |
| 4 /** | 5 /** |
| 5 * Handles special-case rules for the DOM tree builder. | 6 * Handles special-case rules for the DOM tree builder. |
| 6 * | 7 * |
| 12 * @todo - colgroup and col special behaviors | 13 * @todo - colgroup and col special behaviors |
| 13 * - body and head special behaviors | 14 * - body and head special behaviors |
| 14 */ | 15 */ |
| 15 class TreeBuildingRules | 16 class TreeBuildingRules |
| 16 { | 17 { |
| 17 | |
| 18 protected static $tags = array( | 18 protected static $tags = array( |
| 19 'li' => 1, | 19 'li' => 1, |
| 20 'dd' => 1, | 20 'dd' => 1, |
| 21 'dt' => 1, | 21 'dt' => 1, |
| 22 'rt' => 1, | 22 'rt' => 1, |
| 27 'thead' => 1, | 27 'thead' => 1, |
| 28 'tfoot' => 1, | 28 'tfoot' => 1, |
| 29 'tbody' => 1, | 29 'tbody' => 1, |
| 30 'table' => 1, | 30 'table' => 1, |
| 31 'optgroup' => 1, | 31 'optgroup' => 1, |
| 32 'option' => 1 | 32 'option' => 1, |
| 33 ); | 33 ); |
| 34 | |
| 35 /** | |
| 36 * Build a new rules engine. | |
| 37 * | |
| 38 * @param \DOMDocument $doc | |
| 39 * The DOM document to use for evaluation and modification. | |
| 40 */ | |
| 41 public function __construct($doc) | |
| 42 { | |
| 43 $this->doc = $doc; | |
| 44 } | |
| 45 | 34 |
| 46 /** | 35 /** |
| 47 * Returns true if the given tagname has special processing rules. | 36 * Returns true if the given tagname has special processing rules. |
| 48 */ | 37 */ |
| 49 public function hasRules($tagname) | 38 public function hasRules($tagname) |
| 69 case 'rt': | 58 case 'rt': |
| 70 case 'rp': | 59 case 'rp': |
| 71 return $this->handleRT($new, $current); | 60 return $this->handleRT($new, $current); |
| 72 case 'optgroup': | 61 case 'optgroup': |
| 73 return $this->closeIfCurrentMatches($new, $current, array( | 62 return $this->closeIfCurrentMatches($new, $current, array( |
| 74 'optgroup' | 63 'optgroup', |
| 75 )); | 64 )); |
| 76 case 'option': | 65 case 'option': |
| 77 return $this->closeIfCurrentMatches($new, $current, array( | 66 return $this->closeIfCurrentMatches($new, $current, array( |
| 78 'option', | 67 'option', |
| 79 )); | 68 )); |
| 80 case 'tr': | 69 case 'tr': |
| 81 return $this->closeIfCurrentMatches($new, $current, array( | 70 return $this->closeIfCurrentMatches($new, $current, array( |
| 82 'tr' | 71 'tr', |
| 83 )); | 72 )); |
| 84 case 'td': | 73 case 'td': |
| 85 case 'th': | 74 case 'th': |
| 86 return $this->closeIfCurrentMatches($new, $current, array( | 75 return $this->closeIfCurrentMatches($new, $current, array( |
| 87 'th', | 76 'th', |
| 88 'td' | 77 'td', |
| 89 )); | 78 )); |
| 90 case 'tbody': | 79 case 'tbody': |
| 91 case 'thead': | 80 case 'thead': |
| 92 case 'tfoot': | 81 case 'tfoot': |
| 93 case 'table': // Spec isn't explicit about this, but it's necessary. | 82 case 'table': // Spec isn't explicit about this, but it's necessary. |
| 94 | 83 |
| 95 return $this->closeIfCurrentMatches($new, $current, array( | 84 return $this->closeIfCurrentMatches($new, $current, array( |
| 96 'thead', | 85 'thead', |
| 97 'tfoot', | 86 'tfoot', |
| 98 'tbody' | 87 'tbody', |
| 99 )); | 88 )); |
| 100 } | 89 } |
| 101 | 90 |
| 102 return $current; | 91 return $current; |
| 103 } | 92 } |
| 104 | 93 |
| 105 protected function handleLI($ele, $current) | 94 protected function handleLI($ele, $current) |
| 106 { | 95 { |
| 107 return $this->closeIfCurrentMatches($ele, $current, array( | 96 return $this->closeIfCurrentMatches($ele, $current, array( |
| 108 'li' | 97 'li', |
| 109 )); | 98 )); |
| 110 } | 99 } |
| 111 | 100 |
| 112 protected function handleDT($ele, $current) | 101 protected function handleDT($ele, $current) |
| 113 { | 102 { |
| 114 return $this->closeIfCurrentMatches($ele, $current, array( | 103 return $this->closeIfCurrentMatches($ele, $current, array( |
| 115 'dt', | 104 'dt', |
| 116 'dd' | 105 'dd', |
| 117 )); | 106 )); |
| 118 } | 107 } |
| 119 | 108 |
| 120 protected function handleRT($ele, $current) | 109 protected function handleRT($ele, $current) |
| 121 { | 110 { |
| 122 return $this->closeIfCurrentMatches($ele, $current, array( | 111 return $this->closeIfCurrentMatches($ele, $current, array( |
| 123 'rt', | 112 'rt', |
| 124 'rp' | 113 'rp', |
| 125 )); | 114 )); |
| 126 } | 115 } |
| 127 | 116 |
| 128 protected function closeIfCurrentMatches($ele, $current, $match) | 117 protected function closeIfCurrentMatches($ele, $current, $match) |
| 129 { | 118 { |
| 130 $tname = $current->tagName; | 119 if (in_array($current->tagName, $match, true)) { |
| 131 if (in_array($current->tagName, $match)) { | |
| 132 $current->parentNode->appendChild($ele); | 120 $current->parentNode->appendChild($ele); |
| 133 } else { | 121 } else { |
| 134 $current->appendChild($ele); | 122 $current->appendChild($ele); |
| 135 } | 123 } |
| 136 | 124 |
