Blocks: Add paste handler for Grok AI content#72696
Conversation
Converts Grok AI's span-based HTML to semantic HTML when pasting. Handles headings, bold, and italic formatting by detecting Grok's distinctive CSS classes.
|
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. |
|
@ellatrix not sure if you'd have time to review this but it would be helpful! |
|
I don't think we should try to infer semantic content from random classes and styles tbh (which can change any time when they roll out a new UI version). This would mean we set a precedent for custom paste handling from all sort of apps and sites in Gutenberg. Instead we should push Grok to use semantic elements. |
|
I agree with @ellatrix. Core shouldn't maintain mappings for similar random classes across apps. I think this is "won't fix" for now. |
What?
Closes #72469
Adds paste handler support for Grok AI content to properly convert headings and formatting when pasting into the Gutenberg editor.
Why?
When pasting content from Grok AI into the Gutenberg editor, headings and formatting were not being preserved. Grok AI uses span elements with CSS classes for both structure (headings) and styling (bold, italic) instead of semantic HTML tags. This resulted in:
This differs from other AI sources like ChatGPT which use proper semantic HTML that Gutenberg already handles correctly.
How?
Implemented a new
grok-converter.jspaste handler that detects and transforms Grok AI's proprietary HTML structure to semantic HTML:Detection Strategy:
Transformations:
<strong>tags<em>tagsTesting Instructions
Testing Instructions