-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Raw Handling: Fix grok markdown pasting issues #73019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Size Change: +46 B (0%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 668aea1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19952125715
|
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @ebinnion. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
Following PR review feedback, this narrows the non-semantic wrapper detection from span/div/p to only span elements. This reduces the risk of breaking third-party plugin transforms that rely on detecting div or p elements with specific classes, while still fixing the Grok markdown pasting issue. Also adds integration test with real Grok paste content to verify the fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Looks like the added test is failing. Could you tell Claude to run the unit test and fix? |
|
|
||
| it( 'can handle Grok markdown wrapped in a styled span', () => { | ||
| // Simulates pasting markdown from Grok, which wraps content in a styled span | ||
| const grokMarkdownHTML = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not quite what I had in mind. There's a folder with HTML input and output that we use as integration tests. What I had in mind is just adding the the input and expected output to this folder. It can be found at test/integration/fixtures/documents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to include.
- Remove failing unit test for Grok markdown paste handling - Add integration test fixtures (grok-markdown-in/out.html) - Update isPlain() JSDoc to reflect span-only wrapper detection Per review feedback, the test has been moved from a unit test to integration test fixtures following the established pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Updated some of the tests. |
| */ | ||
| export function isPlain( HTML ) { | ||
| return ! /<(?!br[ />])/i.test( HTML ); | ||
| // Existing check: no tags except <br> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably remove this and the new check comment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can be removed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new check will also have to run for non-span wrapped content though, hasSemanticChildren can be moved to the start.
Co-authored-by: Eric Binnion <[email protected]>
Co-authored-by: Marin Atanasov <[email protected]>
- Remove unnecessary inline comments from isPlain function - Add grok-markdown integration test fixtures - Add plain text version of grok markdown for clipboard simulation - Fix expected output heading levels to match markdown conversion 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Alright. Updated this PR in light of the feedback on the tests:
|
The try/catch block was not needed as none of the DOM operations in this function throw errors. Removing it allows any unexpected errors to surface properly rather than being silently suppressed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Co-authored-by: Miguel Fonseca <[email protected]>
- Fix critical bug: change 'element' to 'wrapper' variable reference - Remove unnecessary inline comments for cleaner code - Move semantic children check earlier in function logic to apply to all single-element content, not just span-wrapped content - Change to uppercase 'SPAN' tag comparison to conform with other raw-handling code All unit tests (13/13) and integration tests (60/60) passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
youknowriad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's land this.
|
Thanks for all the help here, all. |
What?
Fixes markdown paste from Grok by expanding the
isPlain()function to detect single non-semantic wrapper elements. I worked with @youknowriad and Claude on this :)Why?
Closes #72468
When copying markdown from Grok using "copy markdown", the clipboard contains both plain text (with markdown syntax like
**bold**,### headers) and HTML (a<span>wrapper with the same markdown text). Gutenberg was detecting the HTML wrapper and skipping markdown conversion, pasting the literal markdown syntax instead of converting it to blocks.How?
Expanded
isPlain()inpackages/blocks/src/api/raw-handling/utils.jsto returntruewhen:span)<br>tags)This allows the markdown converter to run on the plain text content instead of using the HTML wrapper.
Testing Instructions
Before
Markdown syntax appears literally in paragraph blocks
After
Markdown converts to proper block structure