Skip to content

Formatting: Prevent wpautop() from splitting anchors around block elements#12512

Open
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-40202-wpautop-anchor-blocks
Open

Formatting: Prevent wpautop() from splitting anchors around block elements#12512
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-40202-wpautop-anchor-blocks

Conversation

@ArkaPrabhaChowdhury

Copy link
Copy Markdown

Prevents wpautop() from generating invalid markup when an anchor wraps one or more block-level elements. The affected anchors are temporarily treated as block containers during paragraph cleanup, then restored without changing normal inline anchors. The placeholder name is selected to avoid collisions with existing content.

Trac ticket: https://core.trac.wordpress.org/ticket/40202

Testing

  • npm run test:php -- --group 40202
  • npm run test:php -- --filter Tests_Formatting_wpAutop
  • PHPCBF on the changed files
  • PHPCS on the changed files

Use of AI Tools

AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-5
Used for: Ticket analysis, implementation, test coverage, validation, and pull request drafting; the final changes were reviewed and validated by the contributor.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@wpankit

wpankit commented Jul 14, 2026

Copy link
Copy Markdown

Picked through the diff. Looks like this only touches formatting.php, but wpautop also has a JS version in @wordpress/autop that usually needs the same fix to stay in sync.

The other thing on wpautop is regressions. Do the existing Tests_Formatting_wpAutop cases still pass, or just the new ones? Happy to run it if you haven't.

@ArkaPrabhaChowdhury

Copy link
Copy Markdown
Author

Thanks @wpankit — you are right about keeping the JavaScript implementation synchronized.

The @wordpress/autop source is maintained in Gutenberg (the wordpress-develop dist files are ignored generated output), so I added the matching implementation and regression coverage in WordPress/gutenberg#80232: WordPress/gutenberg#80232

Validation completed:

  • Full PHP Tests_Formatting_wpAutop class: 26 tests, 36 assertions passed.
  • Targeted PHP ticket group: 1 test, 2 assertions passed.
  • Full JavaScript packages/autop/src/test/index.test.ts: 19/19 tests passed.
  • JavaScript ESLint and the packages/autop TypeScript check passed.

So both the existing PHP and JavaScript regression suites pass, not only the new cases.

@ArkaPrabhaChowdhury ArkaPrabhaChowdhury marked this pull request as ready for review July 14, 2026 08:09
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props arkaprabhachowdhury, ankitmaru.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants