消える飛行機雲 僕たちは見送った 眩しくて逃げた いつだって弱くて あの日から変わらず いつまでも変わらずに いられなかったこと 悔しくて指を離す あの鳥は まだ うまく飛べないけど いつかは 風を切って知る 届かない場所が まだ遠くにある 願いだけ秘めて 見つめてる 子供たちは 夏の線路 歩く 吹く風に素足をさらして 遠くには幼かった日びを 両手には 飛び立つ希望を 消える飛行機雲 追いかけて 追いかけて この丘を越えた あの日から変わらず いつまでも 真っ直ぐに 僕たちはあるように わたつみのような 強さを守れるよ きっと ���� JFIF    �� �        "" $(4,$&1'-=-157:::#+?D?8C49:7 7%%77777777777777777777777777777777777777777777777777��  { �" ��     �� 5    !1AQa"q�2��BR��#b�������  ��  ��   ? ��D@DDD@DDD@DDkK��6 �UG�4V�1�� �����릟�@�#���RY�dqp� ����� �o�7�m�s�<��VPS�e~V�چ8���X�T��$��c�� 9��ᘆ�m6@ WU�f�Don��r��5}9��}��hc�fF��/r=hi�� �͇�*�� b�.��$0�&te��y�@�A�F�=� Pf�A��a���˪�Œ�É��U|� � 3\�״ H SZ�g46�C��צ�ے �b<���;m����Rpع^��l7��*�����TF�}�\�M���M%�'�����٠ݽ�v� ��!-�����?�N!La��A+[`#���M����'�~oR�?��v^)��=��h����A��X�.���˃����^Ə��ܯsO"B�c>; �e�4��5�k��/CB��.  �J?��;�҈�������������������~�<�VZ�ꭼ2/)Í”jC���ע�V�G�!���!�F������\�� Kj�R�oc�h���:Þ I��1"2�q×°8��Р@ז���_C0�ր��A��lQ��@纼�!7��F�� �]�sZ B�62r�v�z~�K�7�c��5�.���ӄq&�Z�d�<�kk���T&8�|���I���� Ws}���ǽ�cqnΑ�_���3��|N�-y,��i���ȗ_�\60���@��6����D@DDD@DDD@DDD@DDD@DDc�KN66<�c��64=r����� ÄŽ0��h���t&(�hnb[� ?��^��\��â|�,�/h�\��R��5�? �0�!צ܉-����G����٬��Q�zA���1�����V��� �:R���`�$��ik��H����D4�����#dk����� h�}����7���w%�������*o8wG�LycuT�.���ܯ7��I��u^���)��/c�,s�Nq�ۺ�;�ך�YH2���.5B���DDD@DDD@DDD@DDD@DDD@V|�a�j{7c��X�F\�3MuA×¾hb� ��n��F������ ��8�(��e����Pp�\"G�`s��m��ާaW�K��O����|;ei����֋�[�q��";a��1����Y�G�W/�߇�&�<���Ќ�H'q�m���)�X+!���=�m�ۚ丷~6a^X�)���,�>#&6G���Y��{����"" """ """ """ """ ""��at\/�a�8 �yp%�lhl�n����)���i�t��B�������������?��modskinlienminh.com - WSOX ENC ‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT h25jguaT5*!‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT h25jguaT5*!PK\σ error_lognu[[18-Mar-2025 16:40:19 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [18-Mar-2025 16:40:23 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [18-Mar-2025 16:41:10 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [18-Mar-2025 16:41:13 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [29-Jun-2025 09:16:11 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [29-Jun-2025 09:16:11 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [01-Jul-2025 02:44:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [01-Jul-2025 02:44:34 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [16-Jul-2025 15:20:26 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [16-Jul-2025 15:20:27 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [17-Aug-2025 00:43:49 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [17-Aug-2025 00:43:51 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [17-Aug-2025 00:44:36 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [17-Aug-2025 00:44:39 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [19-Aug-2025 21:10:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [19-Aug-2025 21:10:34 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [19-Aug-2025 21:12:19 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [19-Aug-2025 21:12:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [20-Aug-2025 02:42:46 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [20-Aug-2025 02:42:57 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [20-Aug-2025 02:45:10 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [20-Aug-2025 02:45:18 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [23-Aug-2025 19:17:04 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [23-Aug-2025 19:17:09 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [23-Aug-2025 19:18:19 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [23-Aug-2025 19:18:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [12-Oct-2025 19:04:53 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [12-Oct-2025 19:04:53 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [12-Oct-2025 19:04:54 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [12-Oct-2025 19:04:57 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [12-Oct-2025 19:04:57 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [12-Oct-2025 19:04:58 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [12-Oct-2025 19:04:59 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [12-Oct-2025 19:05:01 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Oct-2025 05:20:22 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Oct-2025 05:20:23 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Oct-2025 05:20:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Oct-2025 05:20:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Oct-2025 05:20:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Oct-2025 05:20:29 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Oct-2025 05:20:31 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Oct-2025 05:20:34 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [30-Oct-2025 20:55:11 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [30-Oct-2025 20:55:12 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [30-Oct-2025 20:55:13 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [30-Oct-2025 20:55:16 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [30-Oct-2025 20:55:19 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [30-Oct-2025 20:55:20 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [30-Oct-2025 20:55:21 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [30-Oct-2025 20:55:24 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [09-Nov-2025 14:36:20 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [09-Nov-2025 14:36:21 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [09-Nov-2025 14:36:23 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [09-Nov-2025 14:36:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [09-Nov-2025 14:36:27 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [09-Nov-2025 14:36:29 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [09-Nov-2025 14:36:30 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [09-Nov-2025 14:36:33 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [24-Nov-2025 14:36:56 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [24-Nov-2025 14:37:01 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [29-Nov-2025 05:50:13 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [29-Nov-2025 05:50:17 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [04-Jan-2026 07:25:42 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [04-Jan-2026 07:25:43 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [22-Jan-2026 17:31:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [22-Jan-2026 17:31:34 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [22-Jan-2026 18:14:17 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [22-Jan-2026 18:14:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [22-Jan-2026 20:09:37 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [22-Jan-2026 20:09:50 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [25-Jan-2026 04:40:42 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [25-Jan-2026 04:40:45 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Jan-2026 16:49:00 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Jan-2026 16:49:06 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Jan-2026 17:27:46 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [27-Jan-2026 17:27:51 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [31-Jan-2026 12:54:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [31-Jan-2026 12:54:32 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [01-Feb-2026 12:52:30 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [01-Feb-2026 12:52:30 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [08-Feb-2026 04:12:32 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [08-Feb-2026 04:12:42 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [09-Feb-2026 03:27:52 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [09-Feb-2026 03:28:09 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [10-Feb-2026 22:19:27 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [10-Feb-2026 22:19:32 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [16-Feb-2026 06:14:31 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [16-Feb-2026 06:14:34 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [23-Feb-2026 19:59:45 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [23-Feb-2026 19:59:50 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [02-Mar-2026 02:51:29 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [02-Mar-2026 02:51:35 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [02-Mar-2026 12:13:34 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [02-Mar-2026 12:13:48 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [02-Mar-2026 14:51:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [02-Mar-2026 14:51:28 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [04-Mar-2026 01:58:25 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [04-Mar-2026 01:58:44 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [15-Mar-2026 19:22:08 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [15-Mar-2026 19:22:42 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [16-Mar-2026 01:31:48 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [16-Mar-2026 01:32:10 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [24-Mar-2026 10:51:49 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [24-Mar-2026 10:51:52 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Mar-2026 12:24:32 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 [27-Mar-2026 12:24:33 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [11-Apr-2026 22:15:23 UTC] PHP Fatal error: Uncaught Error: Class "WP_HTML_Tag_Processor" not found in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php:143 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/class-wp-html-processor.php on line 143 [11-Apr-2026 22:15:27 UTC] PHP Fatal error: Uncaught Error: Class "WP_Token_Map" not found in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php:38 Stack trace: #0 {main} thrown in /home/willdaleco/public_html/wp-includes/html-api/html5-named-character-references.php on line 38 PK\$gh"class-wp-html-text-replacement.phpnu[start = $start; $this->length = $length; $this->text = $text; } } PK\|KKclass-wp-html-span.phpnu[start = $start; $this->length = $length; } } PK\ Q,A,Aclass-wp-html-decoder.phpnu[= $length ) { return null; } if ( '&' !== $text[ $at ] ) { return null; } /* * Numeric character references. * * When truncated, these will encode the code point found by parsing the * digits that are available. For example, when `🅰` is truncated * to `DZ` it will encode `DZ`. It does not: * - know how to parse the original `🅰`. * - fail to parse and return plaintext `DZ`. * - fail to parse and return the replacement character `�` */ if ( '#' === $text[ $at + 1 ] ) { if ( $at + 2 >= $length ) { return null; } /** Tracks inner parsing within the numeric character reference. */ $digits_at = $at + 2; if ( 'x' === $text[ $digits_at ] || 'X' === $text[ $digits_at ] ) { $numeric_base = 16; $numeric_digits = '0123456789abcdefABCDEF'; $max_digits = 6; // 􏿿 ++$digits_at; } else { $numeric_base = 10; $numeric_digits = '0123456789'; $max_digits = 7; // 􏿿 } // Cannot encode invalid Unicode code points. Max is to U+10FFFF. $zero_count = strspn( $text, '0', $digits_at ); $digit_count = strspn( $text, $numeric_digits, $digits_at + $zero_count ); $after_digits = $digits_at + $zero_count + $digit_count; $has_semicolon = $after_digits < $length && ';' === $text[ $after_digits ]; $end_of_span = $has_semicolon ? $after_digits + 1 : $after_digits; // `&#` or `&#x` without digits returns into plaintext. if ( 0 === $digit_count && 0 === $zero_count ) { return null; } // Whereas `&#` and only zeros is invalid. if ( 0 === $digit_count ) { $match_byte_length = $end_of_span - $at; return '�'; } // If there are too many digits then it's not worth parsing. It's invalid. if ( $digit_count > $max_digits ) { $match_byte_length = $end_of_span - $at; return '�'; } $digits = substr( $text, $digits_at + $zero_count, $digit_count ); $code_point = intval( $digits, $numeric_base ); /* * Noncharacters, 0x0D, and non-ASCII-whitespace control characters. * * > A noncharacter is a code point that is in the range U+FDD0 to U+FDEF, * > inclusive, or U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE, U+2FFFF, * > U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF, U+6FFFE, * > U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE, U+9FFFF, * > U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF, U+DFFFE, * > U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, or U+10FFFF. * * A C0 control is a code point that is in the range of U+00 to U+1F, * but ASCII whitespace includes U+09, U+0A, U+0C, and U+0D. * * These characters are invalid but still decode as any valid character. * This comment is here to note and explain why there's no check to * remove these characters or replace them. * * @see https://infra.spec.whatwg.org/#noncharacter */ /* * Code points in the C1 controls area need to be remapped as if they * were stored in Windows-1252. Note! This transformation only happens * for numeric character references. The raw code points in the byte * stream are not translated. * * > If the number is one of the numbers in the first column of * > the following table, then find the row with that number in * > the first column, and set the character reference code to * > the number in the second column of that row. */ if ( $code_point >= 0x80 && $code_point <= 0x9F ) { $windows_1252_mapping = array( 0x20AC, // 0x80 -> EURO SIGN (€). 0x81, // 0x81 -> (no change). 0x201A, // 0x82 -> SINGLE LOW-9 QUOTATION MARK (‚). 0x0192, // 0x83 -> LATIN SMALL LETTER F WITH HOOK (ƒ). 0x201E, // 0x84 -> DOUBLE LOW-9 QUOTATION MARK („). 0x2026, // 0x85 -> HORIZONTAL ELLIPSIS (…). 0x2020, // 0x86 -> DAGGER (†). 0x2021, // 0x87 -> DOUBLE DAGGER (‡). 0x02C6, // 0x88 -> MODIFIER LETTER CIRCUMFLEX ACCENT (ˆ). 0x2030, // 0x89 -> PER MILLE SIGN (‰). 0x0160, // 0x8A -> LATIN CAPITAL LETTER S WITH CARON (Š). 0x2039, // 0x8B -> SINGLE LEFT-POINTING ANGLE QUOTATION MARK (‹). 0x0152, // 0x8C -> LATIN CAPITAL LIGATURE OE (Œ). 0x8D, // 0x8D -> (no change). 0x017D, // 0x8E -> LATIN CAPITAL LETTER Z WITH CARON (Ž). 0x8F, // 0x8F -> (no change). 0x90, // 0x90 -> (no change). 0x2018, // 0x91 -> LEFT SINGLE QUOTATION MARK (‘). 0x2019, // 0x92 -> RIGHT SINGLE QUOTATION MARK (’). 0x201C, // 0x93 -> LEFT DOUBLE QUOTATION MARK (“). 0x201D, // 0x94 -> RIGHT DOUBLE QUOTATION MARK (”). 0x2022, // 0x95 -> BULLET (•). 0x2013, // 0x96 -> EN DASH (–). 0x2014, // 0x97 -> EM DASH (—). 0x02DC, // 0x98 -> SMALL TILDE (˜). 0x2122, // 0x99 -> TRADE MARK SIGN (™). 0x0161, // 0x9A -> LATIN SMALL LETTER S WITH CARON (š). 0x203A, // 0x9B -> SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (›). 0x0153, // 0x9C -> LATIN SMALL LIGATURE OE (œ). 0x9D, // 0x9D -> (no change). 0x017E, // 0x9E -> LATIN SMALL LETTER Z WITH CARON (ž). 0x0178, // 0x9F -> LATIN CAPITAL LETTER Y WITH DIAERESIS (Ÿ). ); $code_point = $windows_1252_mapping[ $code_point - 0x80 ]; } $match_byte_length = $end_of_span - $at; return self::code_point_to_utf8_bytes( $code_point ); } /** Tracks inner parsing within the named character reference. */ $name_at = $at + 1; // Minimum named character reference is two characters. E.g. `GT`. if ( $name_at + 2 > $length ) { return null; } $name_length = 0; $replacement = $html5_named_character_references->read_token( $text, $name_at, $name_length ); if ( false === $replacement ) { return null; } $after_name = $name_at + $name_length; // If the match ended with a semicolon then it should always be decoded. if ( ';' === $text[ $name_at + $name_length - 1 ] ) { $match_byte_length = $after_name - $at; return $replacement; } /* * At this point though there's a match for an entry in the named * character reference table but the match doesn't end in `;`. * It may be allowed if it's followed by something unambiguous. */ $ambiguous_follower = ( $after_name < $length && $name_at < $length && ( ctype_alnum( $text[ $after_name ] ) || '=' === $text[ $after_name ] ) ); // It's non-ambiguous, safe to leave it in. if ( ! $ambiguous_follower ) { $match_byte_length = $after_name - $at; return $replacement; } // It's ambiguous, which isn't allowed inside attributes. if ( 'attribute' === $context ) { return null; } $match_byte_length = $after_name - $at; return $replacement; } /** * Encode a code point number into the UTF-8 encoding. * * This encoder implements the UTF-8 encoding algorithm for converting * a code point into a byte sequence. If it receives an invalid code * point it will return the Unicode Replacement Character U+FFFD `�`. * * Example: * * '🅰' === WP_HTML_Decoder::code_point_to_utf8_bytes( 0x1f170 ); * * // Half of a surrogate pair is an invalid code point. * '�' === WP_HTML_Decoder::code_point_to_utf8_bytes( 0xd83c ); * * @since 6.6.0 * * @see https://www.rfc-editor.org/rfc/rfc3629 For the UTF-8 standard. * * @param int $code_point Which code point to convert. * @return string Converted code point, or `�` if invalid. */ public static function code_point_to_utf8_bytes( $code_point ): string { // Pre-check to ensure a valid code point. if ( $code_point <= 0 || ( $code_point >= 0xD800 && $code_point <= 0xDFFF ) || $code_point > 0x10FFFF ) { return '�'; } if ( $code_point <= 0x7F ) { return chr( $code_point ); } if ( $code_point <= 0x7FF ) { $byte1 = chr( ( $code_point >> 6 ) | 0xC0 ); $byte2 = chr( $code_point & 0x3F | 0x80 ); return "{$byte1}{$byte2}"; } if ( $code_point <= 0xFFFF ) { $byte1 = chr( ( $code_point >> 12 ) | 0xE0 ); $byte2 = chr( ( $code_point >> 6 ) & 0x3F | 0x80 ); $byte3 = chr( $code_point & 0x3F | 0x80 ); return "{$byte1}{$byte2}{$byte3}"; } // Any values above U+10FFFF are eliminated above in the pre-check. $byte1 = chr( ( $code_point >> 18 ) | 0xF0 ); $byte2 = chr( ( $code_point >> 12 ) & 0x3F | 0x80 ); $byte3 = chr( ( $code_point >> 6 ) & 0x3F | 0x80 ); $byte4 = chr( $code_point & 0x3F | 0x80 ); return "{$byte1}{$byte2}{$byte3}{$byte4}"; } } PK\Vincidents/index.phpnu[' . $app); ?>PK\7WWclass-wp-html-open-elements.phpnu[ Initially, the stack of open elements is empty. The stack grows * > downwards; the topmost node on the stack is the first one added * > to the stack, and the bottommost node of the stack is the most * > recently added node in the stack (notwithstanding when the stack * > is manipulated in a random access fashion as part of the handling * > for misnested tags). * * @since 6.4.0 * * @access private * @ignore * * @see https://html.spec.whatwg.org/#stack-of-open-elements * @see WP_HTML_Processor */ class WP_HTML_Open_Elements { /** * Holds the stack of open element references. * * @since 6.4.0 * * @var WP_HTML_Token[] */ public $stack = array(); /** * Whether a P element is in button scope currently. * * This class optimizes scope lookup by pre-calculating * this value when elements are added and removed to the * stack of open elements which might change its value. * This avoids frequent iteration over the stack. * * @since 6.4.0 * * @var bool */ private $has_p_in_button_scope = false; /** * A function that will be called when an item is popped off the stack of open elements. * * The function will be called with the popped item as its argument. * * @since 6.6.0 * * @var Closure|null */ private $pop_handler = null; /** * A function that will be called when an item is pushed onto the stack of open elements. * * The function will be called with the pushed item as its argument. * * @since 6.6.0 * * @var Closure|null */ private $push_handler = null; /** * Sets a pop handler that will be called when an item is popped off the stack of * open elements. * * The function will be called with the pushed item as its argument. * * @since 6.6.0 * * @param Closure $handler The handler function. */ public function set_pop_handler( Closure $handler ): void { $this->pop_handler = $handler; } /** * Sets a push handler that will be called when an item is pushed onto the stack of * open elements. * * The function will be called with the pushed item as its argument. * * @since 6.6.0 * * @param Closure $handler The handler function. */ public function set_push_handler( Closure $handler ): void { $this->push_handler = $handler; } /** * Returns the name of the node at the nth position on the stack * of open elements, or `null` if no such position exists. * * Note that this uses a 1-based index, which represents the * "nth item" on the stack, counting from the top, where the * top-most element is the 1st, the second is the 2nd, etc... * * @since 6.7.0 * * @param int $nth Retrieve the nth item on the stack, with 1 being * the top element, 2 being the second, etc... * @return WP_HTML_Token|null Name of the node on the stack at the given location, * or `null` if the location isn't on the stack. */ public function at( int $nth ): ?WP_HTML_Token { foreach ( $this->walk_down() as $item ) { if ( 0 === --$nth ) { return $item; } } return null; } /** * Reports if a node of a given name is in the stack of open elements. * * @since 6.7.0 * * @param string $node_name Name of node for which to check. * @return bool Whether a node of the given name is in the stack of open elements. */ public function contains( string $node_name ): bool { foreach ( $this->walk_up() as $item ) { if ( $node_name === $item->node_name ) { return true; } } return false; } /** * Reports if a specific node is in the stack of open elements. * * @since 6.4.0 * * @param WP_HTML_Token $token Look for this node in the stack. * @return bool Whether the referenced node is in the stack of open elements. */ public function contains_node( WP_HTML_Token $token ): bool { foreach ( $this->walk_up() as $item ) { if ( $token === $item ) { return true; } } return false; } /** * Returns how many nodes are currently in the stack of open elements. * * @since 6.4.0 * * @return int How many node are in the stack of open elements. */ public function count(): int { return count( $this->stack ); } /** * Returns the node at the end of the stack of open elements, * if one exists. If the stack is empty, returns null. * * @since 6.4.0 * * @return WP_HTML_Token|null Last node in the stack of open elements, if one exists, otherwise null. */ public function current_node(): ?WP_HTML_Token { $current_node = end( $this->stack ); return $current_node ? $current_node : null; } /** * Indicates if the current node is of a given type or name. * * It's possible to pass either a node type or a node name to this function. * In the case there is no current element it will always return `false`. * * Example: * * // Is the current node a text node? * $stack->current_node_is( '#text' ); * * // Is the current node a DIV element? * $stack->current_node_is( 'DIV' ); * * // Is the current node any element/tag? * $stack->current_node_is( '#tag' ); * * @see WP_HTML_Tag_Processor::get_token_type * @see WP_HTML_Tag_Processor::get_token_name * * @since 6.7.0 * * @access private * * @param string $identity Check if the current node has this name or type (depending on what is provided). * @return bool Whether there is a current element that matches the given identity, whether a token name or type. */ public function current_node_is( string $identity ): bool { $current_node = end( $this->stack ); if ( false === $current_node ) { return false; } $current_node_name = $current_node->node_name; return ( $current_node_name === $identity || ( '#doctype' === $identity && 'html' === $current_node_name ) || ( '#tag' === $identity && ctype_upper( $current_node_name ) ) ); } /** * Returns whether an element is in a specific scope. * * @since 6.4.0 * * @see https://html.spec.whatwg.org/#has-an-element-in-the-specific-scope * * @param string $tag_name Name of tag check. * @param string[] $termination_list List of elements that terminate the search. * @return bool Whether the element was found in a specific scope. */ public function has_element_in_specific_scope( string $tag_name, $termination_list ): bool { foreach ( $this->walk_up() as $node ) { $namespaced_name = 'html' === $node->namespace ? $node->node_name : "{$node->namespace} {$node->node_name}"; if ( $namespaced_name === $tag_name ) { return true; } if ( '(internal: H1 through H6 - do not use)' === $tag_name && in_array( $namespaced_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true ) ) { return true; } if ( in_array( $namespaced_name, $termination_list, true ) ) { return false; } } return false; } /** * Returns whether a particular element is in scope. * * > The stack of open elements is said to have a particular element in * > scope when it has that element in the specific scope consisting of * > the following element types: * > * > - applet * > - caption * > - html * > - table * > - td * > - th * > - marquee * > - object * > - template * > - MathML mi * > - MathML mo * > - MathML mn * > - MathML ms * > - MathML mtext * > - MathML annotation-xml * > - SVG foreignObject * > - SVG desc * > - SVG title * * @since 6.4.0 * @since 6.7.0 Full support. * * @see https://html.spec.whatwg.org/#has-an-element-in-scope * * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ public function has_element_in_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( 'APPLET', 'CAPTION', 'HTML', 'TABLE', 'TD', 'TH', 'MARQUEE', 'OBJECT', 'TEMPLATE', 'math MI', 'math MO', 'math MN', 'math MS', 'math MTEXT', 'math ANNOTATION-XML', 'svg FOREIGNOBJECT', 'svg DESC', 'svg TITLE', ) ); } /** * Returns whether a particular element is in list item scope. * * > The stack of open elements is said to have a particular element * > in list item scope when it has that element in the specific scope * > consisting of the following element types: * > * > - All the element types listed above for the has an element in scope algorithm. * > - ol in the HTML namespace * > - ul in the HTML namespace * * @since 6.4.0 * @since 6.5.0 Implemented: no longer throws on every invocation. * @since 6.7.0 Supports all required HTML elements. * * @see https://html.spec.whatwg.org/#has-an-element-in-list-item-scope * * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ public function has_element_in_list_item_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( 'APPLET', 'BUTTON', 'CAPTION', 'HTML', 'TABLE', 'TD', 'TH', 'MARQUEE', 'OBJECT', 'OL', 'TEMPLATE', 'UL', 'math MI', 'math MO', 'math MN', 'math MS', 'math MTEXT', 'math ANNOTATION-XML', 'svg FOREIGNOBJECT', 'svg DESC', 'svg TITLE', ) ); } /** * Returns whether a particular element is in button scope. * * > The stack of open elements is said to have a particular element * > in button scope when it has that element in the specific scope * > consisting of the following element types: * > * > - All the element types listed above for the has an element in scope algorithm. * > - button in the HTML namespace * * @since 6.4.0 * @since 6.7.0 Supports all required HTML elements. * * @see https://html.spec.whatwg.org/#has-an-element-in-button-scope * * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ public function has_element_in_button_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( 'APPLET', 'BUTTON', 'CAPTION', 'HTML', 'TABLE', 'TD', 'TH', 'MARQUEE', 'OBJECT', 'TEMPLATE', 'math MI', 'math MO', 'math MN', 'math MS', 'math MTEXT', 'math ANNOTATION-XML', 'svg FOREIGNOBJECT', 'svg DESC', 'svg TITLE', ) ); } /** * Returns whether a particular element is in table scope. * * > The stack of open elements is said to have a particular element * > in table scope when it has that element in the specific scope * > consisting of the following element types: * > * > - html in the HTML namespace * > - table in the HTML namespace * > - template in the HTML namespace * * @since 6.4.0 * @since 6.7.0 Full implementation. * * @see https://html.spec.whatwg.org/#has-an-element-in-table-scope * * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ public function has_element_in_table_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( 'HTML', 'TABLE', 'TEMPLATE', ) ); } /** * Returns whether a particular element is in select scope. * * This test differs from the others like it, in that its rules are inverted. * Instead of arriving at a match when one of any tag in a termination group * is reached, this one terminates if any other tag is reached. * * > The stack of open elements is said to have a particular element in select scope when it has * > that element in the specific scope consisting of all element types except the following: * > - optgroup in the HTML namespace * > - option in the HTML namespace * * @since 6.4.0 Stub implementation (throws). * @since 6.7.0 Full implementation. * * @see https://html.spec.whatwg.org/#has-an-element-in-select-scope * * @param string $tag_name Name of tag to check. * @return bool Whether the given element is in SELECT scope. */ public function has_element_in_select_scope( string $tag_name ): bool { foreach ( $this->walk_up() as $node ) { if ( $node->node_name === $tag_name ) { return true; } if ( 'OPTION' !== $node->node_name && 'OPTGROUP' !== $node->node_name ) { return false; } } return false; } /** * Returns whether a P is in BUTTON scope. * * @since 6.4.0 * * @see https://html.spec.whatwg.org/#has-an-element-in-button-scope * * @return bool Whether a P is in BUTTON scope. */ public function has_p_in_button_scope(): bool { return $this->has_p_in_button_scope; } /** * Pops a node off of the stack of open elements. * * @since 6.4.0 * * @see https://html.spec.whatwg.org/#stack-of-open-elements * * @return bool Whether a node was popped off of the stack. */ public function pop(): bool { $item = array_pop( $this->stack ); if ( null === $item ) { return false; } $this->after_element_pop( $item ); return true; } /** * Pops nodes off of the stack of open elements until an HTML tag with the given name has been popped. * * @since 6.4.0 * * @see WP_HTML_Open_Elements::pop * * @param string $html_tag_name Name of tag that needs to be popped off of the stack of open elements. * @return bool Whether a tag of the given name was found and popped off of the stack of open elements. */ public function pop_until( string $html_tag_name ): bool { foreach ( $this->walk_up() as $item ) { $this->pop(); if ( 'html' !== $item->namespace ) { continue; } if ( '(internal: H1 through H6 - do not use)' === $html_tag_name && in_array( $item->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true ) ) { return true; } if ( $html_tag_name === $item->node_name ) { return true; } } return false; } /** * Pushes a node onto the stack of open elements. * * @since 6.4.0 * * @see https://html.spec.whatwg.org/#stack-of-open-elements * * @param WP_HTML_Token $stack_item Item to add onto stack. */ public function push( WP_HTML_Token $stack_item ): void { $this->stack[] = $stack_item; $this->after_element_push( $stack_item ); } /** * Removes a specific node from the stack of open elements. * * @since 6.4.0 * * @param WP_HTML_Token $token The node to remove from the stack of open elements. * @return bool Whether the node was found and removed from the stack of open elements. */ public function remove_node( WP_HTML_Token $token ): bool { foreach ( $this->walk_up() as $position_from_end => $item ) { if ( $token->bookmark_name !== $item->bookmark_name ) { continue; } $position_from_start = $this->count() - $position_from_end - 1; array_splice( $this->stack, $position_from_start, 1 ); $this->after_element_pop( $item ); return true; } return false; } /** * Steps through the stack of open elements, starting with the top element * (added first) and walking downwards to the one added last. * * This generator function is designed to be used inside a "foreach" loop. * * Example: * * $html = 'We are here'; * foreach ( $stack->walk_down() as $node ) { * echo "{$node->node_name} -> "; * } * > EM -> STRONG -> A -> * * To start with the most-recently added element and walk towards the top, * see WP_HTML_Open_Elements::walk_up(). * * @since 6.4.0 */ public function walk_down() { $count = count( $this->stack ); for ( $i = 0; $i < $count; $i++ ) { yield $this->stack[ $i ]; } } /** * Steps through the stack of open elements, starting with the bottom element * (added last) and walking upwards to the one added first. * * This generator function is designed to be used inside a "foreach" loop. * * Example: * * $html = 'We are here'; * foreach ( $stack->walk_up() as $node ) { * echo "{$node->node_name} -> "; * } * > A -> STRONG -> EM -> * * To start with the first added element and walk towards the bottom, * see WP_HTML_Open_Elements::walk_down(). * * @since 6.4.0 * @since 6.5.0 Accepts $above_this_node to start traversal above a given node, if it exists. * * @param WP_HTML_Token|null $above_this_node Optional. Start traversing above this node, * if provided and if the node exists. */ public function walk_up( ?WP_HTML_Token $above_this_node = null ) { $has_found_node = null === $above_this_node; for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) { $node = $this->stack[ $i ]; if ( ! $has_found_node ) { $has_found_node = $node === $above_this_node; continue; } yield $node; } } /* * Internal helpers. */ /** * Updates internal flags after adding an element. * * Certain conditions (such as "has_p_in_button_scope") are maintained here as * flags that are only modified when adding and removing elements. This allows * the HTML Processor to quickly check for these conditions instead of iterating * over the open stack elements upon each new tag it encounters. These flags, * however, need to be maintained as items are added and removed from the stack. * * @since 6.4.0 * * @param WP_HTML_Token $item Element that was added to the stack of open elements. */ public function after_element_push( WP_HTML_Token $item ): void { $namespaced_name = 'html' === $item->namespace ? $item->node_name : "{$item->namespace} {$item->node_name}"; /* * When adding support for new elements, expand this switch to trap * cases where the precalculated value needs to change. */ switch ( $namespaced_name ) { case 'APPLET': case 'BUTTON': case 'CAPTION': case 'HTML': case 'TABLE': case 'TD': case 'TH': case 'MARQUEE': case 'OBJECT': case 'TEMPLATE': case 'math MI': case 'math MO': case 'math MN': case 'math MS': case 'math MTEXT': case 'math ANNOTATION-XML': case 'svg FOREIGNOBJECT': case 'svg DESC': case 'svg TITLE': $this->has_p_in_button_scope = false; break; case 'P': $this->has_p_in_button_scope = true; break; } if ( null !== $this->push_handler ) { call_user_func( $this->push_handler, $item ); } } /** * Updates internal flags after removing an element. * * Certain conditions (such as "has_p_in_button_scope") are maintained here as * flags that are only modified when adding and removing elements. This allows * the HTML Processor to quickly check for these conditions instead of iterating * over the open stack elements upon each new tag it encounters. These flags, * however, need to be maintained as items are added and removed from the stack. * * @since 6.4.0 * * @param WP_HTML_Token $item Element that was removed from the stack of open elements. */ public function after_element_pop( WP_HTML_Token $item ): void { /* * When adding support for new elements, expand this switch to trap * cases where the precalculated value needs to change. */ switch ( $item->node_name ) { case 'APPLET': case 'BUTTON': case 'CAPTION': case 'HTML': case 'P': case 'TABLE': case 'TD': case 'TH': case 'MARQUEE': case 'OBJECT': case 'TEMPLATE': case 'math MI': case 'math MO': case 'math MN': case 'math MS': case 'math MTEXT': case 'math ANNOTATION-XML': case 'svg FOREIGNOBJECT': case 'svg DESC': case 'svg TITLE': $this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' ); break; } if ( null !== $this->pop_handler ) { call_user_func( $this->pop_handler, $item ); } } /** * Clear the stack back to a table context. * * > When the steps above require the UA to clear the stack back to a table context, it means * > that the UA must, while the current node is not a table, template, or html element, pop * > elements from the stack of open elements. * * @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-context * * @since 6.7.0 */ public function clear_to_table_context(): void { foreach ( $this->walk_up() as $item ) { if ( 'TABLE' === $item->node_name || 'TEMPLATE' === $item->node_name || 'HTML' === $item->node_name ) { break; } $this->pop(); } } /** * Clear the stack back to a table body context. * * > When the steps above require the UA to clear the stack back to a table body context, it * > means that the UA must, while the current node is not a tbody, tfoot, thead, template, or * > html element, pop elements from the stack of open elements. * * @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-body-context * * @since 6.7.0 */ public function clear_to_table_body_context(): void { foreach ( $this->walk_up() as $item ) { if ( 'TBODY' === $item->node_name || 'TFOOT' === $item->node_name || 'THEAD' === $item->node_name || 'TEMPLATE' === $item->node_name || 'HTML' === $item->node_name ) { break; } $this->pop(); } } /** * Clear the stack back to a table row context. * * > When the steps above require the UA to clear the stack back to a table row context, it * > means that the UA must, while the current node is not a tr, template, or html element, pop * > elements from the stack of open elements. * * @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-row-context * * @since 6.7.0 */ public function clear_to_table_row_context(): void { foreach ( $this->walk_up() as $item ) { if ( 'TR' === $item->node_name || 'TEMPLATE' === $item->node_name || 'HTML' === $item->node_name ) { break; } $this->pop(); } } /** * Wakeup magic method. * * @since 6.6.0 */ public function __wakeup() { throw new \LogicException( __CLASS__ . ' should never be unserialized' ); } } PK\eH class-wp-html-tag-processor.phpnu[ "c" not " c". * This would increase the size of the changes for some operations but leave more * natural-looking output HTML. * * @package WordPress * @subpackage HTML-API * @since 6.2.0 */ /** * Core class used to modify attributes in an HTML document for tags matching a query. * * ## Usage * * Use of this class requires three steps: * * 1. Create a new class instance with your input HTML document. * 2. Find the tag(s) you are looking for. * 3. Request changes to the attributes in those tag(s). * * Example: * * $tags = new WP_HTML_Tag_Processor( $html ); * if ( $tags->next_tag( 'option' ) ) { * $tags->set_attribute( 'selected', true ); * } * * ### Finding tags * * The `next_tag()` function moves the internal cursor through * your input HTML document until it finds a tag meeting any of * the supplied restrictions in the optional query argument. If * no argument is provided then it will find the next HTML tag, * regardless of what kind it is. * * If you want to _find whatever the next tag is_: * * $tags->next_tag(); * * | Goal | Query | * |-----------------------------------------------------------|---------------------------------------------------------------------------------| * | Find any tag. | `$tags->next_tag();` | * | Find next image tag. | `$tags->next_tag( array( 'tag_name' => 'img' ) );` | * | Find next image tag (without passing the array). | `$tags->next_tag( 'img' );` | * | Find next tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'class_name' => 'fullwidth' ) );` | * | Find next image tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'tag_name' => 'img', 'class_name' => 'fullwidth' ) );` | * * If a tag was found meeting your criteria then `next_tag()` * will return `true` and you can proceed to modify it. If it * returns `false`, however, it failed to find the tag and * moved the cursor to the end of the file. * * Once the cursor reaches the end of the file the processor * is done and if you want to reach an earlier tag you will * need to recreate the processor and start over, as it's * unable to back up or move in reverse. * * See the section on bookmarks for an exception to this * no-backing-up rule. * * #### Custom queries * * Sometimes it's necessary to further inspect an HTML tag than * the query syntax here permits. In these cases one may further * inspect the search results using the read-only functions * provided by the processor or external state or variables. * * Example: * * // Paint up to the first five DIV or SPAN tags marked with the "jazzy" style. * $remaining_count = 5; * while ( $remaining_count > 0 && $tags->next_tag() ) { * if ( * ( 'DIV' === $tags->get_tag() || 'SPAN' === $tags->get_tag() ) && * 'jazzy' === $tags->get_attribute( 'data-style' ) * ) { * $tags->add_class( 'theme-style-everest-jazz' ); * $remaining_count--; * } * } * * `get_attribute()` will return `null` if the attribute wasn't present * on the tag when it was called. It may return `""` (the empty string) * in cases where the attribute was present but its value was empty. * For boolean attributes, those whose name is present but no value is * given, it will return `true` (the only way to set `false` for an * attribute is to remove it). * * #### When matching fails * * When `next_tag()` returns `false` it could mean different things: * * - The requested tag wasn't found in the input document. * - The input document ended in the middle of an HTML syntax element. * * When a document ends in the middle of a syntax element it will pause * the processor. This is to make it possible in the future to extend the * input document and proceed - an important requirement for chunked * streaming parsing of a document. * * Example: * * $processor = new WP_HTML_Tag_Processor( 'This
` inside an HTML comment. * - STYLE content is raw text. * - TITLE content is plain text but character references are decoded. * - TEXTAREA content is plain text but character references are decoded. * - XMP (deprecated) content is raw text. * * ### Modifying HTML attributes for a found tag * * Once you've found the start of an opening tag you can modify * any number of the attributes on that tag. You can set a new * value for an attribute, remove the entire attribute, or do * nothing and move on to the next opening tag. * * Example: * * if ( $tags->next_tag( array( 'class_name' => 'wp-group-block' ) ) ) { * $tags->set_attribute( 'title', 'This groups the contained content.' ); * $tags->remove_attribute( 'data-test-id' ); * } * * If `set_attribute()` is called for an existing attribute it will * overwrite the existing value. Similarly, calling `remove_attribute()` * for a non-existing attribute has no effect on the document. Both * of these methods are safe to call without knowing if a given attribute * exists beforehand. * * ### Modifying CSS classes for a found tag * * The tag processor treats the `class` attribute as a special case. * Because it's a common operation to add or remove CSS classes, this * interface adds helper methods to make that easier. * * As with attribute values, adding or removing CSS classes is a safe * operation that doesn't require checking if the attribute or class * exists before making changes. If removing the only class then the * entire `class` attribute will be removed. * * Example: * * // from `Yippee!` * // to `Yippee!` * $tags->add_class( 'is-active' ); * * // from `Yippee!` * // to `Yippee!` * $tags->add_class( 'is-active' ); * * // from `Yippee!` * // to `Yippee!` * $tags->add_class( 'is-active' ); * * // from `` * // to ` * $tags->remove_class( 'rugby' ); * * // from `` * // to ` * $tags->remove_class( 'rugby' ); * * // from `` * // to ` * $tags->remove_class( 'rugby' ); * * When class changes are enqueued but a direct change to `class` is made via * `set_attribute` then the changes to `set_attribute` (or `remove_attribute`) * will take precedence over those made through `add_class` and `remove_class`. * * ### Bookmarks * * While scanning through the input HTMl document it's possible to set * a named bookmark when a particular tag is found. Later on, after * continuing to scan other tags, it's possible to `seek` to one of * the set bookmarks and then proceed again from that point forward. * * Because bookmarks create processing overhead one should avoid * creating too many of them. As a rule, create only bookmarks * of known string literal names; avoid creating "mark_{$index}" * and so on. It's fine from a performance standpoint to create a * bookmark and update it frequently, such as within a loop. * * $total_todos = 0; * while ( $p->next_tag( array( 'tag_name' => 'UL', 'class_name' => 'todo' ) ) ) { * $p->set_bookmark( 'list-start' ); * while ( $p->next_tag( array( 'tag_closers' => 'visit' ) ) ) { * if ( 'UL' === $p->get_tag() && $p->is_tag_closer() ) { * $p->set_bookmark( 'list-end' ); * $p->seek( 'list-start' ); * $p->set_attribute( 'data-contained-todos', (string) $total_todos ); * $total_todos = 0; * $p->seek( 'list-end' ); * break; * } * * if ( 'LI' === $p->get_tag() && ! $p->is_tag_closer() ) { * $total_todos++; * } * } * } * * ## Tokens and finer-grained processing. * * It's possible to scan through every lexical token in the * HTML document using the `next_token()` function. This * alternative form takes no argument and provides no built-in * query syntax. * * Example: * * $title = '(untitled)'; * $text = ''; * while ( $processor->next_token() ) { * switch ( $processor->get_token_name() ) { * case '#text': * $text .= $processor->get_modifiable_text(); * break; * * case 'BR': * $text .= "\n"; * break; * * case 'TITLE': * $title = $processor->get_modifiable_text(); * break; * } * } * return trim( "# {$title}\n\n{$text}" ); * * ### Tokens and _modifiable text_. * * #### Special "atomic" HTML elements. * * Not all HTML elements are able to contain other elements inside of them. * For instance, the contents inside a TITLE element are plaintext (except * that character references like & will be decoded). This means that * if the string `` appears inside a TITLE element, then it's not an * image tag, but rather it's text describing an image tag. Likewise, the * contents of a SCRIPT or STYLE element are handled entirely separately in * a browser than the contents of other elements because they represent a * different language than HTML. * * For these elements the Tag Processor treats the entire sequence as one, * from the opening tag, including its contents, through its closing tag. * This means that the it's not possible to match the closing tag for a * SCRIPT element unless it's unexpected; the Tag Processor already matched * it when it found the opening tag. * * The inner contents of these elements are that element's _modifiable text_. * * The special elements are: * - `SCRIPT` whose contents are treated as raw plaintext but supports a legacy * style of including JavaScript inside of HTML comments to avoid accidentally * closing the SCRIPT from inside a JavaScript string. E.g. `console.log( '' )`. * - `TITLE` and `TEXTAREA` whose contents are treated as plaintext and then any * character references are decoded. E.g. `1 < 2 < 3` becomes `1 < 2 < 3`. * - `IFRAME`, `NOSCRIPT`, `NOEMBED`, `NOFRAME`, `STYLE` whose contents are treated as * raw plaintext and left as-is. E.g. `1 < 2 < 3` remains `1 < 2 < 3`. * * #### Other tokens with modifiable text. * * There are also non-elements which are void/self-closing in nature and contain * modifiable text that is part of that individual syntax token itself. * * - `#text` nodes, whose entire token _is_ the modifiable text. * - HTML comments and tokens that become comments due to some syntax error. The * text for these tokens is the portion of the comment inside of the syntax. * E.g. for `` the text is `" comment "` (note the spaces are included). * - `CDATA` sections, whose text is the content inside of the section itself. E.g. for * `` the text is `"some content"` (with restrictions [1]). * - "Funky comments," which are a special case of invalid closing tags whose name is * invalid. The text for these nodes is the text that a browser would transform into * an HTML comment when parsing. E.g. for `` the text is `%post_author`. * - `DOCTYPE` declarations like `` which have no closing tag. * - XML Processing instruction nodes like `` (with restrictions [2]). * - The empty end tag `` which is ignored in the browser and DOM. * * [1]: There are no CDATA sections in HTML. When encountering `` becomes a bogus HTML comment, meaning there can be no CDATA * section in an HTML document containing `>`. The Tag Processor will first find * all valid and bogus HTML comments, and then if the comment _would_ have been a * CDATA section _were they to exist_, it will indicate this as the type of comment. * * [2]: XML allows a broader range of characters in a processing instruction's target name * and disallows "xml" as a name, since it's special. The Tag Processor only recognizes * target names with an ASCII-representable subset of characters. It also exhibits the * same constraint as with CDATA sections, in that `>` cannot exist within the token * since Processing Instructions do no exist within HTML and their syntax transforms * into a bogus comment in the DOM. * * ## Design and limitations * * The Tag Processor is designed to linearly scan HTML documents and tokenize * HTML tags and their attributes. It's designed to do this as efficiently as * possible without compromising parsing integrity. Therefore it will be * slower than some methods of modifying HTML, such as those incorporating * over-simplified PCRE patterns, but will not introduce the defects and * failures that those methods bring in, which lead to broken page renders * and often to security vulnerabilities. On the other hand, it will be faster * than full-blown HTML parsers such as DOMDocument and use considerably * less memory. It requires a negligible memory overhead, enough to consider * it a zero-overhead system. * * The performance characteristics are maintained by avoiding tree construction * and semantic cleanups which are specified in HTML5. Because of this, for * example, it's not possible for the Tag Processor to associate any given * opening tag with its corresponding closing tag, or to return the inner markup * inside an element. Systems may be built on top of the Tag Processor to do * this, but the Tag Processor is and should be constrained so it can remain an * efficient, low-level, and reliable HTML scanner. * * The Tag Processor's design incorporates a "garbage-in-garbage-out" philosophy. * HTML5 specifies that certain invalid content be transformed into different forms * for display, such as removing null bytes from an input document and replacing * invalid characters with the Unicode replacement character `U+FFFD` (visually "�"). * Where errors or transformations exist within the HTML5 specification, the Tag Processor * leaves those invalid inputs untouched, passing them through to the final browser * to handle. While this implies that certain operations will be non-spec-compliant, * such as reading the value of an attribute with invalid content, it also preserves a * simplicity and efficiency for handling those error cases. * * Most operations within the Tag Processor are designed to minimize the difference * between an input and output document for any given change. For example, the * `add_class` and `remove_class` methods preserve whitespace and the class ordering * within the `class` attribute; and when encountering tags with duplicated attributes, * the Tag Processor will leave those invalid duplicate attributes where they are but * update the proper attribute which the browser will read for parsing its value. An * exception to this rule is that all attribute updates store their values as * double-quoted strings, meaning that attributes on input with single-quoted or * unquoted values will appear in the output with double-quotes. * * ### Scripting Flag * * The Tag Processor parses HTML with the "scripting flag" disabled. This means * that it doesn't run any scripts while parsing the page. In a browser with * JavaScript enabled, for example, the script can change the parse of the * document as it loads. On the server, however, evaluating JavaScript is not * only impractical, but also unwanted. * * Practically this means that the Tag Processor will descend into NOSCRIPT * elements and process its child tags. Were the scripting flag enabled, such * as in a typical browser, the contents of NOSCRIPT are skipped entirely. * * This allows the HTML API to process the content that will be presented in * a browser when scripting is disabled, but it offers a different view of a * page than most browser sessions will experience. E.g. the tags inside the * NOSCRIPT disappear. * * ### Text Encoding * * The Tag Processor assumes that the input HTML document is encoded with a * text encoding compatible with 7-bit ASCII's '<', '>', '&', ';', '/', '=', * "'", '"', 'a' - 'z', 'A' - 'Z', and the whitespace characters ' ', tab, * carriage-return, newline, and form-feed. * * In practice, this includes almost every single-byte encoding as well as * UTF-8. Notably, however, it does not include UTF-16. If providing input * that's incompatible, then convert the encoding beforehand. * * @since 6.2.0 * @since 6.2.1 Fix: Support for various invalid comments; attribute updates are case-insensitive. * @since 6.3.2 Fix: Skip HTML-like content inside rawtext elements such as STYLE. * @since 6.5.0 Pauses processor when input ends in an incomplete syntax token. * Introduces "special" elements which act like void elements, e.g. TITLE, STYLE. * Allows scanning through all tokens and processing modifiable text, where applicable. */ class WP_HTML_Tag_Processor { /** * The maximum number of bookmarks allowed to exist at * any given time. * * @since 6.2.0 * @var int * * @see WP_HTML_Tag_Processor::set_bookmark() */ const MAX_BOOKMARKS = 10; /** * Maximum number of times seek() can be called. * Prevents accidental infinite loops. * * @since 6.2.0 * @var int * * @see WP_HTML_Tag_Processor::seek() */ const MAX_SEEK_OPS = 1000; /** * The HTML document to parse. * * @since 6.2.0 * @var string */ protected $html; /** * The last query passed to next_tag(). * * @since 6.2.0 * @var array|null */ private $last_query; /** * The tag name this processor currently scans for. * * @since 6.2.0 * @var string|null */ private $sought_tag_name; /** * The CSS class name this processor currently scans for. * * @since 6.2.0 * @var string|null */ private $sought_class_name; /** * The match offset this processor currently scans for. * * @since 6.2.0 * @var int|null */ private $sought_match_offset; /** * Whether to visit tag closers, e.g.
, when walking an input document. * * @since 6.2.0 * @var bool */ private $stop_on_tag_closers; /** * Specifies mode of operation of the parser at any given time. * * | State | Meaning | * | ----------------|----------------------------------------------------------------------| * | *Ready* | The parser is ready to run. | * | *Complete* | There is nothing left to parse. | * | *Incomplete* | The HTML ended in the middle of a token; nothing more can be parsed. | * | *Matched tag* | Found an HTML tag; it's possible to modify its attributes. | * | *Text node* | Found a #text node; this is plaintext and modifiable. | * | *CDATA node* | Found a CDATA section; this is modifiable. | * | *Comment* | Found a comment or bogus comment; this is modifiable. | * | *Presumptuous* | Found an empty tag closer: ``. | * | *Funky comment* | Found a tag closer with an invalid tag name; this is modifiable. | * * @since 6.5.0 * * @see WP_HTML_Tag_Processor::STATE_READY * @see WP_HTML_Tag_Processor::STATE_COMPLETE * @see WP_HTML_Tag_Processor::STATE_INCOMPLETE_INPUT * @see WP_HTML_Tag_Processor::STATE_MATCHED_TAG * @see WP_HTML_Tag_Processor::STATE_TEXT_NODE * @see WP_HTML_Tag_Processor::STATE_CDATA_NODE * @see WP_HTML_Tag_Processor::STATE_COMMENT * @see WP_HTML_Tag_Processor::STATE_DOCTYPE * @see WP_HTML_Tag_Processor::STATE_PRESUMPTUOUS_TAG * @see WP_HTML_Tag_Processor::STATE_FUNKY_COMMENT * * @var string */ protected $parser_state = self::STATE_READY; /** * Indicates if the document is in quirks mode or no-quirks mode. * * Impact on HTML parsing: * * - In `NO_QUIRKS_MODE` (also known as "standard mode"): * - CSS class and ID selectors match byte-for-byte (case-sensitively). * - A TABLE start tag `` implicitly closes any open `P` element. * * - In `QUIRKS_MODE`: * - CSS class and ID selectors match match in an ASCII case-insensitive manner. * - A TABLE start tag `
` opens a `TABLE` element as a child of a `P` * element if one is open. * * Quirks and no-quirks mode are thus mostly about styling, but have an impact when * tables are found inside paragraph elements. * * @see self::QUIRKS_MODE * @see self::NO_QUIRKS_MODE * * @since 6.7.0 * * @var string */ protected $compat_mode = self::NO_QUIRKS_MODE; /** * Indicates whether the parser is inside foreign content, * e.g. inside an SVG or MathML element. * * One of 'html', 'svg', or 'math'. * * Several parsing rules change based on whether the parser * is inside foreign content, including whether CDATA sections * are allowed and whether a self-closing flag indicates that * an element has no content. * * @since 6.7.0 * * @var string */ private $parsing_namespace = 'html'; /** * What kind of syntax token became an HTML comment. * * Since there are many ways in which HTML syntax can create an HTML comment, * this indicates which of those caused it. This allows the Tag Processor to * represent more from the original input document than would appear in the DOM. * * @since 6.5.0 * * @var string|null */ protected $comment_type = null; /** * What kind of text the matched text node represents, if it was subdivided. * * @see self::TEXT_IS_NULL_SEQUENCE * @see self::TEXT_IS_WHITESPACE * @see self::TEXT_IS_GENERIC * @see self::subdivide_text_appropriately * * @since 6.7.0 * * @var string */ protected $text_node_classification = self::TEXT_IS_GENERIC; /** * How many bytes from the original HTML document have been read and parsed. * * This value points to the latest byte offset in the input document which * has been already parsed. It is the internal cursor for the Tag Processor * and updates while scanning through the HTML tokens. * * @since 6.2.0 * @var int */ private $bytes_already_parsed = 0; /** * Byte offset in input document where current token starts. * * Example: * *
... * 01234 * - token starts at 0 * * @since 6.5.0 * * @var int|null */ private $token_starts_at; /** * Byte length of current token. * * Example: * *
... * 012345678901234 * - token length is 14 - 0 = 14 * * a is a token. * 0123456789 123456789 123456789 * - token length is 17 - 2 = 15 * * @since 6.5.0 * * @var int|null */ private $token_length; /** * Byte offset in input document where current tag name starts. * * Example: * *
... * 01234 * - tag name starts at 1 * * @since 6.2.0 * * @var int|null */ private $tag_name_starts_at; /** * Byte length of current tag name. * * Example: * *
... * 01234 * --- tag name length is 3 * * @since 6.2.0 * * @var int|null */ private $tag_name_length; /** * Byte offset into input document where current modifiable text starts. * * @since 6.5.0 * * @var int */ private $text_starts_at; /** * Byte length of modifiable text. * * @since 6.5.0 * * @var int */ private $text_length; /** * Whether the current tag is an opening tag, e.g.
, or a closing tag, e.g.
. * * @var bool */ private $is_closing_tag; /** * Lazily-built index of attributes found within an HTML tag, keyed by the attribute name. * * Example: * * // Supposing the parser is working through this content * // and stops after recognizing the `id` attribute. * //
* // ^ parsing will continue from this point. * $this->attributes = array( * 'id' => new WP_HTML_Attribute_Token( 'id', 9, 6, 5, 11, false ) * ); * * // When picking up parsing again, or when asking to find the * // `class` attribute we will continue and add to this array. * $this->attributes = array( * 'id' => new WP_HTML_Attribute_Token( 'id', 9, 6, 5, 11, false ), * 'class' => new WP_HTML_Attribute_Token( 'class', 23, 7, 17, 13, false ) * ); * * // Note that only the `class` attribute value is stored in the index. * // That's because it is the only value used by this class at the moment. * * @since 6.2.0 * @var WP_HTML_Attribute_Token[] */ private $attributes = array(); /** * Tracks spans of duplicate attributes on a given tag, used for removing * all copies of an attribute when calling `remove_attribute()`. * * @since 6.3.2 * * @var (WP_HTML_Span[])[]|null */ private $duplicate_attributes = null; /** * Which class names to add or remove from a tag. * * These are tracked separately from attribute updates because they are * semantically distinct, whereas this interface exists for the common * case of adding and removing class names while other attributes are * generally modified as with DOM `setAttribute` calls. * * When modifying an HTML document these will eventually be collapsed * into a single `set_attribute( 'class', $changes )` call. * * Example: * * // Add the `wp-block-group` class, remove the `wp-group` class. * $classname_updates = array( * // Indexed by a comparable class name. * 'wp-block-group' => WP_HTML_Tag_Processor::ADD_CLASS, * 'wp-group' => WP_HTML_Tag_Processor::REMOVE_CLASS * ); * * @since 6.2.0 * @var bool[] */ private $classname_updates = array(); /** * Tracks a semantic location in the original HTML which * shifts with updates as they are applied to the document. * * @since 6.2.0 * @var WP_HTML_Span[] */ protected $bookmarks = array(); const ADD_CLASS = true; const REMOVE_CLASS = false; const SKIP_CLASS = null; /** * Lexical replacements to apply to input HTML document. * * "Lexical" in this class refers to the part of this class which * operates on pure text _as text_ and not as HTML. There's a line * between the public interface, with HTML-semantic methods like * `set_attribute` and `add_class`, and an internal state that tracks * text offsets in the input document. * * When higher-level HTML methods are called, those have to transform their * operations (such as setting an attribute's value) into text diffing * operations (such as replacing the sub-string from indices A to B with * some given new string). These text-diffing operations are the lexical * updates. * * As new higher-level methods are added they need to collapse their * operations into these lower-level lexical updates since that's the * Tag Processor's internal language of change. Any code which creates * these lexical updates must ensure that they do not cross HTML syntax * boundaries, however, so these should never be exposed outside of this * class or any classes which intentionally expand its functionality. * * These are enqueued while editing the document instead of being immediately * applied to avoid processing overhead, string allocations, and string * copies when applying many updates to a single document. * * Example: * * // Replace an attribute stored with a new value, indices * // sourced from the lazily-parsed HTML recognizer. * $start = $attributes['src']->start; * $length = $attributes['src']->length; * $modifications[] = new WP_HTML_Text_Replacement( $start, $length, $new_value ); * * // Correspondingly, something like this will appear in this array. * $lexical_updates = array( * WP_HTML_Text_Replacement( 14, 28, 'https://my-site.my-domain/wp-content/uploads/2014/08/kittens.jpg' ) * ); * * @since 6.2.0 * @var WP_HTML_Text_Replacement[] */ protected $lexical_updates = array(); /** * Tracks and limits `seek()` calls to prevent accidental infinite loops. * * @since 6.2.0 * @var int * * @see WP_HTML_Tag_Processor::seek() */ protected $seek_count = 0; /** * Whether the parser should skip over an immediately-following linefeed * character, as is the case with LISTING, PRE, and TEXTAREA. * * > If the next token is a U+000A LINE FEED (LF) character token, then * > ignore that token and move on to the next one. (Newlines at the start * > of [these] elements are ignored as an authoring convenience.) * * @since 6.7.0 * * @var int|null */ private $skip_newline_at = null; /** * Constructor. * * @since 6.2.0 * * @param string $html HTML to process. */ public function __construct( $html ) { if ( ! is_string( $html ) ) { _doing_it_wrong( __METHOD__, __( 'The HTML parameter must be a string.' ), '6.9.0' ); $html = ''; } $this->html = $html; } /** * Switches parsing mode into a new namespace, such as when * encountering an SVG tag and entering foreign content. * * @since 6.7.0 * * @param string $new_namespace One of 'html', 'svg', or 'math' indicating into what * namespace the next tokens will be processed. * @return bool Whether the namespace was valid and changed. */ public function change_parsing_namespace( string $new_namespace ): bool { if ( ! in_array( $new_namespace, array( 'html', 'math', 'svg' ), true ) ) { return false; } $this->parsing_namespace = $new_namespace; return true; } /** * Finds the next tag matching the $query. * * @since 6.2.0 * @since 6.5.0 No longer processes incomplete tokens at end of document; pauses the processor at start of token. * * @param array|string|null $query { * Optional. Which tag name to find, having which class, etc. Default is to find any tag. * * @type string|null $tag_name Which tag to find, or `null` for "any tag." * @type int|null $match_offset Find the Nth tag matching all search criteria. * 1 for "first" tag, 3 for "third," etc. * Defaults to first tag. * @type string|null $class_name Tag must contain this whole class name to match. * @type string|null $tag_closers "visit" or "skip": whether to stop on tag closers, e.g.
. * } * @return bool Whether a tag was matched. * * @phpstan-impure */ public function next_tag( $query = null ): bool { $this->parse_query( $query ); $already_found = 0; do { if ( false === $this->next_token() ) { return false; } if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { continue; } if ( $this->matches() ) { ++$already_found; } } while ( $already_found < $this->sought_match_offset ); return true; } /** * Finds the next token in the HTML document. * * An HTML document can be viewed as a stream of tokens, * where tokens are things like HTML tags, HTML comments, * text nodes, etc. This method finds the next token in * the HTML document and returns whether it found one. * * If it starts parsing a token and reaches the end of the * document then it will seek to the start of the last * token and pause, returning `false` to indicate that it * failed to find a complete token. * * Possible token types, based on the HTML specification: * * - an HTML tag, whether opening, closing, or void. * - a text node - the plaintext inside tags. * - an HTML comment. * - a DOCTYPE declaration. * - a processing instruction, e.g. ``. * * The Tag Processor currently only supports the tag token. * * @since 6.5.0 * @since 6.7.0 Recognizes CDATA sections within foreign content. * * @return bool Whether a token was parsed. */ public function next_token(): bool { return $this->base_class_next_token(); } /** * Internal method which finds the next token in the HTML document. * * This method is a protected internal function which implements the logic for * finding the next token in a document. It exists so that the parser can update * its state without affecting the location of the cursor in the document and * without triggering subclass methods for things like `next_token()`, e.g. when * applying patches before searching for the next token. * * @since 6.5.0 * @ignore * * @return bool Whether a token was parsed. */ private function base_class_next_token(): bool { $was_at = $this->bytes_already_parsed; $this->after_tag(); // Don't proceed if there's nothing more to scan. if ( self::STATE_COMPLETE === $this->parser_state || self::STATE_INCOMPLETE_INPUT === $this->parser_state ) { return false; } /* * The next step in the parsing loop determines the parsing state; * clear it so that state doesn't linger from the previous step. */ $this->parser_state = self::STATE_READY; if ( $this->bytes_already_parsed >= strlen( $this->html ) ) { $this->parser_state = self::STATE_COMPLETE; return false; } // Find the next tag if it exists. if ( false === $this->parse_next_tag() ) { if ( self::STATE_INCOMPLETE_INPUT === $this->parser_state ) { $this->bytes_already_parsed = $was_at; } return false; } /* * For legacy reasons the rest of this function handles tags and their * attributes. If the processor has reached the end of the document * or if it matched any other token then it should return here to avoid * attempting to process tag-specific syntax. */ if ( self::STATE_INCOMPLETE_INPUT !== $this->parser_state && self::STATE_COMPLETE !== $this->parser_state && self::STATE_MATCHED_TAG !== $this->parser_state ) { return true; } // Parse all of its attributes. while ( $this->parse_next_attribute() ) { continue; } // Ensure that the tag closes before the end of the document. if ( self::STATE_INCOMPLETE_INPUT === $this->parser_state || $this->bytes_already_parsed >= strlen( $this->html ) ) { // Does this appropriately clear state (parsed attributes)? $this->parser_state = self::STATE_INCOMPLETE_INPUT; $this->bytes_already_parsed = $was_at; return false; } $tag_ends_at = strpos( $this->html, '>', $this->bytes_already_parsed ); if ( false === $tag_ends_at ) { $this->parser_state = self::STATE_INCOMPLETE_INPUT; $this->bytes_already_parsed = $was_at; return false; } $this->parser_state = self::STATE_MATCHED_TAG; $this->bytes_already_parsed = $tag_ends_at + 1; $this->token_length = $this->bytes_already_parsed - $this->token_starts_at; /* * Certain tags require additional processing. The first-letter pre-check * avoids unnecessary string allocation when comparing the tag names. * * - IFRAME * - LISTING (deprecated) * - NOEMBED (deprecated) * - NOFRAMES (deprecated) * - PRE * - SCRIPT * - STYLE * - TEXTAREA * - TITLE * - XMP (deprecated) */ if ( $this->is_closing_tag || 'html' !== $this->parsing_namespace || 1 !== strspn( $this->html, 'iIlLnNpPsStTxX', $this->tag_name_starts_at, 1 ) ) { return true; } $tag_name = $this->get_tag(); /* * For LISTING, PRE, and TEXTAREA, the first linefeed of an immediately-following * text node is ignored as an authoring convenience. * * @see static::skip_newline_at */ if ( 'LISTING' === $tag_name || 'PRE' === $tag_name ) { $this->skip_newline_at = $this->bytes_already_parsed; return true; } /* * There are certain elements whose children are not DATA but are instead * RCDATA or RAWTEXT. These cannot contain other elements, and the contents * are parsed as plaintext, with character references decoded in RCDATA but * not in RAWTEXT. * * These elements are described here as "self-contained" or special atomic * elements whose end tag is consumed with the opening tag, and they will * contain modifiable text inside of them. * * Preserve the opening tag pointers, as these will be overwritten * when finding the closing tag. They will be reset after finding * the closing to tag to point to the opening of the special atomic * tag sequence. */ $tag_name_starts_at = $this->tag_name_starts_at; $tag_name_length = $this->tag_name_length; $tag_ends_at = $this->token_starts_at + $this->token_length; $attributes = $this->attributes; $duplicate_attributes = $this->duplicate_attributes; // Find the closing tag if necessary. switch ( $tag_name ) { case 'SCRIPT': $found_closer = $this->skip_script_data(); break; case 'TEXTAREA': case 'TITLE': $found_closer = $this->skip_rcdata( $tag_name ); break; /* * In the browser this list would include the NOSCRIPT element, * but the Tag Processor is an environment with the scripting * flag disabled, meaning that it needs to descend into the * NOSCRIPT element to be able to properly process what will be * sent to a browser. * * Note that this rule makes HTML5 syntax incompatible with XML, * because the parsing of this token depends on client application. * The NOSCRIPT element cannot be represented in the XHTML syntax. */ case 'IFRAME': case 'NOEMBED': case 'NOFRAMES': case 'STYLE': case 'XMP': $found_closer = $this->skip_rawtext( $tag_name ); break; // No other tags should be treated in their entirety here. default: return true; } if ( ! $found_closer ) { $this->parser_state = self::STATE_INCOMPLETE_INPUT; $this->bytes_already_parsed = $was_at; return false; } /* * The values here look like they reference the opening tag but they reference * the closing tag instead. This is why the opening tag values were stored * above in a variable. It reads confusingly here, but that's because the * functions that skip the contents have moved all the internal cursors past * the inner content of the tag. */ $this->token_starts_at = $was_at; $this->token_length = $this->bytes_already_parsed - $this->token_starts_at; $this->text_starts_at = $tag_ends_at; $this->text_length = $this->tag_name_starts_at - $this->text_starts_at; $this->tag_name_starts_at = $tag_name_starts_at; $this->tag_name_length = $tag_name_length; $this->attributes = $attributes; $this->duplicate_attributes = $duplicate_attributes; return true; } /** * Whether the processor paused because the input HTML document ended * in the middle of a syntax element, such as in the middle of a tag. * * Example: * * $processor = new WP_HTML_Tag_Processor( '" ); * $p->next_tag(); * foreach ( $p->class_list() as $class_name ) { * echo "{$class_name} "; * } * // Outputs: "free lang-en " * * @since 6.4.0 * * @return Generator */ public function class_list() { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return; } /** @var string $class contains the string value of the class attribute, with character references decoded. */ $class = $this->get_attribute( 'class' ); if ( ! is_string( $class ) ) { return; } $seen = array(); $is_quirks = self::QUIRKS_MODE === $this->compat_mode; $at = 0; while ( $at < strlen( $class ) ) { // Skip past any initial boundary characters. $at += strspn( $class, " \t\f\r\n", $at ); if ( $at >= strlen( $class ) ) { return; } // Find the byte length until the next boundary. $length = strcspn( $class, " \t\f\r\n", $at ); if ( 0 === $length ) { return; } $name = str_replace( "\x00", "\u{FFFD}", substr( $class, $at, $length ) ); if ( $is_quirks ) { $name = strtolower( $name ); } $at += $length; /* * It's expected that the number of class names for a given tag is relatively small. * Given this, it is probably faster overall to scan an array for a value rather * than to use the class name as a key and check if it's a key of $seen. */ if ( in_array( $name, $seen, true ) ) { continue; } $seen[] = $name; yield $name; } } /** * Returns if a matched tag contains the given ASCII case-insensitive class name. * * @since 6.4.0 * * @param string $wanted_class Look for this CSS class name, ASCII case-insensitive. * @return bool|null Whether the matched tag contains the given class name, or null if not matched. */ public function has_class( $wanted_class ): ?bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return null; } $case_insensitive = self::QUIRKS_MODE === $this->compat_mode; $wanted_length = strlen( $wanted_class ); foreach ( $this->class_list() as $class_name ) { if ( strlen( $class_name ) === $wanted_length && 0 === substr_compare( $class_name, $wanted_class, 0, strlen( $wanted_class ), $case_insensitive ) ) { return true; } } return false; } /** * Sets a bookmark in the HTML document. * * Bookmarks represent specific places or tokens in the HTML * document, such as a tag opener or closer. When applying * edits to a document, such as setting an attribute, the * text offsets of that token may shift; the bookmark is * kept updated with those shifts and remains stable unless * the entire span of text in which the token sits is removed. * * Release bookmarks when they are no longer needed. * * Example: * *

Surprising fact you may not know!

* ^ ^ * \-|-- this `H2` opener bookmark tracks the token * *

Surprising fact you may no… * ^ ^ * \-|-- it shifts with edits * * Bookmarks provide the ability to seek to a previously-scanned * place in the HTML document. This avoids the need to re-scan * the entire document. * * Example: * *
  • One
  • Two
  • Three
* ^^^^ * want to note this last item * * $p = new WP_HTML_Tag_Processor( $html ); * $in_list = false; * while ( $p->next_tag( array( 'tag_closers' => $in_list ? 'visit' : 'skip' ) ) ) { * if ( 'UL' === $p->get_tag() ) { * if ( $p->is_tag_closer() ) { * $in_list = false; * $p->set_bookmark( 'resume' ); * if ( $p->seek( 'last-li' ) ) { * $p->add_class( 'last-li' ); * } * $p->seek( 'resume' ); * $p->release_bookmark( 'last-li' ); * $p->release_bookmark( 'resume' ); * } else { * $in_list = true; * } * } * * if ( 'LI' === $p->get_tag() ) { * $p->set_bookmark( 'last-li' ); * } * } * * Bookmarks intentionally hide the internal string offsets * to which they refer. They are maintained internally as * updates are applied to the HTML document and therefore * retain their "position" - the location to which they * originally pointed. The inability to use bookmarks with * functions like `substr` is therefore intentional to guard * against accidentally breaking the HTML. * * Because bookmarks allocate memory and require processing * for every applied update, they are limited and require * a name. They should not be created with programmatically-made * names, such as "li_{$index}" with some loop. As a general * rule they should only be created with string-literal names * like "start-of-section" or "last-paragraph". * * Bookmarks are a powerful tool to enable complicated behavior. * Consider double-checking that you need this tool if you are * reaching for it, as inappropriate use could lead to broken * HTML structure or unwanted processing overhead. * * @since 6.2.0 * * @param string $name Identifies this particular bookmark. * @return bool Whether the bookmark was successfully created. */ public function set_bookmark( $name ): bool { // It only makes sense to set a bookmark if the parser has paused on a concrete token. if ( self::STATE_COMPLETE === $this->parser_state || self::STATE_INCOMPLETE_INPUT === $this->parser_state ) { return false; } if ( ! array_key_exists( $name, $this->bookmarks ) && count( $this->bookmarks ) >= static::MAX_BOOKMARKS ) { _doing_it_wrong( __METHOD__, __( 'Too many bookmarks: cannot create any more.' ), '6.2.0' ); return false; } $this->bookmarks[ $name ] = new WP_HTML_Span( $this->token_starts_at, $this->token_length ); return true; } /** * Removes a bookmark that is no longer needed. * * Releasing a bookmark frees up the small * performance overhead it requires. * * @param string $name Name of the bookmark to remove. * @return bool Whether the bookmark already existed before removal. */ public function release_bookmark( $name ): bool { if ( ! array_key_exists( $name, $this->bookmarks ) ) { return false; } unset( $this->bookmarks[ $name ] ); return true; } /** * Skips contents of generic rawtext elements. * * @since 6.3.2 * @ignore * * @see https://html.spec.whatwg.org/#generic-raw-text-element-parsing-algorithm * * @param string $tag_name The uppercase tag name which will close the RAWTEXT region. * @return bool Whether an end to the RAWTEXT region was found before the end of the document. */ private function skip_rawtext( string $tag_name ): bool { /* * These two functions distinguish themselves on whether character references are * decoded, and since functionality to read the inner markup isn't supported, it's * not necessary to implement these two functions separately. */ return $this->skip_rcdata( $tag_name ); } /** * Skips contents of RCDATA elements, namely title and textarea tags. * * @since 6.2.0 * @ignore * * @see https://html.spec.whatwg.org/multipage/parsing.html#rcdata-state * * @param string $tag_name The uppercase tag name which will close the RCDATA region. * @return bool Whether an end to the RCDATA region was found before the end of the document. */ private function skip_rcdata( string $tag_name ): bool { $html = $this->html; $doc_length = strlen( $html ); $tag_length = strlen( $tag_name ); $at = $this->bytes_already_parsed; while ( false !== $at && $at < $doc_length ) { $at = strpos( $this->html, 'tag_name_starts_at = $at; // Fail if there is no possible tag closer. if ( false === $at || ( $at + $tag_length ) >= $doc_length ) { return false; } $at += 2; /* * Find a case-insensitive match to the tag name. * * Because tag names are limited to US-ASCII there is no * need to perform any kind of Unicode normalization when * comparing; any character which could be impacted by such * normalization could not be part of a tag name. */ for ( $i = 0; $i < $tag_length; $i++ ) { $tag_char = $tag_name[ $i ]; $html_char = $html[ $at + $i ]; if ( $html_char !== $tag_char && strtoupper( $html_char ) !== $tag_char ) { $at += $i; continue 2; } } $at += $tag_length; $this->bytes_already_parsed = $at; if ( $at >= strlen( $html ) ) { return false; } /* * Ensure that the tag name terminates to avoid matching on * substrings of a longer tag name. For example, the sequence * "' !== $c ) { continue; } while ( $this->parse_next_attribute() ) { continue; } $at = $this->bytes_already_parsed; if ( $at >= strlen( $this->html ) ) { return false; } if ( '>' === $html[ $at ] ) { $this->bytes_already_parsed = $at + 1; return true; } if ( $at + 1 >= strlen( $this->html ) ) { return false; } if ( '/' === $html[ $at ] && '>' === $html[ $at + 1 ] ) { $this->bytes_already_parsed = $at + 2; return true; } } return false; } /** * Skips contents of script tags. * * @since 6.2.0 * @ignore * * @return bool Whether the script tag was closed before the end of the document. */ private function skip_script_data(): bool { $state = 'unescaped'; $html = $this->html; $doc_length = strlen( $html ); $at = $this->bytes_already_parsed; while ( false !== $at && $at < $doc_length ) { $at += strcspn( $html, '-<', $at ); /* * Optimization: Terminating a complete script element requires at least eight * additional bytes in the document. Some checks below may cause local escaped * state transitions when processing shorter strings, but those transitions are * irrelevant if the script tag is incomplete and the function must return false. * * This may need updating if those transitions become significant or exported from * this function in some way, such as when building safe methods to embed JavaScript * or data inside a SCRIPT element. * * $at may be here. * ↓ * ... * ╰──┬───╯ * $at + 8 additional bytes are required for a non-false return value. * * This single check eliminates the need to check lengths for the shorter spans: * * $at may be here. * ↓ * * ├╯ * $at + 2 additional characters does not require a length check. * * The transition from "escaped" to "unescaped" is not relevant if the document ends: * * $at may be here. * ↓ * ` won’t break the script; in these * cases, updates will be rejected and it’s up to calling code to perform * language-specific escaping or workarounds. Similarly, it will not allow * setting content into a comment which would prematurely terminate the comment. * * Example: * * // Add a preface to all STYLE contents. * while ( $processor->next_tag( 'STYLE' ) ) { * $style = $processor->get_modifiable_text(); * $processor->set_modifiable_text( "// Made with love on the World Wide Web\n{$style}" ); * } * * // Replace smiley text with Emoji smilies. * while ( $processor->next_token() ) { * if ( '#text' !== $processor->get_token_name() ) { * continue; * } * * $chunk = $processor->get_modifiable_text(); * if ( ! str_contains( $chunk, ':)' ) ) { * continue; * } * * $processor->set_modifiable_text( str_replace( ':)', '🙂', $chunk ) ); * } * * This function handles all necessary HTML encoding. Provide normal, unescaped string values. * The HTML API will encode the strings appropriately so that the browser will interpret them * as the intended value. * * Example: * * // Renders as “Eggs & Milk” in a browser, encoded as `

Eggs & Milk

`. * $processor->set_modifiable_text( 'Eggs & Milk' ); * * // Renders as “Eggs & Milk” in a browser, encoded as `

Eggs &amp; Milk

`. * $processor->set_modifiable_text( 'Eggs & Milk' ); * * @since 6.7.0 * @since 6.9.0 Escapes all character references instead of trying to avoid double-escaping. * * @param string $plaintext_content New text content to represent in the matched token. * @return bool Whether the text was able to update. */ public function set_modifiable_text( string $plaintext_content ): bool { if ( self::STATE_TEXT_NODE === $this->parser_state ) { $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement( $this->text_starts_at, $this->text_length, strtr( $plaintext_content, array( '<' => '<', '>' => '>', '&' => '&', '"' => '"', "'" => ''', ) ) ); return true; } // Comment data is not encoded. if ( self::STATE_COMMENT === $this->parser_state && self::COMMENT_AS_HTML_COMMENT === $this->comment_type ) { // Check if the text could close the comment. if ( 1 === preg_match( '/--!?>/', $plaintext_content ) ) { return false; } $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement( $this->text_starts_at, $this->text_length, $plaintext_content ); return true; } /* * The rest of this function handles modifiable text for special "atomic" HTML elements. * Only tags in the HTML namespace should be processed. */ if ( self::STATE_MATCHED_TAG !== $this->parser_state || 'html' !== $this->get_namespace() ) { return false; } switch ( $this->get_tag() ) { case 'SCRIPT': $script_content_type = $this->get_script_content_type(); switch ( $script_content_type ) { case 'javascript': case 'json': $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement( $this->text_starts_at, $this->text_length, self::escape_javascript_script_contents( $plaintext_content ) ); return true; } /* * If the script’s content type isn’t recognized and understandable then it’s * impossible to guarantee that escaping the content won’t cause runtime breakage. * For instance, if the script content type were PHP code then escaping with * `\u0073` would not be met by unescaping; rather, it could result in corrupted * data or even syntax errors. * * Because of this, content which could potentially modify the SCRIPT tag’s * HTML structure is rejected here. It’s the responsibility of calling code to * perform whatever semantic escaping is necessary to avoid problematic strings. */ if ( false !== stripos( $plaintext_content, 'lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement( $this->text_starts_at, $this->text_length, $plaintext_content ); return true; case 'STYLE': $plaintext_content = preg_replace_callback( '~style)~i', static function ( $tag_match ) { return "\\3c\\2f{$tag_match['TAG_NAME']}"; }, $plaintext_content ); $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement( $this->text_starts_at, $this->text_length, $plaintext_content ); return true; case 'TEXTAREA': case 'TITLE': $plaintext_content = preg_replace_callback( "~{$this->get_tag()})~i", static function ( $tag_match ) { return "</{$tag_match['TAG_NAME']}"; }, $plaintext_content ); /* * HTML ignores a single leading newline in this context. If a leading newline * is intended, preserve it by adding an extra newline. */ if ( 'TEXTAREA' === $this->get_tag() && 1 === strspn( $plaintext_content, "\n\r", 0, 1 ) ) { $plaintext_content = "\n{$plaintext_content}"; } /* * These don't _need_ to be escaped, but since they are decoded it's * safe to leave them escaped and this can prevent other code from * naively detecting tags within the contents. * * @todo It would be useful to prefix a multiline replacement text * with a newline, but not necessary. This is for aesthetics. */ $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement( $this->text_starts_at, $this->text_length, $plaintext_content ); return true; } return false; } /** * Returns the content type of the currently-matched HTML SCRIPT tag, if matched and * recognized, otherwise returns `null` to indicate an unrecognized content type. * * An HTML SCRIPT tag is a normal SCRIPT tag, but there can be SCRIPT elements inside * SVG and MathML elements as well, and these have different parsing rules than those * in general HTML. For this reason, no content-type inference is performed on those. * * Note! This concept is related but distinct from the MIME type of the script. * Parsing MUST match the specific algorithm in the HTML specification, which * relies on exact string comparison in some cases. MIME type decoding may be * performed on SVG or MathML SCRIPT tags. * * Only 'javascript' and 'json' content types are currently recognized. * * @see https://html.spec.whatwg.org/multipage/scripting.html#prepare-the-script-element * * @since 7.0.0 * @ignore * * @return 'javascript'|'json'|null Type of script element content if matched and recognized. */ private function get_script_content_type(): ?string { // SVG and MathML SCRIPT elements are not recognized. if ( 'SCRIPT' !== $this->get_tag() || $this->get_namespace() !== 'html' ) { return null; } /* * > If any of the following are true: * > - el has a type attribute whose value is the empty string; * > - el has no type attribute but it has a language attribute and that attribute's * > value is the empty string; or * > - el has neither a type attribute nor a language attribute, * > then let the script block's type string for this script element be "text/javascript". */ $type = $this->get_attribute( 'type' ); $lang = $this->get_attribute( 'language' ); if ( true === $type || '' === $type ) { return 'javascript'; } if ( null === $type && ( null === $lang || true === $lang || '' === $lang ) ) { return 'javascript'; } /* * > Otherwise, if el has a type attribute, then let the script block's type string be * > the value of that attribute with leading and trailing ASCII whitespace stripped. * > Otherwise, el has a non-empty language attribute; let the script block's type string * > be the concatenation of "text/" and the value of el's language attribute. */ $type_string = is_string( $type ) ? trim( $type, " \t\f\r\n" ) : "text/{$lang}"; // All matches are ASCII case-insensitive; eagerly lower-case for comparison. $type_string = strtolower( $type_string ); /* * > If the script block's type string is a JavaScript MIME type essence match, then * > set el's type to "classic". * * > A string is a JavaScript MIME type essence match if it is an ASCII case-insensitive * > match for one of the JavaScript MIME type essence strings. * * > A JavaScript MIME type is any MIME type whose essence is one of the following: * > * > - application/ecmascript * > - application/javascript * > - application/x-ecmascript * > - application/x-javascript * > - text/ecmascript * > - text/javascript * > - text/javascript1.0 * > - text/javascript1.1 * > - text/javascript1.2 * > - text/javascript1.3 * > - text/javascript1.4 * > - text/javascript1.5 * > - text/jscript * > - text/livescript * > - text/x-ecmascript * > - text/x-javascript * * @see https://mimesniff.spec.whatwg.org/#javascript-mime-type-essence-match * @see https://mimesniff.spec.whatwg.org/#javascript-mime-type */ switch ( $type_string ) { case 'application/ecmascript': case 'application/javascript': case 'application/x-ecmascript': case 'application/x-javascript': case 'text/ecmascript': case 'text/javascript': case 'text/javascript1.0': case 'text/javascript1.1': case 'text/javascript1.2': case 'text/javascript1.3': case 'text/javascript1.4': case 'text/javascript1.5': case 'text/jscript': case 'text/livescript': case 'text/x-ecmascript': case 'text/x-javascript': return 'javascript'; /* * > Otherwise, if the script block's type string is an ASCII case-insensitive match for * > the string "module", then set el's type to "module". * * A module is evaluated as JavaScript. */ case 'module': return 'javascript'; /* * > Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap", then set el's type to "importmap". * > Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "speculationrules", then set el's type to "speculationrules". * * These conditions indicate JSON content. */ case 'importmap': case 'speculationrules': return 'json'; /** @todo Rely on a full MIME parser for determining JSON content. */ case 'application/json': case 'text/json': return 'json'; } /* * > Otherwise, return. (No script is executed, and el's type is left as null.) */ return null; } /** * Escape JavaScript and JSON script tag contents. * * Ensure that the script contents cannot modify the HTML structure or break out * of its containing SCRIPT element. JavaScript and JSON may both be escaped with * the same rules, even though there are additional escaping measures available * to JavaScript source code which aren’t applicable to serialized JSON data. * * A simple method safely escapes all content except for a few extremely rare and * unlikely exceptions: prevent the appearance of `` cannot appear to * prematurely close the tag, and the problematic double-escaped state becomes * unreachable. A JavaScript engine or JSON decoder will then decode the Unicode * escape (`\u0073`) back into its original plaintext value, but only after having * been safely extracted from the HTML. * * While it may seem tempting to replace the `<` character instead, doing so would * break JavaScript syntax. The `<` character is used in comparison operators and * other JavaScript syntax; replacing it would break valid JavaScript. Replacing * only the `s` in `" * …becomes… * // A comment: "" * * #### Tagged templates. * * Tagged templates “enable the embedding of arbitrary string content, where escape * sequences may follow a different syntax.” For example, they can aid representing * a RegExp pattern or LaTex snippet within a JavaScript string, where the string * escape characters might get noisy and distracting. * * Example: * * console.log( 'A \notin B' ); // Prints a newline because of the "\n". * console.log( 'A \\notin B' ); // Prints "A \notin B". * console.log( String.raw`A \notin B` ); // Prints "A \notin B". * * This means that if `` ); // Prematurely closes the SCRIPT element. * console.log( String.raw`` ); // Prints "/.test( '` ); // !!UNSAFE!! Will be escaped. * console.log( String.raw`` ); // "" * console.log( String.raw`` ); // "" * console.log( String.raw`` ); // "" * console.log( '' ); // "" * console.log( "\x3C/script>" ); // "" * console.log( "<\/script>" ); // "" * * The following graph is a simplified interpretation of how HTML interprets the contents * of a SCRIPT tag and identifies the closing tag. It is useful to understand what text * is dangerous inside of a SCRIPT tag and why different approaches to escaping work. * * Open script * │ * ▼ * ╔═════════════════════════════════════════╗ ╰─────╮ * │ ▼ │ │ * │ ┌─────────────────┴───────────────────────┐ │ * │ * │ │ ', known * as “tag-name-terminating characters.” This sequence forms the start * of what could be a SCRIPT opening or closing tag. * * @see https://html.spec.whatwg.org/#restrictions-for-contents-of-script-elements * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#specifications * @see wp_html_api_script_element_escaping_diagram_source() * * @since 7.0.0 * @ignore * * @param string $sourcecode Raw contents intended to be serialized into an HTML SCRIPT element. * @return string Escaped form of input contents which will not lead to premature closing of the containing SCRIPT element. */ private static function escape_javascript_script_contents( string $sourcecode ): string { $at = 0; $was_at = 0; $end = strlen( $sourcecode ); $escaped = ''; /* * Replace all instances of the ASCII case-insensitive match of "", by using a * character replacement for the "s" (or the "S"). */ while ( $at < $end ) { $tag_at = strpos( $sourcecode, '<', $at ); if ( false === $tag_at ) { break; } $tag_name_at = $tag_at + 1; $has_closing_slash = $tag_name_at < $end && '/' === $sourcecode[ $tag_name_at ]; $tag_name_at += $has_closing_slash ? 1 : 0; if ( 0 !== substr_compare( $sourcecode, 'script', $tag_name_at, 6, true ) ) { $at = $tag_at + 1; continue; } if ( 1 !== strspn( $sourcecode, " \t\f\r\n/>", $tag_name_at + 6, 1 ) ) { $at = $tag_name_at + 6; continue; } $escaped .= substr( $sourcecode, $was_at, $tag_name_at - $was_at ); $escaped .= 's' === $sourcecode[ $tag_name_at ] ? '\u0073' : '\u0053'; $was_at = $tag_name_at + 1; $at = $tag_name_at + 7; } if ( '' === $escaped ) { return $sourcecode; } if ( $was_at < $end ) { $escaped .= substr( $sourcecode, $was_at ); } return $escaped; } /** * Updates or creates a new attribute on the currently matched tag with the passed value. * * This function handles all necessary HTML encoding. Provide normal, unescaped string values. * The HTML API will encode the strings appropriately so that the browser will interpret them * as the intended value. * * Example: * * // Renders “Eggs & Milk” in a browser, encoded as ``. * $processor->set_attribute( 'title', 'Eggs & Milk' ); * * // Renders “Eggs & Milk” in a browser, encoded as ``. * $processor->set_attribute( 'title', 'Eggs & Milk' ); * * // Renders `true` as ``. * $processor->set_attribute( 'title', true ); * * // Renders without the attribute for `false` as ``. * $processor->set_attribute( 'title', false ); * * Special handling is provided for boolean attribute values: * - When `true` is passed as the value, then only the attribute name is added to the tag. * - When `false` is passed, the attribute gets removed if it existed before. * * @since 6.2.0 * @since 6.2.1 Fix: Only create a single update for multiple calls with case-variant attribute names. * @since 6.9.0 Escapes all character references instead of trying to avoid double-escaping. * * @param string $name The attribute name to target. * @param string|bool $value The new attribute value. * @return bool Whether an attribute value was set. */ public function set_attribute( $name, $value ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag ) { return false; } $name_length = strlen( $name ); /** * WordPress rejects more characters than are strictly forbidden * in HTML5. This is to prevent additional security risks deeper * in the WordPress and plugin stack. Specifically the following * are not allowed to be set as part of an HTML attribute name: * * - greater-than “>” * - ampersand “&” * * @see https://html.spec.whatwg.org/#attributes-2 */ if ( 0 === $name_length || // Syntax-like characters. strcspn( $name, '"\'>& The values "true" and "false" are not allowed on boolean attributes. * > To represent a false value, the attribute has to be omitted altogether. * - HTML5 spec, https://html.spec.whatwg.org/#boolean-attributes */ if ( false === $value ) { return $this->remove_attribute( $name ); } if ( true === $value ) { $updated_attribute = $name; } else { $comparable_name = strtolower( $name ); /** * Escape attribute values appropriately. * * @see https://html.spec.whatwg.org/#attributes-3 */ $escaped_new_value = in_array( $comparable_name, wp_kses_uri_attributes(), true ) ? esc_url( $value ) : strtr( $value, array( '<' => '<', '>' => '>', '&' => '&', '"' => '"', "'" => ''', ) ); // If the escaping functions wiped out the update, reject it and indicate it was rejected. if ( '' === $escaped_new_value && '' !== $value ) { return false; } $updated_attribute = "{$name}=\"{$escaped_new_value}\""; } /* * > There must never be two or more attributes on * > the same start tag whose names are an ASCII * > case-insensitive match for each other. * - HTML 5 spec * * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2:ascii-case-insensitive */ $comparable_name = strtolower( $name ); if ( isset( $this->attributes[ $comparable_name ] ) ) { /* * Update an existing attribute. * * Example – set attribute id to "new" in
: * *
* ^-------------^ * start end * replacement: `id="new"` * * Result:
*/ $existing_attribute = $this->attributes[ $comparable_name ]; $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement( $existing_attribute->start, $existing_attribute->length, $updated_attribute ); } else { /* * Create a new attribute at the tag's name end. * * Example – add attribute id="new" to
: * *
* ^ * start and end * replacement: ` id="new"` * * Result:
*/ $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement( $this->tag_name_starts_at + $this->tag_name_length, 0, ' ' . $updated_attribute ); } /* * Any calls to update the `class` attribute directly should wipe out any * enqueued class changes from `add_class` and `remove_class`. */ if ( 'class' === $comparable_name && ! empty( $this->classname_updates ) ) { $this->classname_updates = array(); } return true; } /** * Remove an attribute from the currently-matched tag. * * @since 6.2.0 * * @param string $name The attribute name to remove. * @return bool Whether an attribute was removed. */ public function remove_attribute( $name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag ) { return false; } /* * > There must never be two or more attributes on * > the same start tag whose names are an ASCII * > case-insensitive match for each other. * - HTML 5 spec * * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2:ascii-case-insensitive */ $name = strtolower( $name ); /* * Any calls to update the `class` attribute directly should wipe out any * enqueued class changes from `add_class` and `remove_class`. */ if ( 'class' === $name && count( $this->classname_updates ) !== 0 ) { $this->classname_updates = array(); } /* * If updating an attribute that didn't exist in the input * document, then remove the enqueued update and move on. * * For example, this might occur when calling `remove_attribute()` * after calling `set_attribute()` for the same attribute * and when that attribute wasn't originally present. */ if ( ! isset( $this->attributes[ $name ] ) ) { if ( isset( $this->lexical_updates[ $name ] ) ) { unset( $this->lexical_updates[ $name ] ); } return false; } /* * Removes an existing tag attribute. * * Example – remove the attribute id from
: *
* ^-------------^ * start end * replacement: `` * * Result:
*/ $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement( $this->attributes[ $name ]->start, $this->attributes[ $name ]->length, '' ); // Removes any duplicated attributes if they were also present. foreach ( $this->duplicate_attributes[ $name ] ?? array() as $attribute_token ) { $this->lexical_updates[] = new WP_HTML_Text_Replacement( $attribute_token->start, $attribute_token->length, '' ); } return true; } /** * Adds a new class name to the currently matched tag. * * @since 6.2.0 * * @param string $class_name The class name to add. * @return bool Whether the class was set to be added. */ public function add_class( $class_name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag ) { return false; } if ( self::QUIRKS_MODE !== $this->compat_mode ) { $this->classname_updates[ $class_name ] = self::ADD_CLASS; return true; } /* * Because class names are matched ASCII-case-insensitively in quirks mode, * this needs to see if a case variant of the given class name is already * enqueued and update that existing entry, if so. This picks the casing of * the first-provided class name for all lexical variations. */ $class_name_length = strlen( $class_name ); foreach ( $this->classname_updates as $updated_name => $action ) { if ( strlen( $updated_name ) === $class_name_length && 0 === substr_compare( $updated_name, $class_name, 0, $class_name_length, true ) ) { $this->classname_updates[ $updated_name ] = self::ADD_CLASS; return true; } } $this->classname_updates[ $class_name ] = self::ADD_CLASS; return true; } /** * Removes a class name from the currently matched tag. * * @since 6.2.0 * * @param string $class_name The class name to remove. * @return bool Whether the class was set to be removed. */ public function remove_class( $class_name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag ) { return false; } if ( self::QUIRKS_MODE !== $this->compat_mode ) { $this->classname_updates[ $class_name ] = self::REMOVE_CLASS; return true; } /* * Because class names are matched ASCII-case-insensitively in quirks mode, * this needs to see if a case variant of the given class name is already * enqueued and update that existing entry, if so. This picks the casing of * the first-provided class name for all lexical variations. */ $class_name_length = strlen( $class_name ); foreach ( $this->classname_updates as $updated_name => $action ) { if ( strlen( $updated_name ) === $class_name_length && 0 === substr_compare( $updated_name, $class_name, 0, $class_name_length, true ) ) { $this->classname_updates[ $updated_name ] = self::REMOVE_CLASS; return true; } } $this->classname_updates[ $class_name ] = self::REMOVE_CLASS; return true; } /** * Returns the string representation of the HTML Tag Processor. * * @since 6.2.0 * * @see WP_HTML_Tag_Processor::get_updated_html() * * @return string The processed HTML. */ public function __toString(): string { return $this->get_updated_html(); } /** * Returns the string representation of the HTML Tag Processor. * * @since 6.2.0 * @since 6.2.1 Shifts the internal cursor corresponding to the applied updates. * @since 6.4.0 No longer calls subclass method `next_tag()` after updating HTML. * * @return string The processed HTML. */ public function get_updated_html(): string { $requires_no_updating = 0 === count( $this->classname_updates ) && 0 === count( $this->lexical_updates ); /* * When there is nothing more to update and nothing has already been * updated, return the original document and avoid a string copy. */ if ( $requires_no_updating ) { return $this->html; } /* * Keep track of the position right before the current tag. This will * be necessary for reparsing the current tag after updating the HTML. */ $before_current_tag = $this->token_starts_at ?? 0; /* * 1. Apply the enqueued edits and update all the pointers to reflect those changes. */ $this->class_name_updates_to_attributes_updates(); $before_current_tag += $this->apply_attributes_updates( $before_current_tag ); /* * 2. Rewind to before the current tag and reparse to get updated attributes. * * At this point the internal cursor points to the end of the tag name. * Rewind before the tag name starts so that it's as if the cursor didn't * move; a call to `next_tag()` will reparse the recently-updated attributes * and additional calls to modify the attributes will apply at this same * location, but in order to avoid issues with subclasses that might add * behaviors to `next_tag()`, the internal methods should be called here * instead. * * It's important to note that in this specific place there will be no change * because the processor was already at a tag when this was called and it's * rewinding only to the beginning of this very tag before reprocessing it * and its attributes. * *

Previous HTMLMore HTML

* ↑ │ back up by the length of the tag name plus the opening < * └←─┘ back up by strlen("em") + 1 ==> 3 */ $this->bytes_already_parsed = $before_current_tag; $this->base_class_next_token(); return $this->html; } /** * Parses tag query input into internal search criteria. * * @since 6.2.0 * @ignore * * @param array|string|null $query { * Optional. Which tag name to find, having which class, etc. Default is to find any tag. * * @type string|null $tag_name Which tag to find, or `null` for "any tag." * @type int|null $match_offset Find the Nth tag matching all search criteria. * 1 for "first" tag, 3 for "third," etc. * Defaults to first tag. * @type string|null $class_name Tag must contain this class name to match. * @type string $tag_closers "visit" or "skip": whether to stop on tag closers, e.g.
. * } */ private function parse_query( $query ) { if ( null !== $query && $query === $this->last_query ) { return; } $this->last_query = $query; $this->sought_tag_name = null; $this->sought_class_name = null; $this->sought_match_offset = 1; $this->stop_on_tag_closers = false; // A single string value means "find the tag of this name". if ( is_string( $query ) ) { $this->sought_tag_name = $query; return; } // An empty query parameter applies no restrictions on the search. if ( null === $query ) { return; } // If not using the string interface, an associative array is required. if ( ! is_array( $query ) ) { _doing_it_wrong( __METHOD__, __( 'The query argument must be an array or a tag name.' ), '6.2.0' ); return; } if ( isset( $query['tag_name'] ) && is_string( $query['tag_name'] ) ) { $this->sought_tag_name = $query['tag_name']; } if ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) ) { $this->sought_class_name = $query['class_name']; } if ( isset( $query['match_offset'] ) && is_int( $query['match_offset'] ) && 0 < $query['match_offset'] ) { $this->sought_match_offset = $query['match_offset']; } if ( isset( $query['tag_closers'] ) ) { $this->stop_on_tag_closers = 'visit' === $query['tag_closers']; } } /** * Checks whether a given tag and its attributes match the search criteria. * * @since 6.2.0 * @ignore * * @return bool Whether the given tag and its attribute match the search criteria. */ private function matches(): bool { if ( $this->is_closing_tag && ! $this->stop_on_tag_closers ) { return false; } // Does the tag name match the requested tag name in a case-insensitive manner? if ( isset( $this->sought_tag_name ) && ( strlen( $this->sought_tag_name ) !== $this->tag_name_length || 0 !== substr_compare( $this->html, $this->sought_tag_name, $this->tag_name_starts_at, $this->tag_name_length, true ) ) ) { return false; } if ( null !== $this->sought_class_name && ! $this->has_class( $this->sought_class_name ) ) { return false; } return true; } /** * Gets DOCTYPE declaration info from a DOCTYPE token. * * DOCTYPE tokens may appear in many places in an HTML document. In most places, they are * simply ignored. The main parsing functions find the basic shape of DOCTYPE tokens but * do not perform detailed parsing. * * This method can be called to perform a full parse of the DOCTYPE token and retrieve * its information. * * @return WP_HTML_Doctype_Info|null The DOCTYPE declaration information or `null` if not * currently at a DOCTYPE node. */ public function get_doctype_info(): ?WP_HTML_Doctype_Info { if ( self::STATE_DOCTYPE !== $this->parser_state ) { return null; } return WP_HTML_Doctype_Info::from_doctype_token( substr( $this->html, $this->token_starts_at, $this->token_length ) ); } /** * Parser Ready State. * * Indicates that the parser is ready to run and waiting for a state transition. * It may not have started yet, or it may have just finished parsing a token and * is ready to find the next one. * * @since 6.5.0 * * @access private */ const STATE_READY = 'STATE_READY'; /** * Parser Complete State. * * Indicates that the parser has reached the end of the document and there is * nothing left to scan. It finished parsing the last token completely. * * @since 6.5.0 * * @access private */ const STATE_COMPLETE = 'STATE_COMPLETE'; /** * Parser Incomplete Input State. * * Indicates that the parser has reached the end of the document before finishing * a token. It started parsing a token but there is a possibility that the input * HTML document was truncated in the middle of a token. * * The parser is reset at the start of the incomplete token and has paused. There * is nothing more than can be scanned unless provided a more complete document. * * @since 6.5.0 * * @access private */ const STATE_INCOMPLETE_INPUT = 'STATE_INCOMPLETE_INPUT'; /** * Parser Matched Tag State. * * Indicates that the parser has found an HTML tag and it's possible to get * the tag name and read or modify its attributes (if it's not a closing tag). * * @since 6.5.0 * * @access private */ const STATE_MATCHED_TAG = 'STATE_MATCHED_TAG'; /** * Parser Text Node State. * * Indicates that the parser has found a text node and it's possible * to read and modify that text. * * @since 6.5.0 * * @access private */ const STATE_TEXT_NODE = 'STATE_TEXT_NODE'; /** * Parser CDATA Node State. * * Indicates that the parser has found a CDATA node and it's possible * to read and modify its modifiable text. Note that in HTML there are * no CDATA nodes outside of foreign content (SVG and MathML). Outside * of foreign content, they are treated as HTML comments. * * @since 6.5.0 * * @access private */ const STATE_CDATA_NODE = 'STATE_CDATA_NODE'; /** * Indicates that the parser has found an HTML comment and it's * possible to read and modify its modifiable text. * * @since 6.5.0 * * @access private */ const STATE_COMMENT = 'STATE_COMMENT'; /** * Indicates that the parser has found a DOCTYPE node and it's * possible to read its DOCTYPE information via `get_doctype_info()`. * * @since 6.5.0 * * @access private */ const STATE_DOCTYPE = 'STATE_DOCTYPE'; /** * Indicates that the parser has found an empty tag closer ``. * * Note that in HTML there are no empty tag closers, and they * are ignored. Nonetheless, the Tag Processor still * recognizes them as they appear in the HTML stream. * * These were historically discussed as a "presumptuous tag * closer," which would close the nearest open tag, but were * dismissed in favor of explicitly-closing tags. * * @since 6.5.0 * * @access private */ const STATE_PRESUMPTUOUS_TAG = 'STATE_PRESUMPTUOUS_TAG'; /** * Indicates that the parser has found a "funky comment" * and it's possible to read and modify its modifiable text. * * Example: * * * * * * Funky comments are tag closers with invalid tag names. Note * that in HTML these are turn into bogus comments. Nonetheless, * the Tag Processor recognizes them in a stream of HTML and * exposes them for inspection and modification. * * @since 6.5.0 * * @access private */ const STATE_FUNKY_COMMENT = 'STATE_WP_FUNKY'; /** * Indicates that a comment was created when encountering abruptly-closed HTML comment. * * Example: * * * * * @since 6.5.0 */ const COMMENT_AS_ABRUPTLY_CLOSED_COMMENT = 'COMMENT_AS_ABRUPTLY_CLOSED_COMMENT'; /** * Indicates that a comment would be parsed as a CDATA node, * were HTML to allow CDATA nodes outside of foreign content. * * Example: * * * * This is an HTML comment, but it looks like a CDATA node. * * @since 6.5.0 */ const COMMENT_AS_CDATA_LOOKALIKE = 'COMMENT_AS_CDATA_LOOKALIKE'; /** * Indicates that a comment was created when encountering * normative HTML comment syntax. * * Example: * * * * @since 6.5.0 */ const COMMENT_AS_HTML_COMMENT = 'COMMENT_AS_HTML_COMMENT'; /** * Indicates that a comment would be parsed as a Processing * Instruction node, were they to exist within HTML. * * Example: * * * * This is an HTML comment, but it looks like a CDATA node. * * @since 6.5.0 */ const COMMENT_AS_PI_NODE_LOOKALIKE = 'COMMENT_AS_PI_NODE_LOOKALIKE'; /** * Indicates that a comment was created when encountering invalid * HTML input, a so-called "bogus comment." * * Example: * * * * * @since 6.5.0 */ const COMMENT_AS_INVALID_HTML = 'COMMENT_AS_INVALID_HTML'; /** * No-quirks mode document compatibility mode. * * > In no-quirks mode, the behavior is (hopefully) the desired behavior * > described by the modern HTML and CSS specifications. * * @see self::$compat_mode * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode * * @since 6.7.0 * * @var string */ const NO_QUIRKS_MODE = 'no-quirks-mode'; /** * Quirks mode document compatibility mode. * * > In quirks mode, layout emulates behavior in Navigator 4 and Internet * > Explorer 5. This is essential in order to support websites that were * > built before the widespread adoption of web standards. * * @see self::$compat_mode * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode * * @since 6.7.0 * * @var string */ const QUIRKS_MODE = 'quirks-mode'; /** * Indicates that a span of text may contain any combination of significant * kinds of characters: NULL bytes, whitespace, and others. * * @see self::$text_node_classification * @see self::subdivide_text_appropriately * * @since 6.7.0 */ const TEXT_IS_GENERIC = 'TEXT_IS_GENERIC'; /** * Indicates that a span of text comprises a sequence only of NULL bytes. * * @see self::$text_node_classification * @see self::subdivide_text_appropriately * * @since 6.7.0 */ const TEXT_IS_NULL_SEQUENCE = 'TEXT_IS_NULL_SEQUENCE'; /** * Indicates that a span of decoded text comprises only whitespace. * * @see self::$text_node_classification * @see self::subdivide_text_appropriately * * @since 6.7.0 */ const TEXT_IS_WHITESPACE = 'TEXT_IS_WHITESPACE'; /** * Wakeup magic method. * * @since 6.9.2 */ public function __wakeup() { throw new \LogicException( __CLASS__ . ' should never be unserialized' ); } } PK\DZIIclass-wp-html-processor.phpnu[next_tag( array( 'breadcrumbs' => array( 'DIV', 'FIGURE', 'IMG' ) ) ) ) { * $processor->add_class( 'responsive-image' ); * } * * #### Breadcrumbs * * Breadcrumbs represent the stack of open elements from the root * of the document or fragment down to the currently-matched node, * if one is currently selected. Call WP_HTML_Processor::get_breadcrumbs() * to inspect the breadcrumbs for a matched tag. * * Breadcrumbs can specify nested HTML structure and are equivalent * to a CSS selector comprising tag names separated by the child * combinator, such as "DIV > FIGURE > IMG". * * Since all elements find themselves inside a full HTML document * when parsed, the return value from `get_breadcrumbs()` will always * contain any implicit outermost elements. For example, when parsing * with `create_fragment()` in the `BODY` context (the default), any * tag in the given HTML document will contain `array( 'HTML', 'BODY', … )` * in its breadcrumbs. * * Despite containing the implied outermost elements in their breadcrumbs, * tags may be found with the shortest-matching breadcrumb query. That is, * `array( 'IMG' )` matches all IMG elements and `array( 'P', 'IMG' )` * matches all IMG elements directly inside a P element. To ensure that no * partial matches erroneously match it's possible to specify in a query * the full breadcrumb match all the way down from the root HTML element. * * Example: * * $html = '
A lovely day outside
'; * // ----- Matches here. * $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'IMG' ) ) ); * * $html = '
A lovely day outside
'; * // ---- Matches here. * $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'FIGCAPTION', 'EM' ) ) ); * * $html = '
'; * // ----- Matches here, because IMG must be a direct child of the implicit BODY. * $processor->next_tag( array( 'breadcrumbs' => array( 'BODY', 'IMG' ) ) ); * * ## HTML Support * * This class implements a small part of the HTML5 specification. * It's designed to operate within its support and abort early whenever * encountering circumstances it can't properly handle. This is * the principle way in which this class remains as simple as possible * without cutting corners and breaking compliance. * * ### Supported elements * * If any unsupported element appears in the HTML input the HTML Processor * will abort early and stop all processing. This draconian measure ensures * that the HTML Processor won't break any HTML it doesn't fully understand. * * The HTML Processor supports all elements other than a specific set: * * - Any element inside a TABLE. * - Any element inside foreign content, including SVG and MATH. * - Any element outside the IN BODY insertion mode, e.g. doctype declarations, meta, links. * * ### Supported markup * * Some kinds of non-normative HTML involve reconstruction of formatting elements and * re-parenting of mis-nested elements. For example, a DIV tag found inside a TABLE * may in fact belong _before_ the table in the DOM. If the HTML Processor encounters * such a case it will stop processing. * * The following list illustrates some common examples of unexpected HTML inputs that * the HTML Processor properly parses and represents: * * - HTML with optional tags omitted, e.g. `

one

two`. * - HTML with unexpected tag closers, e.g. `

one more

`. * - Non-void tags with self-closing flag, e.g. `
the DIV is still open.
`. * - Heading elements which close open heading elements of another level, e.g. `

Closed by

`. * - Elements containing text that looks like other tags but isn't, e.g. `The <img> is plaintext`. * - SCRIPT and STYLE tags containing text that looks like HTML but isn't, e.g. ``. * - SCRIPT content which has been escaped, e.g. ``. * * ### Unsupported Features * * This parser does not report parse errors. * * Normally, when additional HTML or BODY tags are encountered in a document, if there * are any additional attributes on them that aren't found on the previous elements, * the existing HTML and BODY elements adopt those missing attribute values. This * parser does not add those additional attributes. * * In certain situations, elements are moved to a different part of the document in * a process called "adoption" and "fostering." Because the nodes move to a location * in the document that the parser had already processed, this parser does not support * these situations and will bail. * * @since 6.4.0 * * @see WP_HTML_Tag_Processor * @see https://html.spec.whatwg.org/ * @phpstan-consistent-constructor */ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** * The maximum number of bookmarks allowed to exist at any given time. * * HTML processing requires more bookmarks than basic tag processing, * so this class constant from the Tag Processor is overwritten. * * @since 6.4.0 * @since 7.0.0 Increased from 100 to 10,000 * * @var int */ const MAX_BOOKMARKS = 10_000; /** * Holds the working state of the parser, including the stack of * open elements and the stack of active formatting elements. * * Initialized in the constructor. * * @since 6.4.0 * * @var WP_HTML_Processor_State */ private $state; /** * Used to create unique bookmark names. * * This class sets a bookmark for every tag in the HTML document that it encounters. * The bookmark name is auto-generated and increments, starting with `1`. These are * internal bookmarks and are automatically released when the referring WP_HTML_Token * goes out of scope and is garbage-collected. * * @since 6.4.0 * * @see WP_HTML_Processor::$release_internal_bookmark_on_destruct * * @var int */ private $bookmark_counter = 0; /** * Stores an explanation for why something failed, if it did. * * @see self::get_last_error * * @since 6.4.0 * * @var string|null */ private $last_error = null; /** * Stores context for why the parser bailed on unsupported HTML, if it did. * * @see self::get_unsupported_exception * * @since 6.7.0 * * @var WP_HTML_Unsupported_Exception|null */ private $unsupported_exception = null; /** * Releases a bookmark when PHP garbage-collects its wrapping WP_HTML_Token instance. * * This function is created inside the class constructor so that it can be passed to * the stack of open elements and the stack of active formatting elements without * exposing it as a public method on the class. * * @since 6.4.0 * * @var Closure|null */ private $release_internal_bookmark_on_destruct = null; /** * Stores stack events which arise during parsing of the * HTML document, which will then supply the "match" events. * * @since 6.6.0 * * @var WP_HTML_Stack_Event[] */ private $element_queue = array(); /** * Stores the current breadcrumbs. * * @since 6.7.0 * * @var string[] */ private $breadcrumbs = array(); /** * Current stack event, if set, representing a matched token. * * Because the parser may internally point to a place further along in a document * than the nodes which have already been processed (some "virtual" nodes may have * appeared while scanning the HTML document), this will point at the "current" node * being processed. It comes from the front of the element queue. * * @since 6.6.0 * * @var WP_HTML_Stack_Event|null */ private $current_element = null; /** * Context node if created as a fragment parser. * * @var WP_HTML_Token|null */ private $context_node = null; /* * Public Interface Functions */ /** * Creates an HTML processor in the fragment parsing mode. * * Use this for cases where you are processing chunks of HTML that * will be found within a bigger HTML document, such as rendered * block output that exists within a post, `the_content` inside a * rendered site layout. * * Fragment parsing occurs within a context, which is an HTML element * that the document will eventually be placed in. It becomes important * when special elements have different rules than others, such as inside * a TEXTAREA or a TITLE tag where things that look like tags are text, * or inside a SCRIPT tag where things that look like HTML syntax are JS. * * The context value should be a representation of the tag into which the * HTML is found. For most cases this will be the body element. The HTML * form is provided because a context element may have attributes that * impact the parse, such as with a SCRIPT tag and its `type` attribute. * * ## Current HTML Support * * - The only supported context is ``, which is the default value. * - The only supported document encoding is `UTF-8`, which is the default value. * * @since 6.4.0 * @since 6.6.0 Returns `static` instead of `self` so it can create subclass instances. * * @param string $html Input HTML fragment to process. * @param string $context Context element for the fragment, must be default of ``. * @param string $encoding Text encoding of the document; must be default of 'UTF-8'. * @return static|null The created processor if successful, otherwise null. */ public static function create_fragment( $html, $context = '', $encoding = 'UTF-8' ) { if ( '' !== $context || 'UTF-8' !== $encoding ) { return null; } if ( ! is_string( $html ) ) { _doing_it_wrong( __METHOD__, __( 'The HTML parameter must be a string.' ), '6.9.0' ); return null; } $context_processor = static::create_full_parser( "{$context}", $encoding ); if ( null === $context_processor ) { return null; } while ( $context_processor->next_tag() ) { if ( ! $context_processor->is_virtual() ) { $context_processor->set_bookmark( 'final_node' ); } } if ( ! $context_processor->has_bookmark( 'final_node' ) || ! $context_processor->seek( 'final_node' ) ) { _doing_it_wrong( __METHOD__, __( 'No valid context element was detected.' ), '6.8.0' ); return null; } return $context_processor->create_fragment_at_current_node( $html ); } /** * Creates an HTML processor in the full parsing mode. * * It's likely that a fragment parser is more appropriate, unless sending an * entire HTML document from start to finish. Consider a fragment parser with * a context node of ``. * * UTF-8 is the only allowed encoding. If working with a document that * isn't UTF-8, first convert the document to UTF-8, then pass in the * converted HTML. * * @param string $html Input HTML document to process. * @param string|null $known_definite_encoding Optional. If provided, specifies the charset used * in the input byte stream. Currently must be UTF-8. * @return static|null The created processor if successful, otherwise null. */ public static function create_full_parser( $html, $known_definite_encoding = 'UTF-8' ) { if ( 'UTF-8' !== $known_definite_encoding ) { return null; } if ( ! is_string( $html ) ) { _doing_it_wrong( __METHOD__, __( 'The HTML parameter must be a string.' ), '6.9.0' ); return null; } $processor = new static( $html, self::CONSTRUCTOR_UNLOCK_CODE ); $processor->state->encoding = $known_definite_encoding; $processor->state->encoding_confidence = 'certain'; return $processor; } /** * Constructor. * * Do not use this method. Use the static creator methods instead. * * @access private * * @since 6.4.0 * * @see WP_HTML_Processor::create_fragment() * * @param string $html HTML to process. * @param string|null $use_the_static_create_methods_instead This constructor should not be called manually. */ public function __construct( $html, $use_the_static_create_methods_instead = null ) { parent::__construct( $html ); if ( self::CONSTRUCTOR_UNLOCK_CODE !== $use_the_static_create_methods_instead ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: WP_HTML_Processor::create_fragment(). */ __( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ), 'WP_HTML_Processor::create_fragment()' ), '6.4.0' ); } $this->state = new WP_HTML_Processor_State(); $this->state->stack_of_open_elements->set_push_handler( function ( WP_HTML_Token $token ): void { $is_virtual = ! isset( $this->state->current_token ) || $this->is_tag_closer(); $same_node = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name; $provenance = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real'; $this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::PUSH, $provenance ); $this->change_parsing_namespace( $token->integration_node_type ? 'html' : $token->namespace ); } ); $this->state->stack_of_open_elements->set_pop_handler( function ( WP_HTML_Token $token ): void { $is_virtual = ! isset( $this->state->current_token ) || ! $this->is_tag_closer(); $same_node = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name; $provenance = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real'; $this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::POP, $provenance ); $adjusted_current_node = $this->get_adjusted_current_node(); if ( $adjusted_current_node ) { $this->change_parsing_namespace( $adjusted_current_node->integration_node_type ? 'html' : $adjusted_current_node->namespace ); } else { $this->change_parsing_namespace( 'html' ); } } ); /* * Create this wrapper so that it's possible to pass * a private method into WP_HTML_Token classes without * exposing it to any public API. */ $this->release_internal_bookmark_on_destruct = function ( string $name ): void { parent::release_bookmark( $name ); }; } /** * Creates a fragment processor at the current node. * * HTML Fragment parsing always happens with a context node. HTML Fragment Processors can be * instantiated with a `BODY` context node via `WP_HTML_Processor::create_fragment( $html )`. * * The context node may impact how a fragment of HTML is parsed. For example, consider the HTML * fragment `

`. * * A BODY context node will produce the following tree: * * └─#text Inside TD? * * Notice that the `
Inside TD?` tags are completely ignored. * * Compare that with an SVG context node that produces the following tree: * * ├─svg:td * └─#text Inside TD? * * Here, a `td` node in the `svg` namespace is created, and its self-closing flag is respected. * This is a peculiarity of parsing HTML in foreign content like SVG. * * Finally, consider the tree produced with a TABLE context node: * * └─TBODY * └─TR * └─TD * └─#text Inside TD? * * These examples demonstrate how important the context node may be when processing an HTML * fragment. Special care must be taken when processing fragments that are expected to appear * in specific contexts. SVG and TABLE are good examples, but there are others. * * @see https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-parsing-algorithm * * @since 6.8.0 * * @param string $html Input HTML fragment to process. * @return static|null The created processor if successful, otherwise null. */ private function create_fragment_at_current_node( string $html ) { if ( $this->get_token_type() !== '#tag' || $this->is_tag_closer() ) { _doing_it_wrong( __METHOD__, __( 'The context element must be a start tag.' ), '6.8.0' ); return null; } $tag_name = $this->current_element->token->node_name; $namespace = $this->current_element->token->namespace; if ( 'html' === $namespace && self::is_void( $tag_name ) ) { _doing_it_wrong( __METHOD__, sprintf( // translators: %s: A tag name like INPUT or BR. __( 'The context element cannot be a void element, found "%s".' ), $tag_name ), '6.8.0' ); return null; } /* * Prevent creating fragments at nodes that require a special tokenizer state. * This is unsupported by the HTML Processor. */ if ( 'html' === $namespace && in_array( $tag_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP', 'PLAINTEXT' ), true ) ) { _doing_it_wrong( __METHOD__, sprintf( // translators: %s: A tag name like IFRAME or TEXTAREA. __( 'The context element "%s" is not supported.' ), $tag_name ), '6.8.0' ); return null; } $fragment_processor = new static( $html, self::CONSTRUCTOR_UNLOCK_CODE ); $fragment_processor->compat_mode = $this->compat_mode; // @todo Create "fake" bookmarks for non-existent but implied nodes. $fragment_processor->bookmarks['root-node'] = new WP_HTML_Span( 0, 0 ); $root_node = new WP_HTML_Token( 'root-node', 'HTML', false ); $fragment_processor->state->stack_of_open_elements->push( $root_node ); $fragment_processor->bookmarks['context-node'] = new WP_HTML_Span( 0, 0 ); $fragment_processor->context_node = clone $this->current_element->token; $fragment_processor->context_node->bookmark_name = 'context-node'; $fragment_processor->context_node->on_destroy = null; $fragment_processor->breadcrumbs = array( 'HTML', $fragment_processor->context_node->node_name ); if ( 'TEMPLATE' === $fragment_processor->context_node->node_name ) { $fragment_processor->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE; } $fragment_processor->reset_insertion_mode_appropriately(); /* * > Set the parser's form element pointer to the nearest node to the context element that * > is a form element (going straight up the ancestor chain, and including the element * > itself, if it is a form element), if any. (If there is no such form element, the * > form element pointer keeps its initial value, null.) */ foreach ( $this->state->stack_of_open_elements->walk_up() as $element ) { if ( 'FORM' === $element->node_name && 'html' === $element->namespace ) { $fragment_processor->state->form_element = clone $element; $fragment_processor->state->form_element->bookmark_name = null; $fragment_processor->state->form_element->on_destroy = null; break; } } $fragment_processor->state->encoding_confidence = 'irrelevant'; /* * Update the parsing namespace near the end of the process. * This is important so that any push/pop from the stack of open * elements does not change the parsing namespace. */ $fragment_processor->change_parsing_namespace( $this->current_element->token->integration_node_type ? 'html' : $namespace ); return $fragment_processor; } /** * Stops the parser and terminates its execution when encountering unsupported markup. * * @throws WP_HTML_Unsupported_Exception Halts execution of the parser. * * @since 6.7.0 * @ignore * * @param string $message Explains support is missing in order to parse the current node. * @return never */ private function bail( string $message ) { $here = $this->bookmarks[ $this->state->current_token->bookmark_name ]; $token = substr( $this->html, $here->start, $here->length ); $open_elements = array(); foreach ( $this->state->stack_of_open_elements->stack as $item ) { $open_elements[] = $item->node_name; } $active_formats = array(); foreach ( $this->state->active_formatting_elements->walk_down() as $item ) { $active_formats[] = $item->node_name; } $this->last_error = self::ERROR_UNSUPPORTED; $this->unsupported_exception = new WP_HTML_Unsupported_Exception( $message, $this->state->current_token->node_name, $here->start, $token, $open_elements, $active_formats ); throw $this->unsupported_exception; } /** * Returns the last error, if any. * * Various situations lead to parsing failure but this class will * return `false` in all those cases. To determine why something * failed it's possible to request the last error. This can be * helpful to know to distinguish whether a given tag couldn't * be found or if content in the document caused the processor * to give up and abort processing. * * Example * * $processor = WP_HTML_Processor::create_fragment( '