Skip to content

Commit 096fc8e

Browse files
committed
Add PLAINTEXT support.
1 parent a385685 commit 096fc8e

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,13 +2122,8 @@ private function step_in_body(): bool {
21222122
$this->close_a_p_element();
21232123
}
21242124

2125-
/*
2126-
* @todo This may need to be handled in the Tag Processor and turn into
2127-
* a single self-contained tag like TEXTAREA, whose modifiable text
2128-
* is the rest of the input document as plaintext.
2129-
*/
2130-
$this->bail( 'Cannot process PLAINTEXT elements.' );
2131-
break;
2125+
$this->insert_html_element( $this->state->current_token );
2126+
return true;
21322127

21332128
/*
21342129
* > A start tag whose tag name is "button"

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,15 @@ private function base_class_next_token(): bool {
974974
return true;
975975
}
976976

977+
if ( 'PLAINTEXT' === $tag_name ) {
978+
$doc_length = strlen( $this->html );
979+
$this->text_starts_at = $this->token_starts_at + $this->token_length;
980+
$this->text_length = $doc_length - $this->text_starts_at;
981+
$this->token_length = $doc_length - $this->token_starts_at;
982+
$this->bytes_already_parsed = $doc_length;
983+
return true;
984+
}
985+
977986
/*
978987
* There are certain elements whose children are not DATA but are instead
979988
* RCDATA or RAWTEXT. These cannot contain other elements, and the contents
@@ -2919,6 +2928,9 @@ public function get_modifiable_text(): string {
29192928

29202929
$tag_name = $this->get_token_name();
29212930
if (
2931+
// Plaintext data is not decoded.
2932+
'PLAINTEXT' === $tag_name ||
2933+
29222934
// Script data is not decoded.
29232935
'SCRIPT' === $tag_name ||
29242936

@@ -3533,7 +3545,13 @@ private function matches(): bool {
35333545
}
35343546

35353547
// Does the tag name match the requested tag name in a case-insensitive manner?
3536-
if ( isset( $this->sought_tag_name ) && 0 !== substr_compare( $this->html, $this->sought_tag_name, $this->tag_name_starts_at, $this->tag_name_length, true ) ) {
3548+
if (
3549+
isset( $this->sought_tag_name ) &&
3550+
(
3551+
strlen( $this->sought_tag_name ) !== $this->tag_name_length ||
3552+
0 !== substr_compare( $this->html, $this->sought_tag_name, $this->tag_name_starts_at, $this->tag_name_length, true )
3553+
)
3554+
) {
35373555
return false;
35383556
}
35393557

0 commit comments

Comments
 (0)