Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
805fb55
WIP: HTML API: Add HTML Spec class to convey information related to t…
dmsnell Feb 24, 2023
84e35ef
WIP: HTML API: Expose self-closing flag in Tag Processor
dmsnell Mar 2, 2023
84e25cf
Expand documentation
dmsnell Mar 2, 2023
c18a81a
Appease the linting gods
dmsnell Mar 2, 2023
af8d49d
Add extra tests for syntax peculiarities.
dmsnell Mar 2, 2023
72e5de0
Appease the linting gods
dmsnell Mar 2, 2023
095a110
Appease the linting gods
dmsnell Mar 2, 2023
9b3f90d
Appease the linting gods
dmsnell Mar 2, 2023
09e16b2
Merge branch 'html-api/tag-processor-self-closing-flag' into html-api…
dmsnell Mar 7, 2023
396285b
Add `ensure_support()` and tests
dmsnell Mar 7, 2023
b2e6856
WIP: Work on next_sibling
dmsnell Mar 7, 2023
65c9f5b
Add the rest of it
dmsnell Mar 10, 2023
f5e4d5e
Merge branch 'trunk' into html-api/add-html-processor
dmsnell Mar 21, 2023
247966b
Rename "next_child" to "first_child" to better match its purpose
dmsnell Mar 21, 2023
f1ccd9b
Ensure no children are found for void elements.
dmsnell Mar 22, 2023
fb31ea1
rename next_child to first_child in test names
dmsnell Mar 22, 2023
2af46d0
Merge branch 'trunk' into html-api/add-html-processor
dmsnell Mar 25, 2023
e945f16
Add Trac ticket reference to tests
dmsnell Mar 29, 2023
96053c9
fixup! Add Trac ticket reference to tests
dmsnell Mar 29, 2023
da7880a
Merge branch 'trunk' into html-api/add-html-processor
dmsnell Mar 29, 2023
264ae35
Merge branch 'html-api/tag-processor-self-closing-flag' into html-api…
dmsnell Mar 29, 2023
04a37b5
Linting issues
dmsnell Mar 29, 2023
0975e34
Wrap bookmarking to create special internal bookmarks used in HTML tr…
dmsnell Apr 20, 2023
d30f766
Merge remote-tracking branch 'upstream/trunk' into html-api/add-html-…
dmsnell Apr 20, 2023
cafee03
Remove `ensure_support`
dmsnell Apr 20, 2023
67bef48
Introduce step function and insertion mode
dmsnell Apr 20, 2023
be6e901
Create some IS_SPECIAL flags
dmsnell May 3, 2023
9980a36
Merge remote-tracking branch 'upstream/trunk' into html-api/add-html-…
dmsnell May 3, 2023
2e874e4
Some bookmarking stuff
dmsnell May 4, 2023
d0e3f4a
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 4, 2023
ece3a68
I think we need a separate actual stack for open elements
dmsnell May 4, 2023
a5284d6
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 8, 2023
74c9e6b
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 8, 2023
a4569cd
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 16, 2023
98180bc
Add WIP stack class, trap exceptions in `step()` to allow nested call…
dmsnell May 17, 2023
0e3ada5
Play with an alternate matching syntax
dmsnell May 17, 2023
739b4aa
Add reset_insertion_mode_appropriately
dmsnell May 17, 2023
2b263b5
Merge remote-tracking branch 'upstream/trunk' into html-api/add-html-…
dmsnell May 17, 2023
e1ec10c
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 20, 2023
bc61ea8
Add custom "Unsupported Exception" class to differentiate from other …
dmsnell May 20, 2023
6f58b70
Set template insertion mode stack to empty array, not null
dmsnell May 20, 2023
d82b146
Expand SPEC data for IS_SPECIAL and IS_OBSOLETE
dmsnell May 21, 2023
a6e5323
Docs for SPEC and some minor refactoring
dmsnell May 21, 2023
8a2215e
Add algorithms for handling list of active formatting elements.
dmsnell May 21, 2023
d96c05a
Add docs for HEAD and FORM pointers.
dmsnell May 21, 2023
c93d420
Generate implied end tags, poorly and naively.
dmsnell May 21, 2023
2e0e4f9
More docs, remove something not necessary.
dmsnell May 21, 2023
f5c7651
Introduce static factory methods
dmsnell May 22, 2023
3956ad9
Access private methods and properties of friend class
dmsnell May 23, 2023
37ce95e
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 24, 2023
613ae1a
Replace goto:ignored with recursion
dmsnell May 24, 2023
46e3777
Continue adding IN BODY handling.
dmsnell May 25, 2023
a1a095c
Merge branch 'trunk' into html-api/add-html-processor
dmsnell May 26, 2023
c2dcc37
Merge remote-tracking branch 'upstream/trunk' into html-api/add-html-…
dmsnell May 28, 2023
c29570e
More support
dmsnell May 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/wp-includes/html-api/class-wp-html-element-stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ class WP_HTML_Element_Stack {
*/
public $stack = array();

public function __construct( $bookmark_name, $element, $flags ) {
$this->bookmark_name = $bookmark_name;
$this->element = $element;
$this->flags = $flags;
}

/**
* Add an item to the top of the stack.
*
Expand Down
135 changes: 134 additions & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
<?php

require_once __DIR__ . '/class-wp-html-element-stack.php';

class WP_HTML_Processor extends WP_HTML_Tag_Processor {
const NOT_IMPLEMENTED_YET = false;

private $depth = 0;
private static $query = array( 'tag_closers' => 'visit' );
private $insertion_mode = 'in-body';

/**
* @var int Unique id for creating bookmarks.
*/
private $bookmark_id = 0;

/**
* @var WP_HTML_Element_Stack Refers to element opening tags.
*/
private $tag_openers = null;

/**
* @var WP_HTML_Element_Stack Referes to element closing tags.
*/
private $tag_closers = null;

/**
* Create a new HTML Processor for reading and modifying HTML structure.
*
* @param string $html Input HTML document.
*/
public function __construct( $html ) {
parent::__construct( $html );

$this->tag_openers = new WP_HTML_Element_Stack();
$this->tag_closers = new WP_HTML_Element_Stack();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would you push to this stack?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still working on an answer for this 😆

}

/**
* Advance the parser by one step.
*
Expand Down Expand Up @@ -70,6 +99,110 @@ private function step_in_body() {

$tag_name = $this->get_tag();
$tag_type = $this->is_tag_closer() ? 'closer' : 'opener';
$op_sigil = $this->is_tag_closer() ? '-' : '+';
$op = "{$op_sigil}{$tag_name}";

switch ( $op ) {
/*
* > A start tag whose tag name is "html"
*/
case '+HTML':
goto ignored;

/*
* > A start tag whose tag name is one of: "base", "basefont", "bgsound",
* > "link", "meta", "noframes", "script", "style", "template", "title"
*
* > An end tag whose tag name is "template"
*/
case '+BASE':
case '+BASEFONT':
case '+BGSOUND':
case '+LINK':
case '+META':
case '+NOFRAMES':
case '+SCRIPT':
case '+STYLE':
case '+TEMPLATE':
case '+TITLE':
case '-TEMPLATE':
parent::seek( 'current' );
$this->insertion_mode = 'in-head';
return $this->step();

/*
* > A start tag whose tag name is "body"
*/
case '+BODY':
goto ignored;


/*
* > A start tag whose tag name is "frameset"
*/
case '+FRAMESET':
throw new Exception( self::NOT_IMPLEMENTED_YET );

/*
* > An end tag whose tag name is "body"
* > An end tag whose tag name is "html"
*/
case '-BODY':
case '-HTML':
/*
* > If the stack of open elements does not have a body element in scope, this is a parse error; ignore the token.
*
* @TODO: We didn't construct an open HTML or BODY tag, but we have to make a choice here based on that.
* Probably need to create these _or_ assume this will always transfer to "after body".
*/
$this->insertion_mode = 'after-body';
return true;

/*
* > A start tag whose tag name is one of: "address", "article", "aside", "blockquote", "center",
* > "details", "dialog", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer",
* > "header", "hgroup", "main", "menu", "nav", "ol", "p", "search", "section", "summary", "ul"
*/
case '+ADDRESS':
case '+ARTICLE':
case '+ASIDE':
case '+BLOCKQUOTE':
case '+CENTER':
case '+DETAILS':
case '+DIALOG':
case '+DIR':
case '+DIV':
case '+DL':
case '+FIELDSET':
case '+FIGCAPTION':
case '+FIGURE':
case '+FOOTER':
case '+HEADER':
case '+HGROUP':
case '+MAIN':
case '+MENU':
case '+NAV':
case '+OL':
case '+P':
case '+SEARCH':
case '+SECTION':
case '+SUMMARY':
case '+UL':
if ( $this->has_in_scope( 'P', 'BUTTON' ) ) {
$this->close_p_element();
}

$this->enter_element( $tag_name );
return;

/*
* > An end-of-file token
*
* Stop parsing.
*/
default:
return false;
}

/*
* > A start tag whose tag name is "html"
Expand Down Expand Up @@ -260,7 +393,7 @@ private function current_node() {
* @return false
*/
private function has_in_scope( $element, $scope ) {
return self::NOT_IMPLEMENTED_YET;
throw new Exception( self::NOT_IMPLEMENTED_YET );
}

public function next_tag( $query = null ) {
Expand Down