mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This includes the following commits: - https://core.trac.wordpress.org/changeset/59285 - https://core.trac.wordpress.org/changeset/59364 - https://core.trac.wordpress.org/changeset/59747 Backport needed to be manually merged due to file conflicts. Trac Ticket: https://core.trac.wordpress.org/ticket/62270
- Loading branch information
1 parent
1c02e68
commit 5c0e7d5
Showing
3 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/phpunit/data/html-api/token-counting-html-processor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
class Token_Counting_HTML_Processor extends WP_HTML_Processor { | ||
|
||
/** | ||
* List of tokens that have already been seen. | ||
* | ||
* @var array<string, int> | ||
*/ | ||
public $token_seen_count = array(); | ||
|
||
/** | ||
* Gets next token. | ||
* | ||
* @return bool Whether next token was matched. | ||
*/ | ||
public function next_token(): bool { | ||
$result = parent::next_token(); | ||
|
||
if ( $this->get_token_type() === '#tag' ) { | ||
$token_name = ( $this->is_tag_closer() ? '-' : '+' ) . $this->get_tag(); | ||
} else { | ||
$token_name = $this->get_token_name(); | ||
} | ||
|
||
if ( ! isset( $this->token_seen_count[ $token_name ] ) ) { | ||
$this->token_seen_count[ $token_name ] = 1; | ||
} else { | ||
++$this->token_seen_count[ $token_name ]; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters