Skip to content

Commit 9e11f19

Browse files
committed
Improve method documentation with examples
1 parent bcebeba commit 9e11f19

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,35 @@ function ( WP_HTML_Token $token ): void {
428428
* Creates a fragment processor at the current node.
429429
*
430430
* HTML Fragment parsing always happens with a context node. HTML Fragment Processors can be
431-
* instantiated with a `BODY` context node via `WP_HTML_Processor::create_fragment()`.
431+
* instantiated with a `BODY` context node via `WP_HTML_Processor::create_fragment( $html )`.
432432
*
433-
* The context node may impact how a fragment of HTML is parsed. For example, when parsing
434-
* `<rect />A</rect>B`:
433+
* The context node may impact how a fragment of HTML is parsed. For example, consider the HTML
434+
* fragment `<td />Inside TD?</td>`.
435435
*
436436
* With a BODY context node results in the following tree:
437437
*
438+
* └─#text Inside TD?
439+
*
440+
* Notice that the `<td>` tags are completely ignored.
441+
*
442+
* Compare that with an SVG context node that produces the following tree:
443+
*
444+
* ├─svg:td
445+
* └─#text Inside TD?
446+
*
447+
* Here, a `td` node in the `svg` namespace is created, and its self-closing flag is respected.
448+
* This is a peculiarity of parsing HTML in foreign content like SVG.
449+
*
450+
* Finally, consider the tree produced with a TABLE context node:
451+
*
452+
* └─TBODY
453+
* └─TR
454+
* └─TD
455+
* └─#text Inside TD?
456+
*
457+
* These examples demonstrate how important the context node may be when processing an HTML
458+
* fragment. Special care must be taken when processing fragments that are expected to appear
459+
* in specific contexts. SVG and TABLE are good examples, but there are others.
438460
*
439461
* @see https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-parsing-algorithm
440462
*

0 commit comments

Comments
 (0)