Skip to content

Blocks: Add paste handler for Grok AI content#72696

Closed
mecskyverse wants to merge 2 commits into
WordPress:trunkfrom
mecskyverse:fix/grok-paste-handling
Closed

Blocks: Add paste handler for Grok AI content#72696
mecskyverse wants to merge 2 commits into
WordPress:trunkfrom
mecskyverse:fix/grok-paste-handling

Conversation

@mecskyverse

Copy link
Copy Markdown
Contributor

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:

  • Headings appearing as plain text without line breaks
  • All content concatenated into a single paragraph
  • Loss of bold and italic formatting
  • Poor content structure and readability

This differs from other AI sources like ChatGPT which use proper semantic HTML that Gutenberg already handles correctly.

How?

Implemented a new grok-converter.js paste handler that detects and transforms Grok AI's proprietary HTML structure to semantic HTML:

Detection Strategy:

  • Uses CSS class pattern matching to identify Grok's distinctive atomic CSS classes
  • Detects block-level spans (display: block) with font-size classes for headings
  • Requires both size and bold classes to avoid false positives
  • Only processes SPAN elements, leaving other HTML untouched

Transformations:

  1. Headings: Converts spans with heading size classes (r-uho16t, r-1blvdjr, etc.) and bold classes to proper heading elements (H1, H2, H3, etc.)
  2. Bold text: Converts spans with font-weight classes (r-b88u0q, r-1vr29t4) to <strong> tags
  3. Italic text: Converts spans with italic class (r-36ujnk) to <em> tags

Testing Instructions

Testing Instructions

  1. Go to Grok AI and generate content with headings
  2. Example prompt: "Create a guide on 'WordPress Getting Started' with headings and subheadings"
  3. Copy the generated content from Grok
  4. Open WordPress editor and create a new post/page
  5. Paste the content into the editor
  6. Verify that headings, Italics and bold font are properly converted to Semantic tags like H1, H2, strong etc.
  7. Verify that content is properly separated into paragraphs (not concatenated)
Before After
before-grok-paste.webm After-grok-paste-compressed.webm

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.
@github-actions

github-actions Bot commented Oct 27, 2025

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mecskyverse <aakashverma1@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>

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

@priethor priethor added the [Type] Bug An existing feature does not function as intended label Oct 29, 2025
@annezazu

annezazu commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

@ellatrix not sure if you'd have time to review this but it would be helpful!

@ellatrix

ellatrix commented Nov 5, 2025

Copy link
Copy Markdown
Member

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.

@Mamaduka

Mamaduka commented May 6, 2026

Copy link
Copy Markdown
Member

I agree with @ellatrix. Core shouldn't maintain mappings for similar random classes across apps.

I think this is "won't fix" for now.

@annezazu annezazu closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copying/pasting from Grok doesn't include text formatting

5 participants