Skip to content

Commit 9101865

Browse files
committed
HTML API: Correct and improve documentation issues.
Developed in #12043. Props jonsurrell, westonruter, dmsnell. See #64896. git-svn-id: https://develop.svn.wordpress.org/trunk@62507 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5a916f0 commit 9101865

18 files changed

Lines changed: 60 additions & 53 deletions

src/wp-includes/html-api/class-wp-html-active-formatting-elements.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function contains_node( WP_HTML_Token $token ) {
6767
*
6868
* @since 6.4.0
6969
*
70-
* @return int How many node are in the stack of active formatting elements.
70+
* @return int How many nodes are in the stack of active formatting elements.
7171
*/
7272
public function count() {
7373
return count( $this->stack );

src/wp-includes/html-api/class-wp-html-attribute-token.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class WP_HTML_Attribute_Token {
3232
public $name;
3333

3434
/**
35-
* Attribute value.
35+
* Byte offset in the input HTML where the attribute value starts.
3636
*
3737
* @since 6.2.0
3838
*
@@ -101,7 +101,7 @@ class WP_HTML_Attribute_Token {
101101
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
102102
*
103103
* @param string $name Attribute name.
104-
* @param int $value_start Attribute value.
104+
* @param int $value_start Byte offset where the attribute value starts.
105105
* @param int $value_length Number of bytes attribute value spans.
106106
* @param int $start The string offset where the attribute name starts.
107107
* @param int $length Byte length of the entire attribute name or name and value pair expression.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function attribute_starts_with( $haystack, $search_text, $case_sen
8383
*
8484
* Example:
8585
*
86-
* '“😄”' === WP_HTML_Decode::decode_text_node( '“😄&#x94' );
86+
* '“😄”' === WP_HTML_Decoder::decode_text_node( '“😄&#x94' );
8787
*
8888
* @since 6.6.0
8989
*
@@ -103,7 +103,7 @@ public static function decode_text_node( $text ): string {
103103
*
104104
* Example:
105105
*
106-
* '“😄”' === WP_HTML_Decode::decode_attribute( '“😄&#x94' );
106+
* '“😄”' === WP_HTML_Decoder::decode_attribute( '“😄&#x94' );
107107
*
108108
* @since 6.6.0
109109
*

src/wp-includes/html-api/class-wp-html-doctype-info.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ class WP_HTML_Doctype_Info {
136136
* (e.g. "quirks" or "no-quirks" mode), it will be inferred from the properties
137137
* of the appropriate DOCTYPE declaration, if one exists. The DOCTYPE can
138138
* indicate one of three possible document compatibility modes:
139+
* "no-quirks", "limited-quirks", or "quirks".
139140
*
140-
* - "no-quirks" and "limited-quirks" modes (also called "standards" mode).
141-
* - "quirks" mode (also called `CSS1Compat` mode).
141+
* Browsers expose the resulting document mode via `document.compatMode`:
142+
* - "BackCompat" indicates "quirks" mode.
143+
* - "CSS1Compat" indicates "no-quirks" or "limited-quirks" (these modes are not
144+
* distinguished by `document.compatMode`).
142145
*
143146
* An appropriate DOCTYPE is one encountered in the "initial" insertion mode,
144147
* before the HTML element has been opened and before finding any other

src/wp-includes/html-api/class-wp-html-open-elements.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class WP_HTML_Open_Elements {
7878
* Sets a pop handler that will be called when an item is popped off the stack of
7979
* open elements.
8080
*
81-
* The function will be called with the pushed item as its argument.
81+
* The function will be called with the popped item as its argument.
8282
*
8383
* @since 6.6.0
8484
*
@@ -103,7 +103,7 @@ public function set_push_handler( Closure $handler ): void {
103103
}
104104

105105
/**
106-
* Returns the name of the node at the nth position on the stack
106+
* Returns the node at the nth position on the stack
107107
* of open elements, or `null` if no such position exists.
108108
*
109109
* Note that this uses a 1-based index, which represents the
@@ -114,7 +114,7 @@ public function set_push_handler( Closure $handler ): void {
114114
*
115115
* @param int $nth Retrieve the nth item on the stack, with 1 being
116116
* the top element, 2 being the second, etc...
117-
* @return WP_HTML_Token|null Name of the node on the stack at the given location,
117+
* @return WP_HTML_Token|null The node on the stack at the given location,
118118
* or `null` if the location isn't on the stack.
119119
*/
120120
public function at( int $nth ): ?WP_HTML_Token {
@@ -168,7 +168,7 @@ public function contains_node( WP_HTML_Token $token ): bool {
168168
*
169169
* @since 6.4.0
170170
*
171-
* @return int How many node are in the stack of open elements.
171+
* @return int How many nodes are in the stack of open elements.
172172
*/
173173
public function count(): int {
174174
return count( $this->stack );

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ public static function create_fragment( $html, $context = '<body>', $encoding =
341341
* isn't UTF-8, first convert the document to UTF-8, then pass in the
342342
* converted HTML.
343343
*
344+
* @since 6.7.0
345+
*
344346
* @param string $html Input HTML document to process.
345347
* @param string|null $known_definite_encoding Optional. If provided, specifies the charset used
346348
* in the input byte stream. Currently must be UTF-8.
@@ -957,7 +959,7 @@ public function matches_breadcrumbs( $breadcrumbs ): bool {
957959
* token, or if it will self-close on the next step.
958960
*
959961
* Most HTML elements expect a closer, such as a P element or
960-
* a DIV element. Others, like an IMG element are void and don't
962+
* a DIV element. Others, like an IMG element, are void and don't
961963
* have a closing tag. Special elements, such as SCRIPT and STYLE,
962964
* are treated just like void tags. Text nodes and self-closing
963965
* foreign content will also act just like a void tag, immediately
@@ -5213,7 +5215,7 @@ private function step_in_foreign_content(): bool {
52135215
*
52145216
* @throws Exception When unable to allocate requested bookmark.
52155217
*
5216-
* @return string|false Name of created bookmark, or false if unable to create.
5218+
* @return string Name of created bookmark.
52175219
*/
52185220
private function bookmark_token() {
52195221
if ( ! parent::set_bookmark( ++$this->bookmark_counter ) ) {

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
*
214214
* ### Bookmarks
215215
*
216-
* While scanning through the input HTMl document it's possible to set
216+
* While scanning through the input HTML document it's possible to set
217217
* a named bookmark when a particular tag is found. Later on, after
218218
* continuing to scan other tags, it's possible to `seek` to one of
219219
* the set bookmarks and then proceed again from that point forward.
@@ -286,7 +286,7 @@
286286
*
287287
* For these elements the Tag Processor treats the entire sequence as one,
288288
* from the opening tag, including its contents, through its closing tag.
289-
* This means that the it's not possible to match the closing tag for a
289+
* This means that it's not possible to match the closing tag for a
290290
* SCRIPT element unless it's unexpected; the Tag Processor already matched
291291
* it when it found the opening tag.
292292
*
@@ -298,7 +298,7 @@
298298
* closing the SCRIPT from inside a JavaScript string. E.g. `console.log( '</script>' )`.
299299
* - `TITLE` and `TEXTAREA` whose contents are treated as plaintext and then any
300300
* character references are decoded. E.g. `1 &lt; 2 < 3` becomes `1 < 2 < 3`.
301-
* - `IFRAME`, `NOSCRIPT`, `NOEMBED`, `NOFRAME`, `STYLE` whose contents are treated as
301+
* - `IFRAME`, `NOEMBED`, `NOFRAMES`, `STYLE` whose contents are treated as
302302
* raw plaintext and left as-is. E.g. `1 &lt; 2 < 3` remains `1 &lt; 2 < 3`.
303303
*
304304
* #### Other tokens with modifiable text.
@@ -329,7 +329,7 @@
329329
* and disallows "xml" as a name, since it's special. The Tag Processor only recognizes
330330
* target names with an ASCII-representable subset of characters. It also exhibits the
331331
* same constraint as with CDATA sections, in that `>` cannot exist within the token
332-
* since Processing Instructions do no exist within HTML and their syntax transforms
332+
* since Processing Instructions do not exist within HTML and their syntax transforms
333333
* into a bogus comment in the DOM.
334334
*
335335
* ## Design and limitations
@@ -521,7 +521,7 @@ class WP_HTML_Tag_Processor {
521521
* - A TABLE start tag `<table>` implicitly closes any open `P` element.
522522
*
523523
* - In `QUIRKS_MODE`:
524-
* - CSS class and ID selectors match match in an ASCII case-insensitive manner.
524+
* - CSS class and ID selectors match in an ASCII case-insensitive manner.
525525
* - A TABLE start tag `<table>` opens a `TABLE` element as a child of a `P`
526526
* element if one is open.
527527
*
@@ -614,12 +614,12 @@ class WP_HTML_Tag_Processor {
614614
* Example:
615615
*
616616
* <div id="test">...
617-
* 012345678901234
618-
* - token length is 14 - 0 = 14
617+
* 0123456789012345
618+
* - token length is 15 - 0 = 15
619619
*
620620
* a <!-- comment --> is a token.
621621
* 0123456789 123456789 123456789
622-
* - token length is 17 - 2 = 15
622+
* - token length is 18 - 2 = 16
623623
*
624624
* @since 6.5.0
625625
*
@@ -926,8 +926,6 @@ public function next_tag( $query = null ): bool {
926926
* - a DOCTYPE declaration.
927927
* - a processing instruction, e.g. `<?xml version="1.0" ?>`.
928928
*
929-
* The Tag Processor currently only supports the tag token.
930-
*
931929
* @since 6.5.0
932930
* @since 6.7.0 Recognizes CDATA sections within foreign content.
933931
*
@@ -1073,7 +1071,7 @@ private function base_class_next_token(): bool {
10731071
*
10741072
* Preserve the opening tag pointers, as these will be overwritten
10751073
* when finding the closing tag. They will be reset after finding
1076-
* the closing to tag to point to the opening of the special atomic
1074+
* the closing tag to point to the opening of the special atomic
10771075
* tag sequence.
10781076
*/
10791077
$tag_name_starts_at = $this->tag_name_starts_at;
@@ -1149,7 +1147,7 @@ private function base_class_next_token(): bool {
11491147
* Example:
11501148
*
11511149
* $processor = new WP_HTML_Tag_Processor( '<input type="text" value="Th' );
1152-
* false === $processor->get_next_tag();
1150+
* false === $processor->next_tag();
11531151
* true === $processor->paused_at_incomplete_token();
11541152
*
11551153
* @since 6.5.0
@@ -2525,7 +2523,7 @@ private function apply_attributes_updates( int $shift_this_point ): int {
25252523
* replacement must be made before all others which follow it
25262524
* at later string indices in the input document.
25272525
*
2528-
* Sorting avoid making out-of-order replacements which
2526+
* Sorting avoids making out-of-order replacements which
25292527
* can lead to mangled output, partially-duplicated
25302528
* attributes, and overwritten attributes.
25312529
*/
@@ -3561,9 +3559,9 @@ public function get_full_comment_text(): ?string {
35613559
* true === $processor->next_token(); // Text is "Apples & Oranges".
35623560
* false === $processor->subdivide_text_appropriately();
35633561
*
3564-
* $processor = new WP_HTML_Tag_Processor( "&#x13; \r\n\tMore" );
3565-
* true === $processor->next_token(); // Text is "␤ ␤␉More".
3566-
* true === $processor->subdivide_text_appropriately(); // Text is "␤ ␤␉".
3562+
* $processor = new WP_HTML_Tag_Processor( "&#xD; \r\n\tMore" );
3563+
* true === $processor->next_token(); // Text is "␍ ␊␉More".
3564+
* true === $processor->subdivide_text_appropriately(); // Text is "␍ ␊␉".
35673565
* true === $processor->next_token(); // Text is "More".
35683566
* false === $processor->subdivide_text_appropriately();
35693567
*
@@ -4941,7 +4939,7 @@ public function get_doctype_info(): ?WP_HTML_Doctype_Info {
49414939
* </2>
49424940
*
49434941
* Funky comments are tag closers with invalid tag names. Note
4944-
* that in HTML these are turn into bogus comments. Nonetheless,
4942+
* that in HTML these are turned into bogus comments. Nonetheless,
49454943
* the Tag Processor recognizes them in a stream of HTML and
49464944
* exposes them for inspection and modification.
49474945
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class WP_HTML_Token {
2929
*
3030
* @since 6.4.0
3131
*
32-
* @var string
32+
* @var string|null
3333
*/
3434
public $bookmark_name = null;
3535

tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function test_unexpected_closing_tags_are_removed() {
261261
$this->assertSame(
262262
WP_HTML_Processor::normalize( 'one</div>two</span>three' ),
263263
'onetwothree',
264-
'Should have removed unpected closing tags.'
264+
'Should have removed unexpected closing tags.'
265265
);
266266
}
267267

tests/phpunit/tests/html-api/wpHtmlProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,11 +1071,11 @@ public function test_ensure_next_token_method_extensibility( $html, $expected_to
10711071
* @ticket 62427
10721072
*/
10731073
public function test_next_tag_lowercase_tag_name() {
1074-
// The upper case <DIV> is irrelevant but illustrates the case-insentivity.
1074+
// The upper case <DIV> is irrelevant but illustrates the case-insensitivity.
10751075
$processor = WP_HTML_Processor::create_fragment( '<section><DIV>' );
10761076
$this->assertTrue( $processor->next_tag( array( 'tag_name' => 'div' ) ) );
10771077

1078-
// The upper case <RECT> is irrelevant but illustrates the case-insentivity.
1078+
// The upper case <RECT> is irrelevant but illustrates the case-insensitivity.
10791079
$processor = WP_HTML_Processor::create_fragment( '<svg><RECT>' );
10801080
$this->assertTrue( $processor->next_tag( array( 'tag_name' => 'rect' ) ) );
10811081
}

0 commit comments

Comments
 (0)