Raw handling: fix shortcode conversion when separated by <br /> tags#76213
Raw handling: fix shortcode conversion when separated by <br /> tags#76213youknowriad merged 1 commit intotrunkfrom
Conversation
Fixes shortcode-to-block conversion failing when shortcodes have only single newlines (no empty lines) before/after them. When the block parser applies autop() to freeform block content, single newlines are converted to <br />\n, causing the shortcode converter's line-boundary regex patterns to fail to recognize the shortcode as block-level. Updated the beforeLineRegexp and afterLineRegexp patterns to recognize <br>, <br/>, and <br /> as line boundaries, in addition to \n and <p>/<\/p> tags. Fixes #76140 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +8 B (0%) Total Size: 6.87 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in cbe812d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22735105256
|
What?
Closes #76140
Fixes shortcode-to-block conversion failing when shortcodes are not surrounded by empty lines.
Why?
When the block parser applies
autop()to freeform block content, single newlines between lines are converted to<br />\nHTML. The shortcode converter's line-boundary regex patterns only recognized\nand<p>/</p>tags, causing shortcodes wrapped by<br />to be incorrectly treated as inline text instead of block-level elements.How?
Updated the
beforeLineRegexpandafterLineRegexppatterns in the shortcode converter to also recognize<br>,<br/>, and<br />as valid line boundaries. Added test coverage for the bug scenario.Testing Instructions
(Replace the IDs with actual image IDs from your media library)
Run tests:
npm run test:unit -- --testNamePattern="segmentHTMLToShortcodeBlock"All 11 tests pass, including 2 new tests that verify the fix works correctly.