[wp-trac] [WordPress Trac] #62036: HTML API: Introduce normalization methods.
WordPress Trac
noreply at wordpress.org
Wed Sep 11 16:20:08 UTC 2024
#62036: HTML API: Introduce normalization methods.
-------------------------+--------------------
Reporter: dmsnell | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.7
Component: HTML API | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+--------------------
Since the HTML Processor knows how to parse HTML, it should provide a
method for //normalizing// HTML, returning a fully-well-formed equivalent
of what it sent its way.
{{{#!php
<?php
echo WP_HTML_Processor::normalize('<a href=#anchor v=5 href="/"
enabled>One</a another v=5><!--');
// <a href="#anchor" v="5" enabled>One</a>
}}}
Such a method can power a safe implementation of `set_inner_html()` which
prevents problems typical of slicing and concatenating HTML.
Additionally, this approach of serializing HTML in order to normalize it
provides a more robust interface for what `force_balance_tags()` attempts
to do. In fact, normalizing HTML at the start of any processing pipeline
will ensure that naive HTML processing code down the line won't get
confused by HTML's syntax quirks.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62036>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list