#61617 closed enhancement (fixed)
HTML API: Add method to replace modifiable text.
Reported by: | dmsnell | Owned by: | dmsnell |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 6.6 |
Component: | HTML API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
The HTML API has provided get_modifiable_text()
since WordPress 6.5, but it has never provided a method to change the modifiable text for a given token in the document.
It should provide this function to make it possible to safely replace HTML text nodes.
Change History (7)
This ticket was mentioned in PR #7007 on WordPress/wordpress-develop by @dmsnell.
4 weeks ago
#1
- Keywords has-unit-tests added
@zieladam commented on PR #7007:
3 weeks ago
#2
get_updated_html()
might need this adjustment:
if ($this->get_token_type() === '#tag') { $this->bytes_already_parsed = $before_current_tag; }
Without it, replacing a longer string with a shorter one can make $this->bytes_already_parsed
negative.
10 days ago
#3
get_updated_html() might need this adjustment:
Thanks @adamziel - this level of review is so helpful! Unfortunately, when I added a test to try and trigger the condition, I couldn't. What do you think? Do you see any problem with this?
#4
@
7 days ago
- Owner set to dmsnell
- Resolution set to fixed
- Status changed from new to closed
In 58829:
@zieladam commented on PR #7007:
5 days ago
#6
Thanks @adamziel - this level of review is so helpful! Unfortunately, when I added a test to try and trigger the condition, I couldn't. What do you think? Do you see any problem with this?
That test looks good. I'd also check for regular tags like DIV
and then for HTML comments. I ran into that in https://github.com/adamziel/site-transfer-protocol, although now can't find the commit where I did it. Eventually I've switched to a different method of setting modifiable text, and now I'm happy to migrate to this now that it's merged.
Trac ticket: Core-61617
This patch introduces a new method,
set_modifiable_text()
to the Tag Processor, which makes it possible and safe to replace text nodes within an HTML document, performing the appropriate escaping.This method can be used in conjunction with other code to modify the text content of a document, and can be used for transforming HTML in a streaming fashion.