HTML API: Refactor wp_strip_all_tags() - #6196
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
df2ca53 to
5837af5
Compare
f46f459 to
9fdccc4
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Trac ticket: Core-65984 Replaces the internal logic of `wp_strip_all_tags()` away from `strip_tags()` and relies on the HTML API instead. The contract of the function changes subtly with this: instead of returning the raw non-tag content of an HTML document, this returns the normalized text nodes that are part of the renderable page, if CSS properties are ignored (e.g. those which change visibility).
9fdccc4 to
866fc80
Compare
Trac ticket: Core-65984.
Rewrites the logic of
wp_strip_all_tags()to rely on the HTML API rather than onstrip_tags(), due to the challengesstrip_tags()has with properly parsing HTML. The new version of the function returns renderable text nodes, normalized and re-escaped for more predictable inputs into downstream parsers.Notable changes
SCRIPTandSTYLEtags used to be lifted out of the elements, which led to data corruption, as these contents are not intended to be renderable with the rest of the text nodes. These are no longer included in the function outputs; the same is true for the “special atomic elements” defined by the HTML API (IFRAME,TEXTAREA,TITLE, etc…)wp_html_excerpt()previously truncated early when the number of characters requested fell inside an HTML character reference, but since character references are now decoded before truncating, the function should more reliably return a string of the requested count of code points.wp_strip_all_tags(), each declaration runs its property and values separately throughwp_strip_all_tags(). This removes some corruption that occurred when there were spans of text resembling incomplete HTML syntax tokens.