Skip to content

feat: first-class HTML block in the admin editor#1215

Open
scottbuscemi wants to merge 3 commits into
mainfrom
feat/html-block-editor
Open

feat: first-class HTML block in the admin editor#1215
scottbuscemi wants to merge 3 commits into
mainfrom
feat/html-block-editor

Conversation

@scottbuscemi
Copy link
Copy Markdown
Contributor

@scottbuscemi scottbuscemi commented May 29, 2026

What does this PR do?

Add a first-class HtmlBlockNode to the admin editor so the existing htmlBlock Portable Text type (produced by the WordPress and Contentful importers) becomes a fully editable block. Previously, imported htmlBlock content fell through to an opaque pluginBlock placeholder with the html field becoming inaccessible. Now authors can create and edit HTML blocks natively in the rich-text editor.

Closes discussion #1185

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: First-class HTML block in the admin editor #1185

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4 (via OpenCode)

Implementation details

New files

  • packages/admin/src/components/editor/HtmlBlockNode.tsx — TipTap atom node extension with React node view. Provides a textarea for editing raw HTML source, a Preview toggle that sanitizes via DOMPurify, drag handle, delete action, and selection ring. Modeled on PluginBlockNode.tsx.

  • packages/core/tests/unit/converters/html-block-round-trip.test.ts — Round-trip test verifying htmlBlock survives PT → PM → PT conversion in the core standalone converters.

Modified files

  • packages/admin/src/components/PortableTextEditor.tsx — Added htmlBlock cases to convertPMNode and convertPTBlock for round-trip conversion. Added /html slash command. Registered HtmlBlockExtension in the extensions array.

  • packages/core/src/components/InlinePortableTextEditor.tsx — Added htmlBlock cases to both converters, a read-only HtmlBlockNode TipTap extension (placeholder, like PluginBlockNode), /html slash command, and registered the extension.

  • packages/core/src/content/converters/types.ts — New PortableTextHtmlBlock interface, added to the PortableTextBlock union.

  • packages/core/src/content/converters/prosemirror-to-portable-text.ts — New convertHtmlBlock handler in the convertNode switch.

  • packages/core/src/content/converters/portable-text-to-prosemirror.ts — New htmlBlock case in convertBlock.

  • packages/core/src/index.ts — Exported PortableTextHtmlBlock type.

Key design decisions

  1. Atom node, not editable content — HTML blocks are atom nodes (like images and plugin blocks), not inline-editable text regions. The textarea is rendered via the React node view, not ProseMirror content editing.

  2. DOMPurify for preview — The admin package already depends on dompurify. The preview toggle runs through DOMPurify.sanitize() so authors see what will actually render, matching the server-side sanitizeContent in core.

  3. All user-facing strings wrapped with Linguit template literals for all button labels, descriptions, placeholder text, and aria attributes.

  4. RTL-safe — Uses logical properties (start/end) throughout.

  5. Inline editor as read-only placeholder — The visual-editing (inline) editor shows HTML blocks as a simple "HTML block (edit in admin)" placeholder, preserving the data losslessly on round-trip without needing to mount the full editing UI.


Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks feat/html-block-editor. Updated automatically when the playground redeploys.

Add HtmlBlockNode TipTap extension to the admin editor so the existing
htmlBlock Portable Text type (produced by WordPress and Contentful
importers) is a fully editable block rather than falling through to an
opaque pluginBlock placeholder.

- New HtmlBlockNode.tsx: atom node with textarea for source editing and
  a Preview toggle that sanitizes via DOMPurify
- Slash command entry (/html) and aliases (raw, markup)
- Round-trip conversion in all three converter locations:
  - PortableTextEditor.tsx (admin editor)
  - InlinePortableTextEditor.tsx (visual-editing editor)
  - Core standalone converters (prosemirror-to-portable-text.ts,
    portable-text-to-prosemirror.ts)
- New PortableTextHtmlBlock type in core converter types, exported from
  the emdash package
- Inline editor renders htmlBlock as a read-only placeholder to prevent
  data loss during visual editing
- Round-trip test for the core converters

Closes discussion #1185
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: d698e89

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
emdash Minor
@emdash-cms/admin Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 29, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs d698e89 May 29 2026, 07:42 PM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 29, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground d698e89 May 29 2026, 07:43 PM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1215

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1215

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1215

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1215

emdash

npm i https://pkg.pr.new/emdash@1215

create-emdash

npm i https://pkg.pr.new/create-emdash@1215

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1215

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1215

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1215

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1215

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1215

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1215

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1215

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1215

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1215

commit: d698e89

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 29, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache d698e89 May 29 2026, 07:43 PM

Drop the Eye/Preview toggle (DOMPurify-based sanitized preview) and the
character count subtitle from the HTML block header. The block is now a
straightforward textarea with a delete button.

This also removes the dompurify import from the component.
@github-actions
Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

Add HTML block documentation to the Working with Content guide:
- Add /html to the slash commands table
- Add HTML blocks to the editor feature list
- New 'HTML Blocks' section explaining the feature and its use cases
- Document the iframe sanitization allowlist limitation (youtube,
  vimeo only by default)
- Provide a full code example for overriding the htmlBlock component
  to allow additional iframe providers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant