Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions html-api-debugger/html-api-debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Plugin URI: https://github.com/sirreal/html-api-debugger
* Description: Add a page to wp-admin for debugging the HTML API.
* Version: 2.9
* Requires at least: 6.7
* Tested up to: 6.8
* Requires at least: 6.9
* Tested up to: 7.2
* Author: Jon Surrell
* Author URI: https://profiles.wordpress.org/jonsurrell/
* License: GPLv2 or later
Expand Down
35 changes: 8 additions & 27 deletions html-api-debugger/html-api-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
function get_supports(): array {
return array(
'create_fragment_advanced' => method_exists( WP_HTML_Processor::class, 'create_fragment_at_current_node' ),
'selectors' =>
class_exists( '\WP_CSS_Complex_Selector_List' )
|| class_exists( '\WP_CSS_Compound_Selector_List' ),
Expand All @@ -27,15 +26,10 @@ class_exists( '\WP_CSS_Complex_Selector_List' )
* @return string|null The normalized HTML or null if not supported.
*/
function get_normalized_html( string $html, array $options ): ?string {
if ( method_exists( WP_HTML_Processor::class, 'create_fragment_at_current_node' ) ) {
$cfacn = new ReflectionMethod( WP_HTML_Processor::class, 'create_fragment_at_current_node' );
$cfacn->setAccessible( true );
}
$cfacn = new ReflectionMethod( WP_HTML_Processor::class, 'create_fragment_at_current_node' );
$cfacn->setAccessible( true );

if (
method_exists( WP_HTML_Processor::class, 'create_fragment_at_current_node' ) &&
$options['context_html']
) {
if ( $options['context_html'] ) {
$context_processor = WP_HTML_Processor::create_full_parser( $options['context_html'] );

add_filter( 'doing_it_wrong_trigger_error', __NAMESPACE__ . '\filter_doing_it_wrong_trigger_error', 10, 2 );
Expand Down Expand Up @@ -103,10 +97,8 @@ function get_tree( string $html, array $options ): array {
$processor_bookmarks = new ReflectionProperty( WP_HTML_Processor::class, 'bookmarks' );
$processor_bookmarks->setAccessible( true );

if ( method_exists( WP_HTML_Processor::class, 'create_fragment_at_current_node' ) ) {
$cfacn = new ReflectionMethod( WP_HTML_Processor::class, 'create_fragment_at_current_node' );
$cfacn->setAccessible( true );
}
$cfacn = new ReflectionMethod( WP_HTML_Processor::class, 'create_fragment_at_current_node' );
$cfacn->setAccessible( true );

$is_fragment_processor = false;
$processor_depth_offset = 0;
Expand All @@ -117,10 +109,7 @@ function get_tree( string $html, array $options ): array {
$doctype_public_identifier = null;
$doctype_system_identifier = null;

if (
method_exists( WP_HTML_Processor::class, 'create_fragment_at_current_node' ) &&
$options['context_html']
) {
if ( $options['context_html'] ) {
$context_processor = WP_HTML_Processor::create_full_parser( $options['context_html'] );

add_filter( 'doing_it_wrong_trigger_error', __NAMESPACE__ . '\filter_doing_it_wrong_trigger_error', 10, 2 );
Expand All @@ -131,11 +120,7 @@ function get_tree( string $html, array $options ): array {
$doctype_name = $doctype->name;
$doctype_public_identifier = $doctype->public_identifier;
$doctype_system_identifier = $doctype->system_identifier;
if (
( property_exists( $doctype, 'indicated_compatibility_mode' )
? $doctype->indicated_compatibility_mode
: $doctype->indicated_compatability_mode ) !== 'quirks'
) {
if ( $doctype->indicated_compatibility_mode !== 'quirks' ) {
$compat_mode = 'CSS1Compat';
}
break;
Expand Down Expand Up @@ -267,11 +252,7 @@ function get_tree( string $html, array $options ): array {
$doctype_name = $doctype->name;
$doctype_public_identifier = $doctype->public_identifier;
$doctype_system_identifier = $doctype->system_identifier;
if (
( property_exists( $doctype, 'indicated_compatibility_mode' )
? $doctype->indicated_compatibility_mode
: $doctype->indicated_compatability_mode ) !== 'quirks'
) {
if ( $doctype->indicated_compatibility_mode !== 'quirks' ) {
$compat_mode = 'CSS1Compat';
}

Expand Down
48 changes: 24 additions & 24 deletions html-api-debugger/interactivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function generate_page( string $html, array $options ): string {
'htmlApiDocumentTitle' => $htmlapi_response['result']['documentTitle'] ?? null,
'htmlApiDoctypeName' => $htmlapi_response['result']['doctypeName'] ?? null,
'htmlApiDoctypePublicId' => $htmlapi_response['result']['doctypePublicId'] ?? null,
'htmlApiDoctypeSytemId' => $htmlapi_response['result']['doctypeSystemId'] ?? null,
'htmlApiDoctypeSystemId' => $htmlapi_response['result']['doctypeSystemId'] ?? null,
'treeWarnings' => $htmlapi_response['result']['warnings'] ?? array(),
'normalizedHtml' => $htmlapi_response['normalizedHtml'] ?? '',

Expand All @@ -60,23 +60,23 @@ function generate_page( string $html, array $options ): string {
?>
<div
data-wp-interactive="<?php echo esc_attr( \HTML_API_Debugger\SLUG ); ?>"
data-wp-watch--main="watch"
data-wp-watch--url="watchURL"
data-wp-watch---main="watch"
data-wp-watch---url="watchURL"
data-wp-init="run"
class="html-api-debugger-container html-api-debugger--grid"
>
<div data-wp-bind--hidden="!state.htmlapiResponse.supports.create_fragment_advanced" class="full-width">
<div class="full-width">
<div class="heading-and-button">
<label for="context-html">Context in which input HTML finds itself</label>
<button type="button" data-wp-on-async--click="handleDefaultBodyContextClick">Use HTML5 BODY context</button>
<button type="button" data-wp-on--click="handleDefaultBodyContextClick">Use HTML5 BODY context</button>
</div>
<textarea
id="context-html"
class="context-html"
placeholder="Provide a fragment context, for example:&#x0A;<!DOCTYPE html><body>"
title="Leave blank to parse a full document."
rows="2"
data-wp-on-async--input="handleContextHtmlInput"
data-wp-on--input="handleContextHtmlInput"
><?php echo "\n" . esc_textarea( str_replace( "\0", '', $options['context_html'] ?? '' ) ); ?></textarea>
</div>
<div>
Expand All @@ -87,7 +87,7 @@ class="context-html"
autocomplete="off"
spellcheck="false"
wrap="off"
data-wp-on-async--input="handleInput"
data-wp-on--input="handleInput"
><?php echo "\n" . esc_textarea( str_replace( "\0", '', $html ) ); ?></textarea>
</div>
<div class="iframe-container">
Expand Down Expand Up @@ -128,41 +128,41 @@ class="context-html"
<div>
<div class="heading-and-button">
<h2>Interpreted by HTML API</h2>
<button type="button" data-wp-on-async--click="handleCopyTreeClick" name="tree__html-api">Copy tree 📋</button>
<button type="button" data-wp-on--click="handleCopyTreeClick" name="tree__html-api">Copy tree 📋</button>
</div>
<div
data-wp-on-async--mouseover="handleSpanOver"
data-wp-on-async--mouseleave="clearSpan"
data-wp-on--mouseover="handleSpanOver"
data-wp-on--mouseleave="clearSpan"
>
<pre class="error-holder" data-wp-bind--hidden="!state.htmlapiResponse.error" data-wp-text="state.htmlapiResponse.error"></pre>
<div data-wp-bind--hidden="state.htmlapiResponse.error">
<ul id="html_api_result_holder" data-wp-ignore></ul>
<ul id="html_api_result_holder"></ul>
</div>
</div>
</div>
<div>
<div class="heading-and-button">
<h2>Interpreted from DOM</h2>
<button type="button" data-wp-on-async--click="handleCopyTreeClick" name="tree__dom">Copy tree 📋</button>
<button type="button" data-wp-on--click="handleCopyTreeClick" name="tree__dom">Copy tree 📋</button>
</div>
<div data-wp-class--mutated="state.hasMutatedDom"><ul id="dom_tree" data-wp-ignore></ul></div>
<div data-wp-class--mutated="state.hasMutatedDom"><ul id="dom_tree"></ul></div>
</div>
</div>

<div class="full-width">
<div>
<div>
<label>Show closers <input type="checkbox" data-wp-bind--checked="state.showClosers" data-wp-on-async--input="handleShowClosersClick"></label>
<label>Show invisible <input type="checkbox" data-wp-bind--checked="state.showInvisible" data-wp-on-async--input="handleShowInvisibleClick"></label>
<span><label>Show virtual <input type="checkbox" data-wp-bind--checked="state.showVirtual" data-wp-on-async--input="handleShowVirtualClick"></label></span>
<label>Show closers <input type="checkbox" data-wp-bind--checked="state.showClosers" data-wp-on--input="handleShowClosersClick"></label>
<label>Show invisible <input type="checkbox" data-wp-bind--checked="state.showInvisible" data-wp-on--input="handleShowInvisibleClick"></label>
<span><label>Show virtual <input type="checkbox" data-wp-bind--checked="state.showVirtual" data-wp-on--input="handleShowVirtualClick"></label></span>
<div data-wp-bind--hidden="!state.htmlapiResponse.supports.selectors">
<label>CSS Selectors <textarea id="selector-input" placeholder="CSS selector: .my-class" data-wp-on-async--input="handleSelectorChange"><?php echo "\n" . esc_textarea( str_replace( "\0", '', $options['selector'] ?? '' ) ); ?></textarea></label>
<label>CSS Selectors <textarea id="selector-input" placeholder="CSS selector: .my-class" data-wp-on--input="handleSelectorChange"><?php echo "\n" . esc_textarea( str_replace( "\0", '', $options['selector'] ?? '' ) ); ?></textarea></label>
</div>
</div>
<div>
<label>
Hover information
<select data-wp-on-async--change="hoverInfoChange">
<select data-wp-on--change="hoverInfoChange">
<option data-wp-bind--selected="state.hoverBreadcrumbs" value="breadcrumbs">(depth) Breadcrumbs…</option>
<option data-wp-bind--selected="state.hoverInsertion" value="insertionMode">Insertion mode</option>
</select>
Expand Down Expand Up @@ -192,7 +192,7 @@ class="context-html"
>
</label>
</div>
<pre class="html-text" id="processed-html" data-wp-ignore><?php echo esc_html( $html ); ?></pre>
<pre class="html-text" id="processed-html"><?php echo esc_html( $html ); ?></pre>
</div>

<p>
Expand All @@ -201,21 +201,21 @@ class="context-html"
<option value="latest">latest</option>
<option value="nightly">nightly</option>
<option value="beta">beta</option>
<option value="6.7">6.7</option>
<option value="6.9">6.9</option>
</select>
</label>
<button data-wp-on-async--click="handleCopyClick" type="button">Copy shareable playground link</button><br>
<button data-wp-on--click="handleCopyClick" type="button">Copy shareable playground link</button><br>
</p>
<p>
<label>
<code>WordPress/develop</code> PR number:
<input type="number" min="1" data-wp-on-async--input="handleCopyCorePrInput">
<input type="number" min="1" data-wp-on--input="handleCopyCorePrInput">
</label>
<label>
<code>WordPress/gutenberg</code> PR number:
<input type="number" min="1" data-wp-on-async--input="handleCopyGutenbergPrInput">
<input type="number" min="1" data-wp-on--input="handleCopyGutenbergPrInput">
</label>
<button data-wp-on-async--click="handleCopyPrClick">Copy shareable playground link to PR</button>
<button data-wp-on--click="handleCopyPrClick">Copy shareable playground link to PR</button>
<span data-wp-bind--hidden="!state.previewCoreLink">
<a
data-wp-bind--href="state.previewCoreLink.href"
Expand Down
5 changes: 1 addition & 4 deletions html-api-debugger/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ let mutationObserver = null;
*
*
* @typedef Supports
* @property {boolean} create_fragment_advanced
* @property {boolean} selectors
*
*
Expand Down Expand Up @@ -191,9 +190,7 @@ const store = createStore( NS, {
},

get contextHTMLForUse() {
return store.state.htmlapiResponse.supports.create_fragment_advanced
? store.state.contextHTML.trim() || null
: null;
return store.state.contextHTML.trim() || null;
},

/** @type {Link|null} */
Expand Down
7 changes: 5 additions & 2 deletions html-api-debugger/readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=== HTML API Debugger ===
Contributors: jonsurrell, bernhard-reiter
Tags: HTML API, development, debug
Requires at least: 6.7
Tested up to: 6.8
Requires at least: 6.9
Tested up to: 7.2
Stable tag: 2.9
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand All @@ -20,6 +20,9 @@ Please file issues and pull requests on the [GitHub repository](https://github.c
* Add "HTML5 Body" context button to allow setting default context.
* Fix fragment tree depth so nodes following atomic elements (`textarea`, `script`, `style`) nest correctly to match the DOM tree.
* Use `get_full_comment_text()` to get comment text in the tree.
* Change `on-async` (deprecated) directives to `on`.
* Fix tree views not updating in WordPress 7.2.
* Drop support for WordPress 6.7 and 6.8.

= 2.9 =
* Fix implicit nullable parameter.
Expand Down