Skip to content

fix(editor): highlight code blocks in editors - #2606

Merged
khoinguyenpham04 merged 9 commits into
mainfrom
codex/issue-2361-code-block-spec
Aug 27, 2026
Merged

khoinguyenpham04 merged 9 commits into
mainfrom
codex/issue-2361-code-block-spec

Conversation

@khoinguyenpham04

@khoinguyenpham04 khoinguyenpham04 commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes code blocks in the admin and inline visual editors so supported languages are syntax-highlighted on borderless light and dark surfaces. Unsupported language values continue to round-trip safely and render as plain text.

This is the bottom pull request in native stack #2607. The controls and visual-polish follow-up is #2603.

Closes #2361

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 — verified for the affected admin and core packages
  • 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). No catalog files are included.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package) — .changeset/bright-code-blocks.md
  • New features link to an approved Discussion: N/A — this fixes existing editor behavior

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI GPT-5.6 Codex, reviewed with GPT-5.6 Terra xhigh

Screenshots / test output

  • Type-aware lint passed.
  • Admin and core typechecks passed.
  • Focused admin and inline code-block tests passed.
  • Admin and core builds completed.
  • Browser-verified syntax highlighting and borderless light/dark surfaces in both editors.
  • The focused Playwright spec is included; its isolated local runner is currently blocked by the existing fixture-dependency build step, so the equivalent flows were also verified directly against the local app.

@changeset-bot

changeset-bot Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0d437fc

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

This PR includes changesets to release 16 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@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/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@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

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 957 lines across 17 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://codex-issue-2361-code-block-spec.try.emdashcms.com, https://codex-issue-2361-code-block-spec-emdash-playground.emdash-cms.workers.dev (commit 0d437fc)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8b27035c.try.emdashcms.com, https://8b27035c-emdash-playground.emdash-cms.workers.dev 0d437fc 2026-08-27T16:52:01.910Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://e9f92dab.try.emdashcms.com, https://e9f92dab-emdash-playground.emdash-cms.workers.dev 463b827 2026-08-27T15:25:11.477Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://34d4afca.try.emdashcms.com, https://34d4afca-emdash-playground.emdash-cms.workers.dev e2655b3 2026-08-26T10:12:04.995Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f83a3752.try.emdashcms.com, https://f83a3752-emdash-playground.emdash-cms.workers.dev 43f23ab 2026-08-25T15:58:57.372Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://e5412461.try.emdashcms.com, https://e5412461-emdash-playground.emdash-cms.workers.dev 03a8e27 2026-08-24T10:26:24.592Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f7884af8.try.emdashcms.com, https://f7884af8-emdash-playground.emdash-cms.workers.dev 9ab02fc 2026-08-23T22:05:51.242Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://6cd52a89.try.emdashcms.com, https://6cd52a89-emdash-playground.emdash-cms.workers.dev 8040fab 2026-08-23T21:15:24.589Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://cdfa0b9a.try.emdashcms.com, https://cdfa0b9a-emdash-playground.emdash-cms.workers.dev a996b74 2026-08-22T22:55:18.007Z Visit the dashboard ↗

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

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 463b827 Aug 27 2026, 03:20 PM

@pkg-pr-new

pkg-pr-new Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-cli@2606

@emdash-cms/plugin-types

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-types@2606

@emdash-cms/registry-client

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-client@2606

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-lexicons@2606

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-moderation@2606

@emdash-cms/registry-verification

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-verification@2606

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/sandbox-workerd@2606

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-field-kit@2606

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 0d437fc

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

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 e2655b3 Aug 26 2026, 10:08 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

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-do e2655b3 Aug 26 2026, 10:06 AM

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

@github-actions github-actions Bot mentioned this pull request Aug 23, 2026
10 of 18 tasks
@khoinguyenpham04
khoinguyenpham04 marked this pull request as ready for review August 23, 2026 10:19
@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 23, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right change for issue #2361. Swapping the plain TipTap codeBlock node for @tiptap/extension-code-block-lowlight with a bounded common + dockerfile grammar set, a plaintext fallback, and scoped CSS variables hits the approved design: supported languages are highlighted in both editors, unsupported strings round-trip as plain text, and the public Code.astro renderer is untouched. The tests cover the important boundary (token spans, plain fallback, language changes, non-string language coercion) and the changeset/packages are appropriate.

I checked the changed source files, the converter tests, the E2E spec, the public code-block component, the catalog/package changes, and the admin theme provider. The only real issue I found is an AGENTS.md convention violation: the new Lowlight instances are module-scope singletons rather than living on globalThis, which can duplicate the heavy grammar map across Vite SSR chunks. Everything else looks solid. Verdict: comment.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond review/needs-rereview New commits since the last review and removed review/needs-review No maintainer or bot review yet review/awaiting-author Reviewed; waiting on the author to respond labels Aug 23, 2026
@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Aug 23, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right fix for issue #2361. Swapping the plain TipTap codeBlock node for @tiptap/extension-code-block-lowlight with a bounded common + dockerfile grammar set, a plaintext fallback, and scoped CSS variables matches the approved design: supported languages are highlighted in both the admin and inline visual editors, unsupported strings round-trip as plain text, and the public Code.astro renderer is untouched.

I re-checked the changed source files, the converter tests, the E2E spec, the public code-block component, the package/catalog changes, and the admin/inline theme styles. The only real issue from the previous review — the Lowlight instances being module-scope singletons rather than living on globalThis, which could duplicate the heavy grammar map across Vite SSR chunks — has been fixed in both packages/admin/src/components/editor/CodeBlockNode.tsx and packages/core/src/components/inline-code-block.tsx. Both now use a Symbol.for key on globalThis per AGENTS.md.

Other notable pieces look solid:

  • The non-string language guard is applied consistently at both Portable Text-to-ProseMirror boundaries (PortableTextEditor.tsx and InlinePortableTextEditor.tsx), so malformed stored values become null instead of crashing decoration setup.
  • The editorLowlight facade correctly guards highlight against unregistered languages and replaces highlightAuto with a plain-text path, preserving the "no auto-detect" product decision.
  • Tests cover the important boundaries: token spans for supported grammars, plain fallback for plaintext/unsupported/invalid languages, language-change updates, and storage integrity.
  • The inline editor CSS is scoped to .emdash-inline-code-block/.emdash-code-block, exposes the documented override variables with system light/dark fallbacks, and uses RTL-safe logical positioning for the language chip.
  • The public page E2E asserts that Code.astro still emits only language-{id} classes and no hljs-* markup.

No remaining blocking or convention issues. LGTM.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 23, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since review/needs-rereview New commits since the last review and removed review/needs-rereview New commits since the last review review/approved Approved; no new commits since labels Aug 23, 2026
@khoinguyenpham04
khoinguyenpham04 force-pushed the codex/issue-2361-code-block-spec branch from e2655b3 to 463b827 Compare August 27, 2026 15:16
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Aug 27, 2026
@khoinguyenpham04
khoinguyenpham04 merged commit 22c4422 into main Aug 27, 2026
47 checks passed
@khoinguyenpham04
khoinguyenpham04 deleted the codex/issue-2361-code-block-spec branch August 27, 2026 20:12
@emdashbot emdashbot Bot mentioned this pull request Aug 27, 2026
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.

Editor code blocks lack syntax highlighting and correct light/dark theme styling

2 participants