Skip to content

Commit

Permalink
Add some constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Nov 28, 2023
1 parent a21f5a3 commit ed23e55
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,31 @@ class WP_HTML_Tag_Processor {
*/
private $is_closing_tag;

/**
* What kind of node was parsed in the last step while scanning through the document,
* or if the parser hasn't paused on a matched token, then `null`.
*
* Can be one of:
* - WP_HTML_Tag_Processor::ELEMENT_NODE
* - WP_HTML_Tag_Processor::TEXT_NODE
* - WP_HTML_Tag_Processor::CDATA_SECTION_NODE
* - WP_HTML_Tag_Processor::PROCESSING_INSTRUCTION_NODE
* - WP_HTML_Tag_Processor::COMMENT_NODE
* - WP_HTML_Tag_Processor::DOCUMENT_TYPE_NODE
* - WP_HTML_Tag_Processor::WP_FUNKY_COMMENT_NODE
*
* @var string|null
*/
private $last_token_type = null;

/**
* In what mode the parser should resume after pausing,
* or if not paused on a matched token, then `null`.
*
* @var string|null
*/
private $continuation_state = null;

/**
* Lazily-built index of attributes found within an HTML tag, keyed by the attribute name.
*
Expand Down Expand Up @@ -567,7 +592,7 @@ public function next_tag( $query = null ) {
return false;
}
$this->tag_ends_at = $tag_ends_at;
$this->bytes_already_parsed = $tag_ends_at;
$this->bytes_already_parsed = min( strlen( $this->html ) - 1, $tag_ends_at + 1 );

// Finally, check if the parsed tag and its attributes match the search query.
if ( $this->matches() ) {
Expand Down Expand Up @@ -2447,4 +2472,17 @@ private function matches() {

return true;
}

// Constants that would otherwise be noisy at the top of the file.

const ELEMENT_NODE = 'NodeType.1.ELEMENT_NODE';
const TEXT_NODE = 'NodeType.3.TEXT_NODE';
const CDATA_SECTION_NODE = 'NodeType.4.CDATA_SECTION_NODE';
const PROCESSING_INSTRUCTION_NODE = 'NodeType.7.PROCESSING_INSTRUCTION_NODE';
const COMMENT_NODE = 'NodeType.8.COMMENT_NODE';
const DOCUMENT_TYPE_NODE = 'NodeType.10.DOCUMENT_TYPE_NODE';
const WP_FUNKY_COMMENT_NODE = 'NodeType.0_1.WP_FUNKY_COMMENT_NODE';

const STATE_COMPLETE = 'The parser has finished scanning through the document.';
const STATE_IN_TAG = 'The parser has found a valid tag name and needs to continue parsing attributes.';
}

0 comments on commit ed23e55

Please sign in to comment.