Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Introduce HTML Tag Processor #3920

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
15863a8
Introduce HTML Tag Processor
dmsnell Jan 26, 2023
40e1cb3
Move class_exists calls to wp-html
dmsnell Jan 30, 2023
8b507e5
Mark helper classes `final`
dmsnell Jan 30, 2023
561acff
Updates from review feedback, mostly docs
dmsnell Jan 30, 2023
57550e7
WP_HTML_Tag_Processor_Test: test improvements
hellofromtonya Jan 30, 2023
b708c6b
Load API files directly from wp-settings.php
hellofromtonya Jan 30, 2023
521a500
Tests: remove loading API files
hellofromtonya Jan 30, 2023
8bdfae4
Renames test classes to coding standard
hellofromtonya Jan 30, 2023
bc17086
Renames test filenames to coding standard
hellofromtonya Jan 30, 2023
334e415
Cleans HEADS from merge conflict from test file
hellofromtonya Jan 30, 2023
def4ed4
Reword explanation of lexical updates
dmsnell Jan 31, 2023
b924e03
docblock and consistency updates, addressing some PR feedback
dmsnell Jan 31, 2023
91dc772
Move HTML processing modules into new html directory
dmsnell Jan 31, 2023
1fd0d7d
Documentation wording updates.
dmsnell Jan 31, 2023
361710d
Rename library to "HTML-API" instead of "HTML"
dmsnell Jan 31, 2023
2d1411a
Un-finalize helper classes
dmsnell Jan 31, 2023
d8fdf41
Replace throwing with trigger_error( E_USER_WARNING )
dmsnell Jan 31, 2023
1465218
Add test to check for bug when encounting unexpected </SCRIPT> closer
dmsnell Feb 1, 2023
5c1a5d5
Update tests: fix data provider and remove Exception expectation
dmsnell Feb 1, 2023
c50ffee
Lint issue
dmsnell Feb 1, 2023
9a5ccf0
Fix broken tests
dmsnell Feb 1, 2023
13dd7d7
Remove some TODOs, most were done already
dmsnell Feb 1, 2023
b31cca4
Expand design and limitations discussion
dmsnell Feb 1, 2023
1a9bec0
Loosen assertion on warning
dmsnell Feb 1, 2023
28e9bf3
Rename some properties to clarify their purpose and expand comments.
dmsnell Feb 1, 2023
1e2ef09
Linter: yoda condition
dmsnell Feb 1, 2023
243dc7c
Typos in comments
dmsnell Feb 1, 2023
8152988
Rework @covers attributes
dmsnell Feb 1, 2023
a5f2d96
Was doing it wrong w.r.t. doing_it_wrong
dmsnell Feb 1, 2023
5b1d47e
Add additional type check to avoid throwing _doing_it_wrong error whe…
dmsnell Feb 1, 2023
3f9b274
Lada la di
dmsnell Feb 2, 2023
1b8c75c
Remove checks that _doing_it_wrong throws a notice
dmsnell Feb 2, 2023
aad5310
Set expected incorrect usage in tests.
dmsnell Feb 2, 2023
4a43850
Docblock updates
dmsnell Feb 2, 2023
fbbf382
Shorten function summary
dmsnell Feb 2, 2023
5b4ad8f
Ensure test assertions have a message parameter
dmsnell Feb 2, 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
89 changes: 89 additions & 0 deletions src/wp-includes/html-api/class-wp-html-attribute-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* HTML Tag Processor: Attribute token structure class.
*
* @package WordPress
* @subpackage HTML-API
* @since 6.2.0
*/

/**
* Data structure for the attribute token that allows to drastically improve performance.
*
* This class is for internal usage of the WP_HTML_Tag_Processor class.
*
* @access private
* @since 6.2.0
*
* @see WP_HTML_Tag_Processor
*/
class WP_HTML_Attribute_Token {
/**
* Attribute name.
*
* @since 6.2.0
* @var string
*/
public $name;

/**
* Attribute value.
*
* @since 6.2.0
* @var int
*/
public $value_starts_at;

/**
* How many bytes the value occupies in the input HTML.
*
* @since 6.2.0
* @var int
*/
public $value_length;

/**
* The string offset where the attribute name starts.
*
* @since 6.2.0
* @var int
*/
public $start;

/**
* The string offset after the attribute value or its name.
*
* @since 6.2.0
* @var int
*/
public $end;

/**
* Whether the attribute is a boolean attribute with value `true`.
*
* @since 6.2.0
* @var bool
*/
public $is_true;

/**
* Constructor.
*
* @since 6.2.0
*
* @param string $name Attribute name.
* @param int $value_start Attribute value.
* @param int $value_length Number of bytes attribute value spans.
* @param int $start The string offset where the attribute name starts.
* @param int $end The string offset after the attribute value or its name.
* @param bool $is_true Whether the attribute is a boolean attribute with true value.
*/
public function __construct( $name, $value_start, $value_length, $start, $end, $is_true ) {
$this->name = $name;
$this->value_starts_at = $value_start;
$this->value_length = $value_length;
$this->start = $start;
$this->end = $end;
$this->is_true = $is_true;
}
}
52 changes: 52 additions & 0 deletions src/wp-includes/html-api/class-wp-html-span.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* HTML Span: Represents a textual span inside an HTML document.
*
* @package WordPress
* @subpackage HTML-API
* @since 6.2.0
*/

/**
* Represents a textual span inside an HTML document.
*
* This is a two-tuple in disguise, used to avoid the memory
* overhead involved in using an array for the same purpose.
*
* This class is for internal usage of the WP_HTML_Tag_Processor class.
*
* @access private
* @since 6.2.0
*
* @see WP_HTML_Tag_Processor
*/
class WP_HTML_Span {
/**
* Byte offset into document where span begins.
*
* @since 6.2.0
* @var int
*/
public $start;

/**
* Byte offset into document where span ends.
*
* @since 6.2.0
* @var int
*/
public $end;

/**
* Constructor.
*
* @since 6.2.0
*
* @param int $start Byte offset into document where replacement span begins.
* @param int $end Byte offset into document where replacement span ends.
*/
public function __construct( $start, $end ) {
$this->start = $start;
$this->end = $end;
}
}
Loading