Skip to content

Commit af1a85d

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 1cbd92c + ca99fef commit af1a85d

15 files changed

Lines changed: 812 additions & 102 deletions

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,15 @@ public function serialize_token(): string {
14021402
$html .= "<!--{$this->get_full_comment_text()}-->";
14031403
break;
14041404

1405+
/**
1406+
* Processing instructions are serialized as `"<?" target " " data "?>"`.
1407+
*
1408+
* @link https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments
1409+
*/
1410+
case '#processing-instruction':
1411+
$html .= "<?{$this->get_tag()} {$this->get_modifiable_text()}?>";
1412+
break;
1413+
14051414
case '#cdata-section':
14061415
$html .= "<![CDATA[{$this->get_modifiable_text()}]]>";
14071416
break;
@@ -1562,10 +1571,12 @@ private function step_initial(): bool {
15621571

15631572
/*
15641573
* > A comment token
1574+
* > A processing instruction token
15651575
*/
15661576
case '#comment':
15671577
case '#funky-comment':
15681578
case '#presumptuous-tag':
1579+
case '#processing-instruction':
15691580
$this->insert_html_element( $this->state->current_token );
15701581
return true;
15711582

@@ -1628,10 +1639,12 @@ private function step_before_html(): bool {
16281639

16291640
/*
16301641
* > A comment token
1642+
* > A processing instruction token
16311643
*/
16321644
case '#comment':
16331645
case '#funky-comment':
16341646
case '#presumptuous-tag':
1647+
case '#processing-instruction':
16351648
$this->insert_html_element( $this->state->current_token );
16361649
return true;
16371650

@@ -1733,10 +1746,12 @@ private function step_before_head(): bool {
17331746

17341747
/*
17351748
* > A comment token
1749+
* > A processing instruction token
17361750
*/
17371751
case '#comment':
17381752
case '#funky-comment':
17391753
case '#presumptuous-tag':
1754+
case '#processing-instruction':
17401755
$this->insert_html_element( $this->state->current_token );
17411756
return true;
17421757

@@ -1832,10 +1847,12 @@ private function step_in_head(): bool {
18321847

18331848
/*
18341849
* > A comment token
1850+
* > A processing instruction token
18351851
*/
18361852
case '#comment':
18371853
case '#funky-comment':
18381854
case '#presumptuous-tag':
1855+
case '#processing-instruction':
18391856
$this->insert_html_element( $this->state->current_token );
18401857
return true;
18411858

@@ -2158,10 +2175,12 @@ private function step_after_head(): bool {
21582175

21592176
/*
21602177
* > A comment token
2178+
* > A processing instruction token
21612179
*/
21622180
case '#comment':
21632181
case '#funky-comment':
21642182
case '#presumptuous-tag':
2183+
case '#processing-instruction':
21652184
$this->insert_html_element( $this->state->current_token );
21662185
return true;
21672186

@@ -2318,6 +2337,7 @@ private function step_in_body(): bool {
23182337
case '#comment':
23192338
case '#funky-comment':
23202339
case '#presumptuous-tag':
2340+
case '#processing-instruction':
23212341
$this->insert_html_element( $this->state->current_token );
23222342
return true;
23232343

@@ -3400,10 +3420,12 @@ private function step_in_table(): bool {
34003420

34013421
/*
34023422
* > A comment token
3423+
* > A processing instruction token
34033424
*/
34043425
case '#comment':
34053426
case '#funky-comment':
34063427
case '#presumptuous-tag':
3428+
case '#processing-instruction':
34073429
$this->insert_html_element( $this->state->current_token );
34083430
return true;
34093431

@@ -3721,10 +3743,12 @@ private function step_in_column_group(): bool {
37213743

37223744
/*
37233745
* > A comment token
3746+
* > A processing instruction token
37243747
*/
37253748
case '#comment':
37263749
case '#funky-comment':
37273750
case '#presumptuous-tag':
3751+
case '#processing-instruction':
37283752
$this->insert_html_element( $this->state->current_token );
37293753
return true;
37303754

@@ -4153,10 +4177,12 @@ private function step_in_select(): bool {
41534177

41544178
/*
41554179
* > A comment token
4180+
* > A processing instruction token
41564181
*/
41574182
case '#comment':
41584183
case '#funky-comment':
41594184
case '#presumptuous-tag':
4185+
case '#processing-instruction':
41604186
$this->insert_html_element( $this->state->current_token );
41614187
return true;
41624188

@@ -4378,12 +4404,14 @@ private function step_in_template(): bool {
43784404
/*
43794405
* > A character token
43804406
* > A comment token
4407+
* > A processing instruction token
43814408
* > A DOCTYPE token
43824409
*/
43834410
case '#text':
43844411
case '#comment':
43854412
case '#funky-comment':
43864413
case '#presumptuous-tag':
4414+
case '#processing-instruction':
43874415
case 'html':
43884416
return $this->step_in_body();
43894417

@@ -4519,10 +4547,12 @@ private function step_after_body(): bool {
45194547

45204548
/*
45214549
* > A comment token
4550+
* > A processing instruction token
45224551
*/
45234552
case '#comment':
45244553
case '#funky-comment':
45254554
case '#presumptuous-tag':
4555+
case '#processing-instruction':
45264556
$this->bail( 'Content outside of BODY is unsupported.' );
45274557
break;
45284558

@@ -4612,10 +4642,12 @@ private function step_in_frameset(): bool {
46124642

46134643
/*
46144644
* > A comment token
4645+
* > A processing instruction token
46154646
*/
46164647
case '#comment':
46174648
case '#funky-comment':
46184649
case '#presumptuous-tag':
4650+
case '#processing-instruction':
46194651
$this->insert_html_element( $this->state->current_token );
46204652
return true;
46214653

@@ -4732,10 +4764,12 @@ private function step_after_frameset(): bool {
47324764

47334765
/*
47344766
* > A comment token
4767+
* > A processing instruction token
47354768
*/
47364769
case '#comment':
47374770
case '#funky-comment':
47384771
case '#presumptuous-tag':
4772+
case '#processing-instruction':
47394773
$this->insert_html_element( $this->state->current_token );
47404774
return true;
47414775

@@ -4802,10 +4836,12 @@ private function step_after_after_body(): bool {
48024836
switch ( $op ) {
48034837
/*
48044838
* > A comment token
4839+
* > A processing instruction token
48054840
*/
48064841
case '#comment':
48074842
case '#funky-comment':
48084843
case '#presumptuous-tag':
4844+
case '#processing-instruction':
48094845
$this->bail( 'Content outside of HTML is unsupported.' );
48104846
break;
48114847

@@ -4866,10 +4902,12 @@ private function step_after_after_frameset(): bool {
48664902
switch ( $op ) {
48674903
/*
48684904
* > A comment token
4905+
* > A processing instruction token
48694906
*/
48704907
case '#comment':
48714908
case '#funky-comment':
48724909
case '#presumptuous-tag':
4910+
case '#processing-instruction':
48734911
$this->bail( 'Content outside of HTML is unsupported.' );
48744912
break;
48754913

@@ -4989,10 +5027,12 @@ private function step_in_foreign_content(): bool {
49895027

49905028
/*
49915029
* > A comment token
5030+
* > A processing instruction token
49925031
*/
49935032
case '#comment':
49945033
case '#funky-comment':
49955034
case '#presumptuous-tag':
5035+
case '#processing-instruction':
49965036
$this->insert_foreign_element( $this->state->current_token, false );
49975037
return true;
49985038

@@ -5306,8 +5346,12 @@ public function get_tag(): ?string {
53065346
/*
53075347
* > A start tag whose tag name is "image"
53085348
* > Change the token's tag name to "img" and reprocess it. (Don't ask.)
5349+
*
5350+
* This only applies to tags; a processing instruction target or a
5351+
* comment which looks like a processing instruction may also report
5352+
* a tag name and must not be rewritten.
53095353
*/
5310-
return ( 'IMAGE' === $tag_name && 'html' === $this->get_namespace() )
5354+
return ( 'IMAGE' === $tag_name && 'html' === $this->get_namespace() && '#tag' === $this->get_token_type() )
53115355
? 'IMG'
53125356
: $tag_name;
53135357
}
@@ -5376,8 +5420,11 @@ public function get_token_name(): ?string {
53765420
* - `#doctype` when matched on a DOCTYPE declaration.
53775421
* - `#presumptuous-tag` when matched on an empty tag closer.
53785422
* - `#funky-comment` when matched on a funky comment.
5423+
* - `#processing-instruction` when matched on a processing instruction.
53795424
*
53805425
* @since 6.6.0 Subclassed for the HTML Processor.
5426+
* @since 7.1.0 Recognize processing instructions according to an HTML
5427+
* specification update.
53815428
*
53825429
* @return string|null What kind of token is matched, or null.
53835430
*/

0 commit comments

Comments
 (0)