PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/html-purified/lib/HTMLPurifier/Lexer/PH5P.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 3904 lines | 1977 code | 614 blank | 1313 comment | 305 complexity | fe014dc9d00bc84352578e9183917d24 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Experimental HTML5-based parser using Jeroen van der Meer's PH5P library.
  4. * Occupies space in the HTML5 pseudo-namespace, which may cause conflicts.
  5. *
  6. * @note
  7. * Recent changes to PHP's DOM extension have resulted in some fatal
  8. * error conditions with the original version of PH5P. Pending changes,
  9. * this lexer will punt to DirectLex if DOM throughs an exception.
  10. */
  11. class HTMLPurifier_Lexer_PH5P extends HTMLPurifier_Lexer_DOMLex {
  12. public function tokenizeHTML($html, $config, $context) {
  13. $new_html = $this->normalize($html, $config, $context);
  14. $new_html = $this->wrapHTML($new_html, $config, $context);
  15. try {
  16. $parser = new HTML5($new_html);
  17. $doc = $parser->save();
  18. } catch (DOMException $e) {
  19. // Uh oh, it failed. Punt to DirectLex.
  20. $lexer = new HTMLPurifier_Lexer_DirectLex();
  21. $context->register('PH5PError', $e); // save the error, so we can detect it
  22. return $lexer->tokenizeHTML($html, $config, $context); // use original HTML
  23. }
  24. $tokens = array();
  25. $this->tokenizeDOM(
  26. $doc->getElementsByTagName('html')->item(0)-> // <html>
  27. getElementsByTagName('body')->item(0)-> // <body>
  28. getElementsByTagName('div')->item(0) // <div>
  29. , $tokens);
  30. return $tokens;
  31. }
  32. }
  33. /*
  34. Copyright 2007 Jeroen van der Meer <http://jero.net/>
  35. Permission is hereby granted, free of charge, to any person obtaining a
  36. copy of this software and associated documentation files (the
  37. "Software"), to deal in the Software without restriction, including
  38. without limitation the rights to use, copy, modify, merge, publish,
  39. distribute, sublicense, and/or sell copies of the Software, and to
  40. permit persons to whom the Software is furnished to do so, subject to
  41. the following conditions:
  42. The above copyright notice and this permission notice shall be included
  43. in all copies or substantial portions of the Software.
  44. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  45. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  46. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  47. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  48. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  49. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  50. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  51. */
  52. class HTML5 {
  53. private $data;
  54. private $char;
  55. private $EOF;
  56. private $state;
  57. private $tree;
  58. private $token;
  59. private $content_model;
  60. private $escape = false;
  61. private $entities = array('AElig;','AElig','AMP;','AMP','Aacute;','Aacute',
  62. 'Acirc;','Acirc','Agrave;','Agrave','Alpha;','Aring;','Aring','Atilde;',
  63. 'Atilde','Auml;','Auml','Beta;','COPY;','COPY','Ccedil;','Ccedil','Chi;',
  64. 'Dagger;','Delta;','ETH;','ETH','Eacute;','Eacute','Ecirc;','Ecirc','Egrave;',
  65. 'Egrave','Epsilon;','Eta;','Euml;','Euml','GT;','GT','Gamma;','Iacute;',
  66. 'Iacute','Icirc;','Icirc','Igrave;','Igrave','Iota;','Iuml;','Iuml','Kappa;',
  67. 'LT;','LT','Lambda;','Mu;','Ntilde;','Ntilde','Nu;','OElig;','Oacute;',
  68. 'Oacute','Ocirc;','Ocirc','Ograve;','Ograve','Omega;','Omicron;','Oslash;',
  69. 'Oslash','Otilde;','Otilde','Ouml;','Ouml','Phi;','Pi;','Prime;','Psi;',
  70. 'QUOT;','QUOT','REG;','REG','Rho;','Scaron;','Sigma;','THORN;','THORN',
  71. 'TRADE;','Tau;','Theta;','Uacute;','Uacute','Ucirc;','Ucirc','Ugrave;',
  72. 'Ugrave','Upsilon;','Uuml;','Uuml','Xi;','Yacute;','Yacute','Yuml;','Zeta;',
  73. 'aacute;','aacute','acirc;','acirc','acute;','acute','aelig;','aelig',
  74. 'agrave;','agrave','alefsym;','alpha;','amp;','amp','and;','ang;','apos;',
  75. 'aring;','aring','asymp;','atilde;','atilde','auml;','auml','bdquo;','beta;',
  76. 'brvbar;','brvbar','bull;','cap;','ccedil;','ccedil','cedil;','cedil',
  77. 'cent;','cent','chi;','circ;','clubs;','cong;','copy;','copy','crarr;',
  78. 'cup;','curren;','curren','dArr;','dagger;','darr;','deg;','deg','delta;',
  79. 'diams;','divide;','divide','eacute;','eacute','ecirc;','ecirc','egrave;',
  80. 'egrave','empty;','emsp;','ensp;','epsilon;','equiv;','eta;','eth;','eth',
  81. 'euml;','euml','euro;','exist;','fnof;','forall;','frac12;','frac12',
  82. 'frac14;','frac14','frac34;','frac34','frasl;','gamma;','ge;','gt;','gt',
  83. 'hArr;','harr;','hearts;','hellip;','iacute;','iacute','icirc;','icirc',
  84. 'iexcl;','iexcl','igrave;','igrave','image;','infin;','int;','iota;',
  85. 'iquest;','iquest','isin;','iuml;','iuml','kappa;','lArr;','lambda;','lang;',
  86. 'laquo;','laquo','larr;','lceil;','ldquo;','le;','lfloor;','lowast;','loz;',
  87. 'lrm;','lsaquo;','lsquo;','lt;','lt','macr;','macr','mdash;','micro;','micro',
  88. 'middot;','middot','minus;','mu;','nabla;','nbsp;','nbsp','ndash;','ne;',
  89. 'ni;','not;','not','notin;','nsub;','ntilde;','ntilde','nu;','oacute;',
  90. 'oacute','ocirc;','ocirc','oelig;','ograve;','ograve','oline;','omega;',
  91. 'omicron;','oplus;','or;','ordf;','ordf','ordm;','ordm','oslash;','oslash',
  92. 'otilde;','otilde','otimes;','ouml;','ouml','para;','para','part;','permil;',
  93. 'perp;','phi;','pi;','piv;','plusmn;','plusmn','pound;','pound','prime;',
  94. 'prod;','prop;','psi;','quot;','quot','rArr;','radic;','rang;','raquo;',
  95. 'raquo','rarr;','rceil;','rdquo;','real;','reg;','reg','rfloor;','rho;',
  96. 'rlm;','rsaquo;','rsquo;','sbquo;','scaron;','sdot;','sect;','sect','shy;',
  97. 'shy','sigma;','sigmaf;','sim;','spades;','sub;','sube;','sum;','sup1;',
  98. 'sup1','sup2;','sup2','sup3;','sup3','sup;','supe;','szlig;','szlig','tau;',
  99. 'there4;','theta;','thetasym;','thinsp;','thorn;','thorn','tilde;','times;',
  100. 'times','trade;','uArr;','uacute;','uacute','uarr;','ucirc;','ucirc',
  101. 'ugrave;','ugrave','uml;','uml','upsih;','upsilon;','uuml;','uuml','weierp;',
  102. 'xi;','yacute;','yacute','yen;','yen','yuml;','yuml','zeta;','zwj;','zwnj;');
  103. const PCDATA = 0;
  104. const RCDATA = 1;
  105. const CDATA = 2;
  106. const PLAINTEXT = 3;
  107. const DOCTYPE = 0;
  108. const STARTTAG = 1;
  109. const ENDTAG = 2;
  110. const COMMENT = 3;
  111. const CHARACTR = 4;
  112. const EOF = 5;
  113. public function __construct($data) {
  114. $this->data = $data;
  115. $this->char = -1;
  116. $this->EOF = strlen($data);
  117. $this->tree = new HTML5TreeConstructer;
  118. $this->content_model = self::PCDATA;
  119. $this->state = 'data';
  120. while($this->state !== null) {
  121. $this->{$this->state.'State'}();
  122. }
  123. }
  124. public function save() {
  125. return $this->tree->save();
  126. }
  127. private function char() {
  128. return ($this->char < $this->EOF)
  129. ? $this->data[$this->char]
  130. : false;
  131. }
  132. private function character($s, $l = 0) {
  133. if($s + $l < $this->EOF) {
  134. if($l === 0) {
  135. return $this->data[$s];
  136. } else {
  137. return substr($this->data, $s, $l);
  138. }
  139. }
  140. }
  141. private function characters($char_class, $start) {
  142. return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
  143. }
  144. private function dataState() {
  145. // Consume the next input character
  146. $this->char++;
  147. $char = $this->char();
  148. if($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
  149. /* U+0026 AMPERSAND (&)
  150. When the content model flag is set to one of the PCDATA or RCDATA
  151. states: switch to the entity data state. Otherwise: treat it as per
  152. the "anything else" entry below. */
  153. $this->state = 'entityData';
  154. } elseif($char === '-') {
  155. /* If the content model flag is set to either the RCDATA state or
  156. the CDATA state, and the escape flag is false, and there are at
  157. least three characters before this one in the input stream, and the
  158. last four characters in the input stream, including this one, are
  159. U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
  160. and U+002D HYPHEN-MINUS ("<!--"), then set the escape flag to true. */
  161. if(($this->content_model === self::RCDATA || $this->content_model ===
  162. self::CDATA) && $this->escape === false &&
  163. $this->char >= 3 && $this->character($this->char - 4, 4) === '<!--') {
  164. $this->escape = true;
  165. }
  166. /* In any case, emit the input character as a character token. Stay
  167. in the data state. */
  168. $this->emitToken(array(
  169. 'type' => self::CHARACTR,
  170. 'data' => $char
  171. ));
  172. /* U+003C LESS-THAN SIGN (<) */
  173. } elseif($char === '<' && ($this->content_model === self::PCDATA ||
  174. (($this->content_model === self::RCDATA ||
  175. $this->content_model === self::CDATA) && $this->escape === false))) {
  176. /* When the content model flag is set to the PCDATA state: switch
  177. to the tag open state.
  178. When the content model flag is set to either the RCDATA state or
  179. the CDATA state and the escape flag is false: switch to the tag
  180. open state.
  181. Otherwise: treat it as per the "anything else" entry below. */
  182. $this->state = 'tagOpen';
  183. /* U+003E GREATER-THAN SIGN (>) */
  184. } elseif($char === '>') {
  185. /* If the content model flag is set to either the RCDATA state or
  186. the CDATA state, and the escape flag is true, and the last three
  187. characters in the input stream including this one are U+002D
  188. HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"),
  189. set the escape flag to false. */
  190. if(($this->content_model === self::RCDATA ||
  191. $this->content_model === self::CDATA) && $this->escape === true &&
  192. $this->character($this->char, 3) === '-->') {
  193. $this->escape = false;
  194. }
  195. /* In any case, emit the input character as a character token.
  196. Stay in the data state. */
  197. $this->emitToken(array(
  198. 'type' => self::CHARACTR,
  199. 'data' => $char
  200. ));
  201. } elseif($this->char === $this->EOF) {
  202. /* EOF
  203. Emit an end-of-file token. */
  204. $this->EOF();
  205. } elseif($this->content_model === self::PLAINTEXT) {
  206. /* When the content model flag is set to the PLAINTEXT state
  207. THIS DIFFERS GREATLY FROM THE SPEC: Get the remaining characters of
  208. the text and emit it as a character token. */
  209. $this->emitToken(array(
  210. 'type' => self::CHARACTR,
  211. 'data' => substr($this->data, $this->char)
  212. ));
  213. $this->EOF();
  214. } else {
  215. /* Anything else
  216. THIS DIFFERS GREATLY FROM THE SPEC: Get as many character that
  217. otherwise would also be treated as a character token and emit it
  218. as a single character token. Stay in the data state. */
  219. $len = strcspn($this->data, '<&', $this->char);
  220. $char = substr($this->data, $this->char, $len);
  221. $this->char += $len - 1;
  222. $this->emitToken(array(
  223. 'type' => self::CHARACTR,
  224. 'data' => $char
  225. ));
  226. $this->state = 'data';
  227. }
  228. }
  229. private function entityDataState() {
  230. // Attempt to consume an entity.
  231. $entity = $this->entity();
  232. // If nothing is returned, emit a U+0026 AMPERSAND character token.
  233. // Otherwise, emit the character token that was returned.
  234. $char = (!$entity) ? '&' : $entity;
  235. $this->emitToken(array(
  236. 'type' => self::CHARACTR,
  237. 'data' => $char
  238. ));
  239. // Finally, switch to the data state.
  240. $this->state = 'data';
  241. }
  242. private function tagOpenState() {
  243. switch($this->content_model) {
  244. case self::RCDATA:
  245. case self::CDATA:
  246. /* If the next input character is a U+002F SOLIDUS (/) character,
  247. consume it and switch to the close tag open state. If the next
  248. input character is not a U+002F SOLIDUS (/) character, emit a
  249. U+003C LESS-THAN SIGN character token and switch to the data
  250. state to process the next input character. */
  251. if($this->character($this->char + 1) === '/') {
  252. $this->char++;
  253. $this->state = 'closeTagOpen';
  254. } else {
  255. $this->emitToken(array(
  256. 'type' => self::CHARACTR,
  257. 'data' => '<'
  258. ));
  259. $this->state = 'data';
  260. }
  261. break;
  262. case self::PCDATA:
  263. // If the content model flag is set to the PCDATA state
  264. // Consume the next input character:
  265. $this->char++;
  266. $char = $this->char();
  267. if($char === '!') {
  268. /* U+0021 EXCLAMATION MARK (!)
  269. Switch to the markup declaration open state. */
  270. $this->state = 'markupDeclarationOpen';
  271. } elseif($char === '/') {
  272. /* U+002F SOLIDUS (/)
  273. Switch to the close tag open state. */
  274. $this->state = 'closeTagOpen';
  275. } elseif(preg_match('/^[A-Za-z]$/', $char)) {
  276. /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
  277. Create a new start tag token, set its tag name to the lowercase
  278. version of the input character (add 0x0020 to the character's code
  279. point), then switch to the tag name state. (Don't emit the token
  280. yet; further details will be filled in before it is emitted.) */
  281. $this->token = array(
  282. 'name' => strtolower($char),
  283. 'type' => self::STARTTAG,
  284. 'attr' => array()
  285. );
  286. $this->state = 'tagName';
  287. } elseif($char === '>') {
  288. /* U+003E GREATER-THAN SIGN (>)
  289. Parse error. Emit a U+003C LESS-THAN SIGN character token and a
  290. U+003E GREATER-THAN SIGN character token. Switch to the data state. */
  291. $this->emitToken(array(
  292. 'type' => self::CHARACTR,
  293. 'data' => '<>'
  294. ));
  295. $this->state = 'data';
  296. } elseif($char === '?') {
  297. /* U+003F QUESTION MARK (?)
  298. Parse error. Switch to the bogus comment state. */
  299. $this->state = 'bogusComment';
  300. } else {
  301. /* Anything else
  302. Parse error. Emit a U+003C LESS-THAN SIGN character token and
  303. reconsume the current input character in the data state. */
  304. $this->emitToken(array(
  305. 'type' => self::CHARACTR,
  306. 'data' => '<'
  307. ));
  308. $this->char--;
  309. $this->state = 'data';
  310. }
  311. break;
  312. }
  313. }
  314. private function closeTagOpenState() {
  315. $next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
  316. $the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
  317. if(($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
  318. (!$the_same || ($the_same && (!preg_match('/[\t\n\x0b\x0c >\/]/',
  319. $this->character($this->char + 1 + strlen($next_node))) || $this->EOF === $this->char)))) {
  320. /* If the content model flag is set to the RCDATA or CDATA states then
  321. examine the next few characters. If they do not match the tag name of
  322. the last start tag token emitted (case insensitively), or if they do but
  323. they are not immediately followed by one of the following characters:
  324. * U+0009 CHARACTER TABULATION
  325. * U+000A LINE FEED (LF)
  326. * U+000B LINE TABULATION
  327. * U+000C FORM FEED (FF)
  328. * U+0020 SPACE
  329. * U+003E GREATER-THAN SIGN (>)
  330. * U+002F SOLIDUS (/)
  331. * EOF
  332. ...then there is a parse error. Emit a U+003C LESS-THAN SIGN character
  333. token, a U+002F SOLIDUS character token, and switch to the data state
  334. to process the next input character. */
  335. $this->emitToken(array(
  336. 'type' => self::CHARACTR,
  337. 'data' => '</'
  338. ));
  339. $this->state = 'data';
  340. } else {
  341. /* Otherwise, if the content model flag is set to the PCDATA state,
  342. or if the next few characters do match that tag name, consume the
  343. next input character: */
  344. $this->char++;
  345. $char = $this->char();
  346. if(preg_match('/^[A-Za-z]$/', $char)) {
  347. /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
  348. Create a new end tag token, set its tag name to the lowercase version
  349. of the input character (add 0x0020 to the character's code point), then
  350. switch to the tag name state. (Don't emit the token yet; further details
  351. will be filled in before it is emitted.) */
  352. $this->token = array(
  353. 'name' => strtolower($char),
  354. 'type' => self::ENDTAG
  355. );
  356. $this->state = 'tagName';
  357. } elseif($char === '>') {
  358. /* U+003E GREATER-THAN SIGN (>)
  359. Parse error. Switch to the data state. */
  360. $this->state = 'data';
  361. } elseif($this->char === $this->EOF) {
  362. /* EOF
  363. Parse error. Emit a U+003C LESS-THAN SIGN character token and a U+002F
  364. SOLIDUS character token. Reconsume the EOF character in the data state. */
  365. $this->emitToken(array(
  366. 'type' => self::CHARACTR,
  367. 'data' => '</'
  368. ));
  369. $this->char--;
  370. $this->state = 'data';
  371. } else {
  372. /* Parse error. Switch to the bogus comment state. */
  373. $this->state = 'bogusComment';
  374. }
  375. }
  376. }
  377. private function tagNameState() {
  378. // Consume the next input character:
  379. $this->char++;
  380. $char = $this->character($this->char);
  381. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  382. /* U+0009 CHARACTER TABULATION
  383. U+000A LINE FEED (LF)
  384. U+000B LINE TABULATION
  385. U+000C FORM FEED (FF)
  386. U+0020 SPACE
  387. Switch to the before attribute name state. */
  388. $this->state = 'beforeAttributeName';
  389. } elseif($char === '>') {
  390. /* U+003E GREATER-THAN SIGN (>)
  391. Emit the current tag token. Switch to the data state. */
  392. $this->emitToken($this->token);
  393. $this->state = 'data';
  394. } elseif($this->char === $this->EOF) {
  395. /* EOF
  396. Parse error. Emit the current tag token. Reconsume the EOF
  397. character in the data state. */
  398. $this->emitToken($this->token);
  399. $this->char--;
  400. $this->state = 'data';
  401. } elseif($char === '/') {
  402. /* U+002F SOLIDUS (/)
  403. Parse error unless this is a permitted slash. Switch to the before
  404. attribute name state. */
  405. $this->state = 'beforeAttributeName';
  406. } else {
  407. /* Anything else
  408. Append the current input character to the current tag token's tag name.
  409. Stay in the tag name state. */
  410. $this->token['name'] .= strtolower($char);
  411. $this->state = 'tagName';
  412. }
  413. }
  414. private function beforeAttributeNameState() {
  415. // Consume the next input character:
  416. $this->char++;
  417. $char = $this->character($this->char);
  418. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  419. /* U+0009 CHARACTER TABULATION
  420. U+000A LINE FEED (LF)
  421. U+000B LINE TABULATION
  422. U+000C FORM FEED (FF)
  423. U+0020 SPACE
  424. Stay in the before attribute name state. */
  425. $this->state = 'beforeAttributeName';
  426. } elseif($char === '>') {
  427. /* U+003E GREATER-THAN SIGN (>)
  428. Emit the current tag token. Switch to the data state. */
  429. $this->emitToken($this->token);
  430. $this->state = 'data';
  431. } elseif($char === '/') {
  432. /* U+002F SOLIDUS (/)
  433. Parse error unless this is a permitted slash. Stay in the before
  434. attribute name state. */
  435. $this->state = 'beforeAttributeName';
  436. } elseif($this->char === $this->EOF) {
  437. /* EOF
  438. Parse error. Emit the current tag token. Reconsume the EOF
  439. character in the data state. */
  440. $this->emitToken($this->token);
  441. $this->char--;
  442. $this->state = 'data';
  443. } else {
  444. /* Anything else
  445. Start a new attribute in the current tag token. Set that attribute's
  446. name to the current input character, and its value to the empty string.
  447. Switch to the attribute name state. */
  448. $this->token['attr'][] = array(
  449. 'name' => strtolower($char),
  450. 'value' => null
  451. );
  452. $this->state = 'attributeName';
  453. }
  454. }
  455. private function attributeNameState() {
  456. // Consume the next input character:
  457. $this->char++;
  458. $char = $this->character($this->char);
  459. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  460. /* U+0009 CHARACTER TABULATION
  461. U+000A LINE FEED (LF)
  462. U+000B LINE TABULATION
  463. U+000C FORM FEED (FF)
  464. U+0020 SPACE
  465. Stay in the before attribute name state. */
  466. $this->state = 'afterAttributeName';
  467. } elseif($char === '=') {
  468. /* U+003D EQUALS SIGN (=)
  469. Switch to the before attribute value state. */
  470. $this->state = 'beforeAttributeValue';
  471. } elseif($char === '>') {
  472. /* U+003E GREATER-THAN SIGN (>)
  473. Emit the current tag token. Switch to the data state. */
  474. $this->emitToken($this->token);
  475. $this->state = 'data';
  476. } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
  477. /* U+002F SOLIDUS (/)
  478. Parse error unless this is a permitted slash. Switch to the before
  479. attribute name state. */
  480. $this->state = 'beforeAttributeName';
  481. } elseif($this->char === $this->EOF) {
  482. /* EOF
  483. Parse error. Emit the current tag token. Reconsume the EOF
  484. character in the data state. */
  485. $this->emitToken($this->token);
  486. $this->char--;
  487. $this->state = 'data';
  488. } else {
  489. /* Anything else
  490. Append the current input character to the current attribute's name.
  491. Stay in the attribute name state. */
  492. $last = count($this->token['attr']) - 1;
  493. $this->token['attr'][$last]['name'] .= strtolower($char);
  494. $this->state = 'attributeName';
  495. }
  496. }
  497. private function afterAttributeNameState() {
  498. // Consume the next input character:
  499. $this->char++;
  500. $char = $this->character($this->char);
  501. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  502. /* U+0009 CHARACTER TABULATION
  503. U+000A LINE FEED (LF)
  504. U+000B LINE TABULATION
  505. U+000C FORM FEED (FF)
  506. U+0020 SPACE
  507. Stay in the after attribute name state. */
  508. $this->state = 'afterAttributeName';
  509. } elseif($char === '=') {
  510. /* U+003D EQUALS SIGN (=)
  511. Switch to the before attribute value state. */
  512. $this->state = 'beforeAttributeValue';
  513. } elseif($char === '>') {
  514. /* U+003E GREATER-THAN SIGN (>)
  515. Emit the current tag token. Switch to the data state. */
  516. $this->emitToken($this->token);
  517. $this->state = 'data';
  518. } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
  519. /* U+002F SOLIDUS (/)
  520. Parse error unless this is a permitted slash. Switch to the
  521. before attribute name state. */
  522. $this->state = 'beforeAttributeName';
  523. } elseif($this->char === $this->EOF) {
  524. /* EOF
  525. Parse error. Emit the current tag token. Reconsume the EOF
  526. character in the data state. */
  527. $this->emitToken($this->token);
  528. $this->char--;
  529. $this->state = 'data';
  530. } else {
  531. /* Anything else
  532. Start a new attribute in the current tag token. Set that attribute's
  533. name to the current input character, and its value to the empty string.
  534. Switch to the attribute name state. */
  535. $this->token['attr'][] = array(
  536. 'name' => strtolower($char),
  537. 'value' => null
  538. );
  539. $this->state = 'attributeName';
  540. }
  541. }
  542. private function beforeAttributeValueState() {
  543. // Consume the next input character:
  544. $this->char++;
  545. $char = $this->character($this->char);
  546. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  547. /* U+0009 CHARACTER TABULATION
  548. U+000A LINE FEED (LF)
  549. U+000B LINE TABULATION
  550. U+000C FORM FEED (FF)
  551. U+0020 SPACE
  552. Stay in the before attribute value state. */
  553. $this->state = 'beforeAttributeValue';
  554. } elseif($char === '"') {
  555. /* U+0022 QUOTATION MARK (")
  556. Switch to the attribute value (double-quoted) state. */
  557. $this->state = 'attributeValueDoubleQuoted';
  558. } elseif($char === '&') {
  559. /* U+0026 AMPERSAND (&)
  560. Switch to the attribute value (unquoted) state and reconsume
  561. this input character. */
  562. $this->char--;
  563. $this->state = 'attributeValueUnquoted';
  564. } elseif($char === '\'') {
  565. /* U+0027 APOSTROPHE (')
  566. Switch to the attribute value (single-quoted) state. */
  567. $this->state = 'attributeValueSingleQuoted';
  568. } elseif($char === '>') {
  569. /* U+003E GREATER-THAN SIGN (>)
  570. Emit the current tag token. Switch to the data state. */
  571. $this->emitToken($this->token);
  572. $this->state = 'data';
  573. } else {
  574. /* Anything else
  575. Append the current input character to the current attribute's value.
  576. Switch to the attribute value (unquoted) state. */
  577. $last = count($this->token['attr']) - 1;
  578. $this->token['attr'][$last]['value'] .= $char;
  579. $this->state = 'attributeValueUnquoted';
  580. }
  581. }
  582. private function attributeValueDoubleQuotedState() {
  583. // Consume the next input character:
  584. $this->char++;
  585. $char = $this->character($this->char);
  586. if($char === '"') {
  587. /* U+0022 QUOTATION MARK (")
  588. Switch to the before attribute name state. */
  589. $this->state = 'beforeAttributeName';
  590. } elseif($char === '&') {
  591. /* U+0026 AMPERSAND (&)
  592. Switch to the entity in attribute value state. */
  593. $this->entityInAttributeValueState('double');
  594. } elseif($this->char === $this->EOF) {
  595. /* EOF
  596. Parse error. Emit the current tag token. Reconsume the character
  597. in the data state. */
  598. $this->emitToken($this->token);
  599. $this->char--;
  600. $this->state = 'data';
  601. } else {
  602. /* Anything else
  603. Append the current input character to the current attribute's value.
  604. Stay in the attribute value (double-quoted) state. */
  605. $last = count($this->token['attr']) - 1;
  606. $this->token['attr'][$last]['value'] .= $char;
  607. $this->state = 'attributeValueDoubleQuoted';
  608. }
  609. }
  610. private function attributeValueSingleQuotedState() {
  611. // Consume the next input character:
  612. $this->char++;
  613. $char = $this->character($this->char);
  614. if($char === '\'') {
  615. /* U+0022 QUOTATION MARK (')
  616. Switch to the before attribute name state. */
  617. $this->state = 'beforeAttributeName';
  618. } elseif($char === '&') {
  619. /* U+0026 AMPERSAND (&)
  620. Switch to the entity in attribute value state. */
  621. $this->entityInAttributeValueState('single');
  622. } elseif($this->char === $this->EOF) {
  623. /* EOF
  624. Parse error. Emit the current tag token. Reconsume the character
  625. in the data state. */
  626. $this->emitToken($this->token);
  627. $this->char--;
  628. $this->state = 'data';
  629. } else {
  630. /* Anything else
  631. Append the current input character to the current attribute's value.
  632. Stay in the attribute value (single-quoted) state. */
  633. $last = count($this->token['attr']) - 1;
  634. $this->token['attr'][$last]['value'] .= $char;
  635. $this->state = 'attributeValueSingleQuoted';
  636. }
  637. }
  638. private function attributeValueUnquotedState() {
  639. // Consume the next input character:
  640. $this->char++;
  641. $char = $this->character($this->char);
  642. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  643. /* U+0009 CHARACTER TABULATION
  644. U+000A LINE FEED (LF)
  645. U+000B LINE TABULATION
  646. U+000C FORM FEED (FF)
  647. U+0020 SPACE
  648. Switch to the before attribute name state. */
  649. $this->state = 'beforeAttributeName';
  650. } elseif($char === '&') {
  651. /* U+0026 AMPERSAND (&)
  652. Switch to the entity in attribute value state. */
  653. $this->entityInAttributeValueState();
  654. } elseif($char === '>') {
  655. /* U+003E GREATER-THAN SIGN (>)
  656. Emit the current tag token. Switch to the data state. */
  657. $this->emitToken($this->token);
  658. $this->state = 'data';
  659. } else {
  660. /* Anything else
  661. Append the current input character to the current attribute's value.
  662. Stay in the attribute value (unquoted) state. */
  663. $last = count($this->token['attr']) - 1;
  664. $this->token['attr'][$last]['value'] .= $char;
  665. $this->state = 'attributeValueUnquoted';
  666. }
  667. }
  668. private function entityInAttributeValueState() {
  669. // Attempt to consume an entity.
  670. $entity = $this->entity();
  671. // If nothing is returned, append a U+0026 AMPERSAND character to the
  672. // current attribute's value. Otherwise, emit the character token that
  673. // was returned.
  674. $char = (!$entity)
  675. ? '&'
  676. : $entity;
  677. $last = count($this->token['attr']) - 1;
  678. $this->token['attr'][$last]['value'] .= $char;
  679. }
  680. private function bogusCommentState() {
  681. /* Consume every character up to the first U+003E GREATER-THAN SIGN
  682. character (>) or the end of the file (EOF), whichever comes first. Emit
  683. a comment token whose data is the concatenation of all the characters
  684. starting from and including the character that caused the state machine
  685. to switch into the bogus comment state, up to and including the last
  686. consumed character before the U+003E character, if any, or up to the
  687. end of the file otherwise. (If the comment was started by the end of
  688. the file (EOF), the token is empty.) */
  689. $data = $this->characters('^>', $this->char);
  690. $this->emitToken(array(
  691. 'data' => $data,
  692. 'type' => self::COMMENT
  693. ));
  694. $this->char += strlen($data);
  695. /* Switch to the data state. */
  696. $this->state = 'data';
  697. /* If the end of the file was reached, reconsume the EOF character. */
  698. if($this->char === $this->EOF) {
  699. $this->char = $this->EOF - 1;
  700. }
  701. }
  702. private function markupDeclarationOpenState() {
  703. /* If the next two characters are both U+002D HYPHEN-MINUS (-)
  704. characters, consume those two characters, create a comment token whose
  705. data is the empty string, and switch to the comment state. */
  706. if($this->character($this->char + 1, 2) === '--') {
  707. $this->char += 2;
  708. $this->state = 'comment';
  709. $this->token = array(
  710. 'data' => null,
  711. 'type' => self::COMMENT
  712. );
  713. /* Otherwise if the next seven chacacters are a case-insensitive match
  714. for the word "DOCTYPE", then consume those characters and switch to the
  715. DOCTYPE state. */
  716. } elseif(strtolower($this->character($this->char + 1, 7)) === 'doctype') {
  717. $this->char += 7;
  718. $this->state = 'doctype';
  719. /* Otherwise, is is a parse error. Switch to the bogus comment state.
  720. The next character that is consumed, if any, is the first character
  721. that will be in the comment. */
  722. } else {
  723. $this->char++;
  724. $this->state = 'bogusComment';
  725. }
  726. }
  727. private function commentState() {
  728. /* Consume the next input character: */
  729. $this->char++;
  730. $char = $this->char();
  731. /* U+002D HYPHEN-MINUS (-) */
  732. if($char === '-') {
  733. /* Switch to the comment dash state */
  734. $this->state = 'commentDash';
  735. /* EOF */
  736. } elseif($this->char === $this->EOF) {
  737. /* Parse error. Emit the comment token. Reconsume the EOF character
  738. in the data state. */
  739. $this->emitToken($this->token);
  740. $this->char--;
  741. $this->state = 'data';
  742. /* Anything else */
  743. } else {
  744. /* Append the input character to the comment token's data. Stay in
  745. the comment state. */
  746. $this->token['data'] .= $char;
  747. }
  748. }
  749. private function commentDashState() {
  750. /* Consume the next input character: */
  751. $this->char++;
  752. $char = $this->char();
  753. /* U+002D HYPHEN-MINUS (-) */
  754. if($char === '-') {
  755. /* Switch to the comment end state */
  756. $this->state = 'commentEnd';
  757. /* EOF */
  758. } elseif($this->char === $this->EOF) {
  759. /* Parse error. Emit the comment token. Reconsume the EOF character
  760. in the data state. */
  761. $this->emitToken($this->token);
  762. $this->char--;
  763. $this->state = 'data';
  764. /* Anything else */
  765. } else {
  766. /* Append a U+002D HYPHEN-MINUS (-) character and the input
  767. character to the comment token's data. Switch to the comment state. */
  768. $this->token['data'] .= '-'.$char;
  769. $this->state = 'comment';
  770. }
  771. }
  772. private function commentEndState() {
  773. /* Consume the next input character: */
  774. $this->char++;
  775. $char = $this->char();
  776. if($char === '>') {
  777. $this->emitToken($this->token);
  778. $this->state = 'data';
  779. } elseif($char === '-') {
  780. $this->token['data'] .= '-';
  781. } elseif($this->char === $this->EOF) {
  782. $this->emitToken($this->token);
  783. $this->char--;
  784. $this->state = 'data';
  785. } else {
  786. $this->token['data'] .= '--'.$char;
  787. $this->state = 'comment';
  788. }
  789. }
  790. private function doctypeState() {
  791. /* Consume the next input character: */
  792. $this->char++;
  793. $char = $this->char();
  794. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  795. $this->state = 'beforeDoctypeName';
  796. } else {
  797. $this->char--;
  798. $this->state = 'beforeDoctypeName';
  799. }
  800. }
  801. private function beforeDoctypeNameState() {
  802. /* Consume the next input character: */
  803. $this->char++;
  804. $char = $this->char();
  805. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  806. // Stay in the before DOCTYPE name state.
  807. } elseif(preg_match('/^[a-z]$/', $char)) {
  808. $this->token = array(
  809. 'name' => strtoupper($char),
  810. 'type' => self::DOCTYPE,
  811. 'error' => true
  812. );
  813. $this->state = 'doctypeName';
  814. } elseif($char === '>') {
  815. $this->emitToken(array(
  816. 'name' => null,
  817. 'type' => self::DOCTYPE,
  818. 'error' => true
  819. ));
  820. $this->state = 'data';
  821. } elseif($this->char === $this->EOF) {
  822. $this->emitToken(array(
  823. 'name' => null,
  824. 'type' => self::DOCTYPE,
  825. 'error' => true
  826. ));
  827. $this->char--;
  828. $this->state = 'data';
  829. } else {
  830. $this->token = array(
  831. 'name' => $char,
  832. 'type' => self::DOCTYPE,
  833. 'error' => true
  834. );
  835. $this->state = 'doctypeName';
  836. }
  837. }
  838. private function doctypeNameState() {
  839. /* Consume the next input character: */
  840. $this->char++;
  841. $char = $this->char();
  842. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  843. $this->state = 'AfterDoctypeName';
  844. } elseif($char === '>') {
  845. $this->emitToken($this->token);
  846. $this->state = 'data';
  847. } elseif(preg_match('/^[a-z]$/', $char)) {
  848. $this->token['name'] .= strtoupper($char);
  849. } elseif($this->char === $this->EOF) {
  850. $this->emitToken($this->token);
  851. $this->char--;
  852. $this->state = 'data';
  853. } else {
  854. $this->token['name'] .= $char;
  855. }
  856. $this->token['error'] = ($this->token['name'] === 'HTML')
  857. ? false
  858. : true;
  859. }
  860. private function afterDoctypeNameState() {
  861. /* Consume the next input character: */
  862. $this->char++;
  863. $char = $this->char();
  864. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  865. // Stay in the DOCTYPE name state.
  866. } elseif($char === '>') {
  867. $this->emitToken($this->token);
  868. $this->state = 'data';
  869. } elseif($this->char === $this->EOF) {
  870. $this->emitToken($this->token);
  871. $this->char--;
  872. $this->state = 'data';
  873. } else {
  874. $this->token['error'] = true;
  875. $this->state = 'bogusDoctype';
  876. }
  877. }
  878. private function bogusDoctypeState() {
  879. /* Consume the next input character: */
  880. $this->char++;
  881. $char = $this->char();
  882. if($char === '>') {
  883. $this->emitToken($this->token);
  884. $this->state = 'data';
  885. } elseif($this->char === $this->EOF) {
  886. $this->emitToken($this->token);
  887. $this->char--;
  888. $this->state = 'data';
  889. } else {
  890. // Stay in the bogus DOCTYPE state.
  891. }
  892. }
  893. private function entity() {
  894. $start = $this->char;
  895. // This section defines how to consume an entity. This definition is
  896. // used when parsing entities in text and in attributes.
  897. // The behaviour depends on the identity of the next character (the
  898. // one immediately after the U+0026 AMPERSAND character):
  899. switch($this->character($this->char + 1)) {
  900. // U+0023 NUMBER SIGN (#)
  901. case '#':
  902. // The behaviour further depends on the character after the
  903. // U+0023 NUMBER SIGN:
  904. switch($this->character($this->char + 1)) {
  905. // U+0078 LATIN SMALL LETTER X
  906. // U+0058 LATIN CAPITAL LETTER X
  907. case 'x':
  908. case 'X':
  909. // Follow the steps below, but using the range of
  910. // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
  911. // NINE, U+0061 LATIN SMALL LETTER A through to U+0066
  912. // LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
  913. // A, through to U+0046 LATIN CAPITAL LETTER F (in other
  914. // words, 0-9, A-F, a-f).
  915. $char = 1;
  916. $char_class = '0-9A-Fa-f';
  917. break;
  918. // Anything else
  919. default:
  920. // Follow the steps below, but using the range of
  921. // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
  922. // NINE (i.e. just 0-9).
  923. $char = 0;
  924. $char_class = '0-9';
  925. break;
  926. }
  927. // Consume as many characters as match the range of characters
  928. // given above.
  929. $this->char++;
  930. $e_name = $this->characters($char_class, $this->char + $char + 1);
  931. $entity = $this->character($start, $this->char);
  932. $cond = strlen($e_name) > 0;
  933. // The rest of the parsing happens bellow.
  934. break;
  935. // Anything else
  936. default:
  937. // Consume the maximum number of characters possible, with the
  938. // consumed characters case-sensitively matching one of the
  939. // identifiers in the first column of the entities table.
  940. $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
  941. $len = strlen($e_name);
  942. for($c = 1; $c <= $len; $c++) {
  943. $id = substr($e_name, 0, $c);
  944. $this->char++;
  945. if(in_array($id, $this->entities)) {
  946. if ($e_name[$c-1] !== ';') {
  947. if ($c < $len && $e_name[$c] == ';') {
  948. $this->char++; // consume extra semicolon
  949. }
  950. }
  951. $entity = $id;
  952. break;
  953. }
  954. }
  955. $cond = isset($entity);
  956. // The rest of the parsing happens bellow.
  957. break;
  958. }
  959. if(!$cond) {
  960. // If no match can be made, then this is a parse error. No
  961. // characters are consumed, and nothing is returned.
  962. $this->char = $start;
  963. return false;
  964. }
  965. // Return a character token for the character corresponding to the
  966. // entity name (as given by the second column of the entities table).
  967. return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8');
  968. }
  969. private function emitToken($token) {
  970. $emit = $this->tree->emitToken($token);
  971. if(is_int($emit)) {
  972. $this->content_model = $emit;
  973. } elseif($token['type'] === self::ENDTAG) {
  974. $this->content_model = self::PCDATA;
  975. }
  976. }
  977. private function EOF() {
  978. $this->state = null;
  979. $this->tree->emitToken(array(
  980. 'type' => self::EOF
  981. ));
  982. }
  983. }
  984. class HTML5TreeConstructer {
  985. public $stack = array();
  986. private $phase;
  987. private $mode;
  988. private $dom;
  989. private $foster_parent = null;
  990. private $a_formatting = array();
  991. private $head_pointer = null;
  992. private $form_pointer = null;
  993. private $scoping = array('button','caption','html','marquee','object','table','td','th');
  994. private $formatting = array('a','b','big','em','font','i','nobr','s','small','strike','strong','tt','u');
  995. private $special = array('address','area','base','basefont','bgsound',
  996. 'blockquote','body','br','center','col','colgroup','dd','dir','div','dl',
  997. 'dt','embed','fieldset','form','frame','frameset','h1','h2','h3','h4','h5',
  998. 'h6','head','hr','iframe','image','img','input','isindex','li','link',
  999. 'listing','menu','meta','noembed','noframes','noscript','ol','optgroup',
  1000. 'option','p','param','plaintext','pre','script','select','spacer','style',
  1001. 'tbody','textarea','tfoot','thead','title','tr','ul','wbr');
  1002. // The different phases.
  1003. const INIT_PHASE = 0;
  1004. const ROOT_PHASE = 1;
  1005. const MAIN_PHASE = 2;
  1006. const END_PHASE = 3;
  1007. // The different insertion modes for the main phase.
  1008. const BEFOR_HEAD = 0;
  1009. const IN_HEAD = 1;
  1010. const AFTER_HEAD = 2;
  1011. const IN_BODY = 3;
  1012. const IN_TABLE = 4;
  1013. const IN_CAPTION = 5;
  1014. const IN_CGROUP = 6;
  1015. const IN_TBODY = 7;
  1016. const IN_ROW = 8;
  1017. const IN_CELL = 9;
  1018. const IN_SELECT = 10;
  1019. const AFTER_BODY = 11;
  1020. const IN_FRAME = 12;
  1021. const AFTR_FRAME = 13;
  1022. // The different types of elements.
  1023. const SPECIAL = 0;
  1024. const SCOPING = 1;
  1025. const FORMATTING = 2;
  1026. const PHRASING = 3;
  1027. const MARKER = 0;
  1028. public function __construct() {
  1029. $this->phase = self::INIT_PHASE;
  1030. $this->mode = self::BEFOR_HEAD;
  1031. $this->dom = new DOMDocument;
  1032. $this->dom->encoding = 'UTF-8';
  1033. $this->dom->preserveWhiteSpace = true;
  1034. $this->dom->substituteEntities = true;
  1035. $this->dom->strictErrorChecking = false;
  1036. }
  1037. // Process tag tokens
  1038. public function emitToken($token) {
  1039. switch($this->phase) {
  1040. case self::INIT_PHASE: return $this->initPhase($token); break;
  1041. case self::ROOT_PHASE: return $this->rootElementPhase($token); break;
  1042. case self::MAIN_PHASE: return $this->mainPhase($token); break;
  1043. case self::END_PHASE : return $this->trailingEndPhase($token); break;
  1044. }
  1045. }
  1046. private function initPhase($token) {
  1047. /* Initially, the tree construction stage must handle each token
  1048. emitted from the tokenisation stage as follows: */
  1049. /* A DOCTYPE token that is marked as being in error
  1050. A comment token
  1051. A start tag token
  1052. An end tag token
  1053. A character token that is not one of one of U+0009 CHARACTER TABULATION,
  1054. U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  1055. or U+0020 SPACE
  1056. An end-of-file token */
  1057. if((isset($token['error']) && $token['error']) ||
  1058. $token['type'] === HTML5::COMMENT ||
  1059. $token['type'] === HTML5::STARTTAG ||
  1060. $token['type'] === HTML5::ENDTAG ||
  1061. $token['type'] === HTML5::EOF ||
  1062. ($token['type'] === HTML5::CHARACTR && isset($token['data']) &&
  1063. !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']))) {
  1064. /* This specification does not define how to handle this case. In
  1065. particular, user agents may ignore the entirety of this specification
  1066. altogether for such documents, and instead invoke special parse modes
  1067. with a greater emphasis on backwards compatibility. */
  1068. $this->phase = self::ROOT_PHASE;
  1069. return $this->rootElementPhase($token);
  1070. /* A DOCTYPE token marked as being correct */
  1071. } elseif(isset($token['error']) && !$token['error']) {
  1072. /* Append a DocumentType node to the Document node, with the name
  1073. attribute set to the name given in the DOCTYPE token (which will be
  1074. "HTML"), and the other attributes specific to DocumentType objects
  1075. set to null, empty lists, or the empty string as appropriate. */
  1076. $doctype = new DOMDocumentType(null, null, 'HTML');
  1077. /* Then, switch to the root element phase of the tree construction
  1078. stage. */
  1079. $this->phase = self::ROOT_PHASE;
  1080. /* A character token that is one of one of U+0009 CHARACTER TABULATION,
  1081. U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  1082. or U+0020 SPACE */
  1083. } elseif(isset($token['data']) && preg_match('/^[\t\n\x0b\x0c ]+$/',
  1084. $token['data'])) {
  1085. /* Append that character to the Document node. */
  1086. $text = $this->dom->createTextNode($token['data']);
  1087. $this->dom->appendChild($text);
  1088. }
  1089. }
  1090. private function rootElementPhase($token) {
  1091. /* After the initial phase, as each token is emitted from the tokenisation
  1092. stage, it must be processed as described in this section. */
  1093. /* A DOCTYPE token */
  1094. if($token['type'] === HTML5::DOCTYPE) {
  1095. // Parse error. Ignore the token.
  1096. /* A comment token */
  1097. } elseif($token['type'] === HTML5::COMMENT) {
  1098. /* Append a Comment node to the Document object with the data
  1099. attribute set to the data given in the comment token. */
  1100. $comment = $this->dom->createComment($token['data']);
  1101. $this->dom->appendChild($comment);
  1102. /* A character token that is one of one of U+0009 CHARACTER TABULATION,
  1103. U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  1104. or U+0020 SPACE */
  1105. } elseif($token['type'] === HTML5::CHARACTR &&
  1106. preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
  1107. /* Append that character to the Document node. */
  1108. $text = $this->dom->createTextNode($token['data…

Large files files are truncated, but you can click here to view the full file