Skip to content

feat(CodeBlock): support styled tokenizer tokens - #6670

Closed
ernestt wants to merge 1 commit into
markdown-upgrade/14-mermaidfrom
markdown-upgrade/15-styled-tokens
Closed

ernestt wants to merge 1 commit into
markdown-upgrade/14-mermaidfrom
markdown-upgrade/15-styled-tokens

Conversation

@ernestt

@ernestt ernestt commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

User need

Trusted CodeBlock tokenizers can attach bounded literal styles while exact source text remains the DOM and clipboard value.

Problem and solution fit

Class-only token styling cannot represent engines that return per-token colors without either global CSS generation or source-replacing markup. A narrow style field keeps presentation metadata separate from source fidelity.

Current specification

CodeBlock's trusted-tokenizer and source-fidelity contracts, supporting AST-039 renderers. Pinned source.

Public delta and caller burden

Add validated SyntaxToken.style support for bounded color/font-style/font-weight/text-decoration values; invalid styles fail closed and token offsets must remain safe and non-overlapping.

Design and alternatives

The capability is explicit and opt-in where it changes syntax, rendering, or package weight. Existing defaults and replacement seams remain compatible; broader alternatives stay outside this PR.

Evidence

Functional evidence

This change is intentionally nonvisual; a pixel comparison would be misleading.

  • Tests reconstruct the exact source from safe non-overlapping offsets and assert identical DOM/clipboard text while validating the bounded style surface.

Focused behavior and compatibility coverage ships with the implementation.

Scope

  • One capability is added.
  • Unrelated fixes and policy changes were split into adjacent stack entries.
  • Consumer docs and focused tests ship with the feature.
  • Public text and artifacts contain no internal context.

Testing

  • Focused: Tokenizer validation, source reconstruction, overlapping/invalid range rejection, rendered DOM text, and clipboard tests.
  • Stack head: pnpm exec vitest run packages/core/src/Markdown packages/core/src/CodeBlock — 37 files, 760 tests.
  • Stack head: pnpm --filter @astryxdesign/core typecheck.
  • Repository checks: pnpm check:repo.

Stack

Previous: #6669 · Next: #6671 · Each PR is intentionally one commit and one primary intent.

@vercel

vercel Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Error Error Sep 26, 2026 4:11pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 26, 2026
@astracat-bot

astracat-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
📝 Draft — not reviewed automatically (for maintainers only) Sep 28, 2026, 6:55 PM UTC

Summary:
Let trusted custom tokenizers attach a narrow inline presentation to syntax tokens. Styled tokens automatically use the span renderer while CodeBlock keeps its source-faithful DOM and clipboard value.

Test Plan:
- pnpm exec vitest run packages/core/src/CodeBlock/CodeBlock.test.tsx packages/core/src/CodeBlock/tokenizer.test.ts --root .
- pnpm --filter @astryxdesign/core typecheck
- pnpm --filter @astryxdesign/core typecheck:docs
- pnpm --filter @astryxdesign/core build
- pnpm check:repo
- pnpm visual:probe-theme:check
@ernestt

ernestt commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@cixzhang — I’d appreciate your feedback on this draft.

Focus: Trusted CodeBlock tokenizers can attach bounded literal styles while exact source text remains the DOM and clipboard value.

This is PR 15/20 in the linked Markdown stack. It is intentionally one commit and one primary intent; the description includes focused functional evidence and previous/next links, so you can review just this PR’s delta.

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

The implementation is small and preserves source text correctly, but it expands the stable tokenizer API with an exported style type and new rendering precedence without current CodeBlock authority. Please land a design-only contract covering why per-token styling is public, the allowed property set, when styles force span rendering, and the theming and accessibility guarantees. Then rebase this change and add a package-level public type and import test.

@ernestt
ernestt added this pull request to stack #6700 September 28, 2026 18:03
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook and Sandbox are not both ready on the exact-head Vercel preview. CI concluded failure.

Modified Components

Outline (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 719 -
Complexity N/A High (28) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

4 of 422 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Markdown Default probe dark 29,661
Markdown Default probe light 29,652
SideNav Resizable in AppShell probe dark 3,208

Generated by PR Enrichment workflow | View full report

@ernestt ernestt closed this Oct 9, 2026
@github-actions
github-actions Bot deleted the markdown-upgrade/15-styled-tokens branch October 10, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — cfe17474 Deployed Sep 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants