Skip to content

Code-block card and inline-code chip rendering (opt-in) - #132

Draft
dylandeheer wants to merge 3 commits into
nodes-app:mainfrom
GetWeeve:feature/code-block-card
Draft

Code-block card and inline-code chip rendering (opt-in)#132
dylandeheer wants to merge 3 commits into
nodes-app:mainfrom
GetWeeve:feature/code-block-card

Conversation

@dylandeheer

Copy link
Copy Markdown

What

Two opt-in rendering upgrades in the TextKit 2 layer, both defaulting to the historical .backgroundColor glyph-run fills exactly:

Code-block cardCodeBlockStyle.cornerRadius renders a fenced block as ONE continuous rounded card spanning the whole block, wrapped lines included. Each fragment paints its slice full-width and rounds corners only on the fragments holding the block's first and last characters (extend-and-clip, so every fragment still draws strictly inside its own strip — invalidation and scrolling stay per-fragment). The styler tags the block with a .codeBlockCard attribute carrying the block range instead of a .backgroundColor, so no square fills fight the card. CodeBlockStyle.cardVerticalPadding pins the hidden fence lines' height so they read as the card's interior padding; fences revert to their natural code line height while the caret reveals them.

Inline-code chipsInlineCodeStyle.chipCornerRadius draws a small rounded background hugging each inline code span (per wrapped line, at the code font's own height rather than the whole line box) with chipHorizontalPadding of breathing room. MarkdownEditorTheme.inlineCodeBackground colors the chip (nil → codeBackground → the syntax-highlighter background).

Selection stays visible above both card and chips via the same even-odd cut-out the legacy code-block fill uses.

Why

Per-paragraph square fills read as disjoint highlight bands, not as a code block; designs that specify a rounded card with interior padding and chip-style inline code had no seam to express it.

Tests

CodeBlockCardTests — defaults preserved (both features), card tagging + background suppression, fence padding pin + caret reveal, chip tagging, theme slot. Full suite green.

Stacks on the code typography knobs (#128); the last commit is this feature.

Made with Cursor

dylandeheer and others added 3 commits August 3, 2026 22:59
The theme can recolor every element except heading text (it inherits
bodyText), and the heading config covers every metric except the face —
so an embedder that wants serif display headings over a sans body has
to fork. HeadingStyle.fontName picks a PostScript face for headings,
honored exactly so the chosen weight survives; an unresolvable name
falls back to the stock bold base font, like TaskCheckboxStyle's symbol
fallback. MarkdownEditorTheme.headingText colors heading text while the
`#` glyphs stay on headingMarker and inline constructs inside a heading
keep their own ink. Emphasis inside a heading still composes on top of
the configured face (traits added, family and per-level size kept).
Both knobs default to nil, which keeps styling identical to before.

Co-authored-by: Cursor <cursoragent@cursor.com>
Adds additive code typography and theming knobs:

- CodeBlockStyle.fontName swaps the fenced-block face; nil (the
  default) keeps the syntax-highlighter service's font, and an
  unresolvable name degrades to it (mirrors HeadingStyle.fontName).
- InlineCodeStyle.fontName overrides inline `code` spans
  independently; nil follows the block face, exactly as today.
- MarkdownEditorTheme.codeBackground replaces the background behind
  fenced blocks and inline spans; nil keeps the service background.

Code-block card chrome (corner radius, padding) is intentionally NOT
included: the background today is a plain text attribute, and a card
would need fragment-level drawing. Deferred.

Co-authored-by: Cursor <cursoragent@cursor.com>
CodeBlockStyle.cornerRadius renders a fenced block as ONE continuous
rounded card: each fragment paints its slice full-width, rounding
corners only on the fragments holding the block's first and last
characters (extend-and-clip keeps every fragment drawing strictly
inside its own strip, so invalidation and scrolling stay per-fragment).
CodeBlockStyle.cardVerticalPadding pins the hidden fence lines' height
as the card's interior padding; fences revert to natural height while
the caret reveals them. InlineCodeStyle.chipCornerRadius draws a small
rounded chip hugging each inline code span with chipHorizontalPadding
of breathing room, colored by theme.inlineCodeBackground (fallback
codeBackground, then the highlighter background). Selection cuts out
even-odd above both card and chips. All defaults preserve the
historical .backgroundColor glyph-run fills exactly.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant