Skip to content

Commit

Permalink
Refactor ImageCDN parsing to rely on HTML API instead of RegExps (#32700
Browse files Browse the repository at this point in the history
)

The introduction of the HTML API into WordPress 6.2 offers a new method of
matching and modifying HTML. In this patch we're replacing code that attempts
to parse the input HTML and visit all images, then read and modify them based
on the values of their attributes and computed Photon properties.

In the previous code the `Image_CDN` class scanned the entire HTML document to
generate a list of PREG image match objects, then iterated over those matches
and performed string-replace operations on them.

Now the class does a pass from start to finish, visting each image tag along
the way, and making the appropriate modifications.

Co-authored-by: Adnan Haque <3737780+haqadn@users.noreply.github.com>
Co-authored-by: Brandon Kraft <public@brandonkraft.com>
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
Co-authored-by: Mark George <thingalon@gmail.com>
Co-authored-by: Osk <oskosk@users.noreply.github.com>
  • Loading branch information
6 people committed Aug 23, 2024
1 parent 474f7f3 commit 424e68a
Show file tree
Hide file tree
Showing 2 changed files with 349 additions and 280 deletions.
4 changes: 4 additions & 0 deletions projects/packages/image-cdn/changelog/html-api-for-image-cdn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Rely on WordPress HTML API to parse HTML instead of Regex
Loading

0 comments on commit 424e68a

Please sign in to comment.