Make WordPress Core

Changeset 58192

Timestamp:
05/24/2024 01:19:10 AM (2 months ago)
Author:
dmsnell
Message:

HTML API: Add expects_closer() method to HTML Processor

This patch adds a new method, WP_HTML_Processor->expects_closer() to indicate
if the currently-matched node expects to find a closing token. For example, a
DIV element expects a closing </div> tag, but an <img> expects none, because
it's a void element. Similarly, #text nodes and HTML comments only appear as
unitary nodes on the stack of open elements. Once proceeding further in the
document they are immediately removed without any closing tag.

This new method serves as a helper to indicate whether or not to expect the
closer, as this can be more complicated than it seems, and calling code
shouldn't have to build custom interpretations and implementations. Instead,
the HTML Processor ought to export its internal knowledge to make it easy for
consuming code and projects.

Developed in https://github.com/WordPress/wordpress-develop/pull/6600
Discussed in https://core.trac.wordpress.org/ticket/61257

Fixes #61257.
Props dmsnell, jonsurrell.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r58191 r58192  
    507507
    508508        return false;
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
    509547    }
    510548
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r58191 r58192  
    180180            $processor->get_breadcrumbs(),
    181181            "DIV should have been a sibling of the {$tag_name}."
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269
     270
     271
     272
     273
     274
     275
     276
     277
     278
    182279        );
    183280    }
Note: See TracChangeset for help on using the changeset viewer.