Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(settings): Markdown font family and size (#1164)

Paul Robertsond214352c6cd1
diff --git a/CLAUDE.md b/CLAUDE.md
index a757ba1c4..6a793905d 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -2061,6 +2061,14 @@ raw-HTML tokens as escaped TEXT (a program's `<stdin>` is not markup; parsed as
stripped it) and trims capture-pane's trailing padding. The escape is on the `html` token, never a
global pre-escape of `<`, which would double-escape code spans/fences.
+**The rendered-Markdown font is a setting** (`markdownFontFamily` / `markdownFontSize`, Settings →
+Appearance; `@shared/markdown-font`). App.tsx publishes it as `--md-font-family` / `--md-font-size`
+on <html>, plus `--md-code-font-family` = the TERMINAL font family; styles.css keeps the defaults on
+`:root`. Every rule that sizes rendered Markdown reads the tokens — `.term-md__content` (⌘M output
+view, editor preview, the kanban file preview), `.term-chat__msg` and the ⌘M composer input —
+headings are `em`, and code is `0.92em` of the body (relative, so it stays in proportion).
+`styles.markdown-font.test.ts` pins this. Sticky notes keep their own font on purpose.
+
**A link in rendered markdown must never navigate the app window.** DOMPurify keeps an anchor's
href as written, and agents write relative links constantly (`[pty-manager.ts](src/core/pty-manager.ts:4100)`).
A click resolved it against the app document: on the desktop another `file://` path, which the old
diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx
index 7d72ee81e..d2a74ba71 100644
--- a/src/renderer/App.tsx
+++ b/src/renderer/App.tsx
@@ -17,6 +17,11 @@ import { resolveTerminalRenderer } from '../shared/webgl'
import { resolveTerminalTheme } from './terminal/themes'
import { resolveUiScale } from '../shared/ui-scale'
import { resolveTabBarHeight } from '../shared/window-chrome-metrics'
+import {
+ resolveMarkdownCodeFontFamily,
+ resolveMarkdownFontFamily,
+ resolveMarkdownFontSize
+} from '../shared/markdown-font'
import { useAppTheme } from './state/useAppTheme'
import { installWindowActivityOnDocument } from './lib/windowActivity'
import {
@@ -67,6 +72,19 @@ export default function App() {
document.documentElement.style.setProperty('--tabbar-h', `${resolveTabBarHeight(tabBarHeight)}px`)
}, [tabBarHeight])
+ // The rendered-Markdown views' font (Settings → Appearance; @shared/markdown-font). Published as
+ // tokens like `--tabbar-h`: styles.css keeps the defaults on :root, so an un-hydrated store
+ // draws the default font. Code inside Markdown takes the terminal's font family.
+ const markdownFontFamily = useSettings((s) => s.settings.markdownFontFamily)
+ const markdownFontSize = useSettings((s) => s.settings.markdownFontSize)
+ const terminalFontFamily = useSettings((s) => s.settings.fontFamily)
+ useEffect(() => {
+ const style = document.documentElement.style
+ style.setProperty('--md-font-family', resolveMarkdownFontFamily(markdownFontFamily))
+ style.setProperty('--md-font-size', `${resolveMarkdownFontSize(markdownFontSize)}px`)
+ style.setProperty('--md-code-font-family', resolveMarkdownCodeFontFamily(terminalFontFamily))
+ }, [markdownFontFamily, markdownFontSize, terminalFontFamily])
+
// Hold every infinite CSS animation still while nobody is looking at this window (the gate is
// `--nt-anim-state` / `[data-nt-window]` in styles.css, where the measurements live). Installed
// here rather than in Canvas because the surfaces that animate outside the canvas — the
diff --git a/src/renderer/components/settings/FontPicker.test.tsx b/src/renderer/components/settings/FontPicker.test.tsx
new file mode 100644
index 000000000..929fcdb5f
--- /dev/null
+++ b/src/renderer/components/settings/FontPicker.test.tsx
@@ -0,0 +1,58 @@
+// @vitest-environment jsdom
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { createRoot, type Root } from 'react-dom/client'
+import { act } from 'react'
+import { FontPicker } from './FontPicker'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+const SYSTEM = { label: 'System font', stack: '-apple-system, BlinkMacSystemFont, sans-serif' }
+
+let host: HTMLDivElement
+let root: Root
+
+beforeEach(() => {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+ document.body.innerHTML = ''
+})
+
+const select = (label: string) => host.querySelector<HTMLSelectElement>(`select[aria-label="${label}"]`)
+
+describe('FontPicker systemOption', () => {
+ it('shows the system row selected when the value is the default stack, with no "missing" warning', () => {
+ act(() =>
+ root.render(<FontPicker label="Markdown font" value={SYSTEM.stack} onChange={() => {}} systemOption={SYSTEM} />)
+ )
+
+ expect(select('Markdown font family')?.selectedOptions[0]?.textContent).toBe('System font')
+ expect(host.textContent).not.toMatch(/isn’t installed/)
+ })
+
+ it('stores the default stack when the system row is picked', () => {
+ const onChange = vi.fn()
+ act(() =>
+ root.render(<FontPicker label="Markdown font" value='"Georgia", serif' onChange={onChange} systemOption={SYSTEM} />)
+ )
+ const el = select('Markdown font family')!
+
+ act(() => {
+ el.value = '__system__'
+ el.dispatchEvent(new Event('change', { bubbles: true }))
+ })
+
+ expect(onChange).toHaveBeenCalledWith(SYSTEM.stack)
+ })
+
+ it('has no system row without the prop (the terminal picker is unchanged)', () => {
+ act(() => root.render(<FontPicker value="Menlo, monospace" onChange={() => {}} />))
+
+ expect(host.textContent).not.toMatch(/System font/)
+ expect(select('Font family')).not.toBeNull()
+ })
+})
diff --git a/src/renderer/components/settings/FontPicker.tsx b/src/renderer/components/settings/FontPicker.tsx
index 67d177258..79c000d66 100644
--- a/src/renderer/components/settings/FontPicker.tsx
+++ b/src/renderer/components/settings/FontPicker.tsx
@@ -13,6 +13,8 @@ import {
/** Marks the free-text row in the dropdown — anything not in the detected list. */
const CUSTOM = '__custom__'
+/** Marks the `systemOption` row: the setting's own default stack. */
+const SYSTEM = '__system__'
/**
* Whether this browser exposes the Local Font Access API. Chromium-only, and in the Server
@@ -40,10 +42,24 @@ async function queryAllFamilies(): Promise<string[]> {
*/
export function FontPicker({
value,
- onChange
+ onChange,
+ catalog = MONO_FONT_CATALOG,
+ buildStack = buildFontStack,
+ systemOption,
+ label = 'Font'
}: {
value: string
onChange: (stack: string) => void
+ /** Families offered in the list (filtered by what is installed). Default: coding fonts. */
+ catalog?: readonly string[]
+ /** Turns a picked family into the stored stack (keeps fallbacks). Default: monospace ones. */
+ buildStack?: (family: string) => string
+ /** An extra first row meaning "this setting's default stack" — for a default that is not one
+ * installed family (the system font stack starts with `-apple-system`, which no list holds and
+ * which a font probe on another OS would report as missing). */
+ systemOption?: { label: string; stack: string }
+ /** Prefixes the two controls' accessible names ("Font family", "Font stack"). */
+ label?: string
}): React.JSX.Element {
// One measurer for the lifetime of the picker: it holds a single reused canvas, and building one
// per probe is what turns a 31-font scan into a visible hitch.
@@ -65,19 +81,21 @@ export function FontPicker({
const installed = useMemo(() => {
if (!measure) return []
- const all = [...new Set([...MONO_FONT_CATALOG, ...extraFamilies])].sort((a, b) =>
+ const all = [...new Set([...catalog, ...extraFamilies])].sort((a, b) =>
a.localeCompare(b)
)
return detectInstalled(all, measure)
// fontsReady is a re-scan trigger, not a value.
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [measure, extraFamilies, fontsReady])
+ }, [measure, catalog, extraFamilies, fontsReady])
const primary = primaryFamily(value)
+ const isSystem = systemOption !== undefined && value.trim() === systemOption.stack
// `measure` being null (no canvas) means we cannot tell — and "unknown" must not render as a
- // warning that the user's font is missing.
- const missing = !!measure && !!primary && !isFontAvailable(primary, measure)
- const selectValue = installed.includes(primary) ? primary : CUSTOM
+ // warning that the user's font is missing. The system stack is never "missing": its first name
+ // is a platform alias with fallbacks behind it.
+ const missing = !isSystem && !!measure && !!primary && !isFontAvailable(primary, measure)
+ const selectValue = isSystem ? SYSTEM : installed.includes(primary) ? primary : CUSTOM
async function browseAll(): Promise<void> {
setBrowseError(null)
@@ -95,11 +113,14 @@ export function FontPicker({
<Select
className="w-64"
value={selectValue}
- aria-label="Font family"
+ aria-label={`${label} family`}
onChange={(e) => {
- if (e.target.value !== CUSTOM) onChange(buildFontStack(e.target.value))
+ const picked = e.target.value
+ if (picked === SYSTEM && systemOption !== undefined) onChange(systemOption.stack)
+ else if (picked !== CUSTOM) onChange(buildStack(picked))
}}
>
+ {systemOption !== undefined && <option value={SYSTEM}>{systemOption.label}</option>}
{installed.length > 0 && (
<optgroup label="Installed">
{installed.map((f) => (
@@ -116,7 +137,7 @@ export function FontPicker({
<Input
className="w-64"
value={value}
- aria-label="Font stack"
+ aria-label={`${label} stack`}
onChange={(e) => onChange(e.target.value)}
/>
{missing ? (
diff --git a/src/renderer/components/settings/sections/AppearanceSection.tsx b/src/renderer/components/settings/sections/AppearanceSection.tsx
index fb070e49d..2d59e72e0 100644
--- a/src/renderer/components/settings/sections/AppearanceSection.tsx
+++ b/src/renderer/components/settings/sections/AppearanceSection.tsx
@@ -44,6 +44,16 @@ import {
resolveTabBarHeight
} from '@shared/window-chrome-metrics'
import { NumberField } from '@renderer/ui/NumberField'
+import { FontPicker } from '../FontPicker'
+import { PROSE_FONT_CATALOG, buildProseFontStack } from '@renderer/lib/fontDetect'
+import {
+ DEFAULT_MARKDOWN_FONT_FAMILY,
+ DEFAULT_MARKDOWN_FONT_SIZE,
+ MARKDOWN_FONT_SIZE_MAX,
+ MARKDOWN_FONT_SIZE_MIN,
+ resolveMarkdownFontFamily,
+ resolveMarkdownFontSize
+} from '@shared/markdown-font'
import { SectionReset } from '../SectionReset'
import { APPEARANCE_RESET_KEYS } from '@renderer/lib/settingsReset'
@@ -60,6 +70,14 @@ const ROWS = {
title: 'Tab bar height',
keywords: ['tab', 'bar', 'height', 'strip', 'top', 'title bar', 'thickness', 'compact', 'dense']
},
+ markdownFont: {
+ title: 'Markdown font',
+ keywords: ['markdown', 'font', 'family', 'typeface', 'chat', 'preview', 'reading', 'output', 'text', 'serif', 'sans']
+ },
+ markdownFontSize: {
+ title: 'Markdown font size',
+ keywords: ['markdown', 'font', 'size', 'text', 'bigger', 'larger', 'smaller', 'chat', 'preview', 'reading', 'readability']
+ },
accent: { title: 'Accent', keywords: ['accent', 'color', 'theme', 'appearance'] },
wallpaper: {
title: 'Desktop wallpaper',
@@ -231,6 +249,51 @@ function TabBarHeightRow(): React.JSX.Element {
)
}
+/** Applies to the ⌘M output and chat views and the editor's Markdown preview (@shared/markdown-font). */
+function MarkdownFontRows(): React.JSX.Element {
+ const family = useSettings((s) => s.settings.markdownFontFamily)
+ const size = useSettings((s) => s.settings.markdownFontSize)
+ const update = useSettings((s) => s.update)
+ return (
+ <>
+ <SearchableRow {...ROWS.markdownFont}>
+ <FieldRow
+ label="Markdown font"
+ description="Used by the ⌘M output and chat views and the editor's Markdown preview. Code inside them uses your terminal font."
+ control={
+ <FontPicker
+ label="Markdown font"
+ value={resolveMarkdownFontFamily(family)}
+ onChange={(stack) => update({ markdownFontFamily: stack })}
+ catalog={PROSE_FONT_CATALOG}
+ buildStack={buildProseFontStack}
+ systemOption={{ label: 'System font', stack: DEFAULT_MARKDOWN_FONT_FAMILY }}
+ />
+ }
+ />
+ </SearchableRow>
+ <SearchableRow {...ROWS.markdownFontSize}>
+ <FieldRow
+ label="Markdown font size"
+ description={`Body text size in the same views, in pixels (${MARKDOWN_FONT_SIZE_MIN}–${MARKDOWN_FONT_SIZE_MAX}; default ${DEFAULT_MARKDOWN_FONT_SIZE}). Headings and code scale with it.`}
+ control={
+ <div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
+ <NumberField
+ value={resolveMarkdownFontSize(size)}
+ min={MARKDOWN_FONT_SIZE_MIN}
+ max={MARKDOWN_FONT_SIZE_MAX}
+ ariaLabel="Markdown font size"
+ onChange={(v) => update({ markdownFontSize: resolveMarkdownFontSize(v) })}
+ />
+ <span style={{ opacity: 0.6 }}>px</span>
+ </div>
+ }
+ />
+ </SearchableRow>
+ </>
+ )
+}
+
/** One picker tile. The selected tile gets the text-coloured ring, like the accent swatches. */
function WallpaperTile({
label,
@@ -475,6 +538,7 @@ export function AppearanceSection({ isActive }: { isActive: boolean }): React.JS
<SearchableRow {...ROWS.tabBarHeight}>
<TabBarHeightRow />
</SearchableRow>
+ <MarkdownFontRows />
<SearchableRow {...ROWS.accent}>
<div className="flex items-center justify-between gap-4 py-2.5">
<span className="text-[13px] text-text">Accent</span>
diff --git a/src/renderer/lib/fontDetect.test.ts b/src/renderer/lib/fontDetect.test.ts
index 31d3298a0..292a39976 100644
--- a/src/renderer/lib/fontDetect.test.ts
+++ b/src/renderer/lib/fontDetect.test.ts
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest'
import {
MONO_FONT_CATALOG,
buildFontStack,
+ buildProseFontStack,
detectInstalled,
isFontAvailable,
isGenericFamily,
@@ -139,3 +140,17 @@ describe('MONO_FONT_CATALOG', () => {
expect([...MONO_FONT_CATALOG]).toEqual([...MONO_FONT_CATALOG].sort())
})
})
+
+describe('buildProseFontStack', () => {
+ it('keeps proportional fallbacks ending in sans-serif', () => {
+ expect(buildProseFontStack('Iowan Old Style')).toBe('"Iowan Old Style", -apple-system, BlinkMacSystemFont, sans-serif')
+ })
+
+ it('keeps a generic family as a complete stack', () => {
+ expect(buildProseFontStack('serif')).toBe('serif')
+ })
+
+ it('answers sans-serif for nothing', () => {
+ expect(buildProseFontStack(' ')).toBe('sans-serif')
+ })
+})
diff --git a/src/renderer/lib/fontDetect.ts b/src/renderer/lib/fontDetect.ts
index acfb99ebf..656e1f1cd 100644
--- a/src/renderer/lib/fontDetect.ts
+++ b/src/renderer/lib/fontDetect.ts
@@ -88,6 +88,17 @@ export function buildFontStack(family: string): string {
return `${quoteFamily(trimmed)}, Menlo, Monaco, "Courier New", monospace`
}
+/**
+ * `buildFontStack` for reading text (the Markdown font): proportional fallbacks, ending in
+ * `sans-serif`. A generic family (`serif`, `system-ui`) is a complete stack on its own.
+ */
+export function buildProseFontStack(family: string): string {
+ const trimmed = family.trim()
+ if (!trimmed) return 'sans-serif'
+ if (isGenericFamily(trimmed)) return trimmed
+ return `${quoteFamily(trimmed)}, -apple-system, BlinkMacSystemFont, sans-serif`
+}
+
/**
* Whether `family` resolves to a real installed font.
*
@@ -155,6 +166,44 @@ export const MONO_FONT_CATALOG: readonly string[] = [
'Victor Mono'
]
+/**
+ * Well-known reading fonts (sans and serif, across macOS, Windows and Linux) for the Markdown font
+ * picker. A catalogue like `MONO_FONT_CATALOG`: filtered by what is installed, never a whitelist.
+ */
+export const PROSE_FONT_CATALOG: readonly string[] = [
+ 'Arial',
+ 'Atkinson Hyperlegible',
+ 'Avenir Next',
+ 'Baskerville',
+ 'Cantarell',
+ 'Charter',
+ 'DejaVu Sans',
+ 'DejaVu Serif',
+ 'Georgia',
+ 'Gill Sans',
+ 'Helvetica Neue',
+ 'IBM Plex Sans',
+ 'IBM Plex Serif',
+ 'Inter',
+ 'Iowan Old Style',
+ 'Lato',
+ 'Liberation Sans',
+ 'Liberation Serif',
+ 'New York',
+ 'Noto Sans',
+ 'Noto Serif',
+ 'Open Sans',
+ 'Optima',
+ 'Palatino',
+ 'Roboto',
+ 'Segoe UI',
+ 'Source Sans 3',
+ 'Source Serif 4',
+ 'Times New Roman',
+ 'Ubuntu',
+ 'Verdana'
+]
+
/**
* A canvas-backed measurer, or null where there is no 2D context to measure with.
*
diff --git a/src/renderer/lib/settingsReset.ts b/src/renderer/lib/settingsReset.ts
index 1c0f4a384..3edbae6e3 100644
--- a/src/renderer/lib/settingsReset.ts
+++ b/src/renderer/lib/settingsReset.ts
@@ -37,6 +37,8 @@ export const APPEARANCE_RESET_KEYS = [
'appTheme',
'uiScale',
'tabBarHeight',
+ 'markdownFontFamily',
+ 'markdownFontSize',
'accent',
'desktopWallpaper',
'hiddenNodeMenuItems',
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index d356011ab..1f4b64957 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -162,6 +162,11 @@
--radius: 8px;
--radius-sm: 6px;
--radius-lg: 12px;
+ /* The rendered-Markdown views' font (Settings → Appearance). App.tsx overrides these on <html>
+ from settings; these are the defaults (@shared/markdown-font) for an un-hydrated store. */
+ --md-font-family: -apple-system, BlinkMacSystemFont, sans-serif;
+ --md-font-size: 13px;
+ --md-code-font-family: Menlo, Monaco, "Courier New", monospace;
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', 'Helvetica Neue',
sans-serif;
font-size: 13px;
@@ -3150,8 +3155,8 @@ body,
min-height: 0;
overflow: auto;
padding: 12px 16px;
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- font-size: 13px;
+ font-family: var(--md-font-family);
+ font-size: var(--md-font-size);
line-height: 1.6;
color: var(--text);
/* Allow text selection / copy (React Flow nodes are non-selectable by default). */
@@ -3167,14 +3172,16 @@ body,
line-height: 1.3;
}
+/* Heading sizes are proportions of the body size (20 / 17 / 15 px at the default 13), so they
+ follow the Markdown font size setting. */
.term-md__content h1 {
- font-size: 20px;
+ font-size: 1.54em;
}
.term-md__content h2 {
- font-size: 17px;
+ font-size: 1.31em;
}
.term-md__content h3 {
- font-size: 15px;
+ font-size: 1.15em;
}
.term-md__content p,
@@ -3188,8 +3195,9 @@ body,
}
.term-md__content code {
- font-family: Menlo, Monaco, monospace;
- font-size: 12px;
+ /* The terminal's font, at 0.92 of the Markdown size (12px at the default 13). */
+ font-family: var(--md-code-font-family);
+ font-size: 0.92em;
background: rgba(var(--tint-rgb), 0.08);
padding: 1px 5px;
border-radius: 5px;
@@ -3326,7 +3334,8 @@ body,
ASSISTANT's is plain full-width text on the panel with no bubble, roomy line height and paragraph
spacing, and a quiet action row under each turn (ChatTurnActions). */
.term-chat__msg {
- font-size: 13px;
+ font-family: var(--md-font-family);
+ font-size: var(--md-font-size);
line-height: 1.5;
word-break: break-word;
min-width: 0;
@@ -3421,6 +3430,10 @@ body,
.term-chat__text > :last-child {
margin-bottom: 0;
}
+.term-chat__text code {
+ font-family: var(--md-code-font-family);
+ font-size: 0.92em;
+}
.term-chat__text pre {
background: rgba(0, 0, 0, 0.35);
padding: 8px;
@@ -3832,8 +3845,8 @@ body,
width: 100%;
resize: none;
padding: 4px 6px;
- font-family: inherit;
- font-size: 13px;
+ font-family: var(--md-font-family);
+ font-size: var(--md-font-size);
color: var(--text-strong);
background: transparent;
border: none;
diff --git a/src/renderer/styles.markdown-font.test.ts b/src/renderer/styles.markdown-font.test.ts
new file mode 100644
index 000000000..366546aa1
--- /dev/null
+++ b/src/renderer/styles.markdown-font.test.ts
@@ -0,0 +1,82 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import {
+ DEFAULT_CODE_FONT_FAMILY,
+ DEFAULT_MARKDOWN_FONT_FAMILY,
+ DEFAULT_MARKDOWN_FONT_SIZE
+} from '@shared/markdown-font'
+
+/**
+ * The Markdown font setting (Settings → Appearance) reaches the views as three tokens App.tsx sets
+ * on <html>. Every rule that sizes or picks the font of rendered Markdown must read the tokens, or
+ * the setting silently stops applying to that view. The :root defaults are what an un-hydrated
+ * store draws, so they must equal the setting's defaults.
+ */
+const CSS = readFileSync(join(__dirname, 'styles.css'), 'utf8').replace(/\r\n/g, '\n')
+
+function token(name: string): string {
+ const root = CSS.slice(CSS.indexOf(':root {'), CSS.search(/^:root\[data-theme='light'\]\s*\{/m))
+ const m = new RegExp(`^\\s*${name}:\\s*([^;]+);`, 'm').exec(root)
+ if (!m) throw new Error(`${name} is not declared in :root`)
+ return m[1].trim()
+}
+
+/** The body of the rule whose selector is exactly `selector` (not part of a selector group). */
+function rule(selector: string): string {
+ const re = new RegExp(`^${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\{`, 'gm')
+ for (const m of CSS.matchAll(re)) {
+ const prev = CSS.lastIndexOf('\n', m.index - 1)
+ const prevLine = CSS.slice(CSS.lastIndexOf('\n', prev - 1) + 1, prev).trim()
+ if (prevLine.endsWith(',')) continue
+ return CSS.slice(m.index, CSS.indexOf('}', m.index))
+ }
+ throw new Error(`no rule for ${selector}`)
+}
+
+describe('Markdown font tokens', () => {
+ it(':root defaults equal the setting defaults', () => {
+ expect(token('--md-font-family')).toBe(DEFAULT_MARKDOWN_FONT_FAMILY)
+ expect(token('--md-font-size')).toBe(`${DEFAULT_MARKDOWN_FONT_SIZE}px`)
+ expect(token('--md-code-font-family')).toBe(DEFAULT_CODE_FONT_FAMILY)
+ })
+
+ it('the output view and editor preview read them', () => {
+ const body = rule('.term-md__content')
+
+ expect(body).toMatch(/font-family:\s*var\(--md-font-family\)/)
+ expect(body).toMatch(/font-size:\s*var\(--md-font-size\)/)
+ })
+
+ it('headings scale with the body size instead of fixed pixels', () => {
+ for (const h of ['h1', 'h2', 'h3']) {
+ expect(rule(`.term-md__content ${h}`)).toMatch(/font-size:\s*[\d.]+em/)
+ }
+ })
+
+ it('the chat thread and its composer read them', () => {
+ for (const sel of ['.term-chat__msg', '.term-chat__composer-input']) {
+ const body = rule(sel)
+
+ expect(body, sel).toMatch(/font-family:\s*var\(--md-font-family\)/)
+ expect(body, sel).toMatch(/font-size:\s*var\(--md-font-size\)/)
+ }
+ })
+
+ it('code uses the terminal font at 0.92 of the Markdown size, in both views', () => {
+ for (const sel of ['.term-md__content code', '.term-chat__text code']) {
+ const body = rule(sel)
+
+ expect(body, sel).toMatch(/font-family:\s*var\(--md-code-font-family\)/)
+ expect(body, sel).toMatch(/font-size:\s*0\.92em/)
+ }
+ })
+
+ it('App.tsx publishes all three tokens from the resolvers', () => {
+ const app = readFileSync(join(__dirname, 'App.tsx'), 'utf8')
+
+ expect(app).toMatch(/setProperty\('--md-font-family', resolveMarkdownFontFamily\(/)
+ expect(app).toMatch(/setProperty\('--md-font-size', `\$\{resolveMarkdownFontSize\(/)
+ expect(app).toMatch(/setProperty\('--md-code-font-family', resolveMarkdownCodeFontFamily\(/)
+ })
+})
diff --git a/src/shared/markdown-font.test.ts b/src/shared/markdown-font.test.ts
new file mode 100644
index 000000000..6366b969b
--- /dev/null
+++ b/src/shared/markdown-font.test.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from 'vitest'
+import {
+ DEFAULT_CODE_FONT_FAMILY,
+ DEFAULT_MARKDOWN_FONT_FAMILY,
+ DEFAULT_MARKDOWN_FONT_SIZE,
+ MARKDOWN_FONT_SIZE_MAX,
+ MARKDOWN_FONT_SIZE_MIN,
+ resolveMarkdownCodeFontFamily,
+ resolveMarkdownFontFamily,
+ resolveMarkdownFontSize
+} from './markdown-font'
+import { DEFAULT_SETTINGS } from './types'
+
+describe('resolveMarkdownFontSize', () => {
+ it('keeps a size inside the range, rounded', () => {
+ expect(resolveMarkdownFontSize(16)).toBe(16)
+ expect(resolveMarkdownFontSize(15.6)).toBe(16)
+ })
+
+ it('clamps to the terminal font range', () => {
+ expect(resolveMarkdownFontSize(2)).toBe(MARKDOWN_FONT_SIZE_MIN)
+ expect(resolveMarkdownFontSize(400)).toBe(MARKDOWN_FONT_SIZE_MAX)
+ })
+
+ it('answers the default for anything that is not a finite number (settings.json is hand-editable)', () => {
+ for (const bad of [undefined, null, '16', Number.NaN, Number.POSITIVE_INFINITY, {}]) {
+ expect(resolveMarkdownFontSize(bad)).toBe(DEFAULT_MARKDOWN_FONT_SIZE)
+ }
+ })
+})
+
+describe('resolveMarkdownFontFamily', () => {
+ it('keeps a font stack, trimmed', () => {
+ expect(resolveMarkdownFontFamily(' "Iowan Old Style", Georgia, serif ')).toBe('"Iowan Old Style", Georgia, serif')
+ })
+
+ it('answers the default for an empty or non-string value', () => {
+ for (const bad of [undefined, null, 12, '', ' ']) {
+ expect(resolveMarkdownFontFamily(bad)).toBe(DEFAULT_MARKDOWN_FONT_FAMILY)
+ }
+ })
+
+ it('refuses a value that could end the CSS declaration it is set into', () => {
+ for (const bad of ['Georgia; color: red', 'Georgia} body {', 'a<b', 'a\\62', 'Geor\ngia', 'x'.repeat(301)]) {
+ expect(resolveMarkdownFontFamily(bad)).toBe(DEFAULT_MARKDOWN_FONT_FAMILY)
+ }
+ })
+})
+
+describe('resolveMarkdownCodeFontFamily', () => {
+ it('follows the terminal font family', () => {
+ expect(resolveMarkdownCodeFontFamily('"JetBrains Mono", monospace')).toBe('"JetBrains Mono", monospace')
+ })
+
+ it('falls back to the terminal default for an unusable value', () => {
+ expect(resolveMarkdownCodeFontFamily('')).toBe(DEFAULT_CODE_FONT_FAMILY)
+ })
+})
+
+describe('defaults', () => {
+ it('ship in DEFAULT_SETTINGS', () => {
+ expect(DEFAULT_SETTINGS.markdownFontFamily).toBe(DEFAULT_MARKDOWN_FONT_FAMILY)
+ expect(DEFAULT_SETTINGS.markdownFontSize).toBe(DEFAULT_MARKDOWN_FONT_SIZE)
+ })
+
+ it('the code fallback is the terminal font default', () => {
+ expect(DEFAULT_CODE_FONT_FAMILY).toBe(DEFAULT_SETTINGS.fontFamily)
+ })
+})
diff --git a/src/shared/markdown-font.ts b/src/shared/markdown-font.ts
new file mode 100644
index 000000000..bda4d0a1a
--- /dev/null
+++ b/src/shared/markdown-font.ts
@@ -0,0 +1,57 @@
+/**
+ * The font of the rendered-Markdown reading views: the ⌘M output view, the ⌘M chat view (thread
+ * and composer) and the editor's Markdown preview (Settings → Appearance).
+ *
+ * Applied as CSS custom properties on <html> (`--md-font-family`, `--md-font-size`,
+ * `--md-code-font-family`, set by App.tsx); styles.css reads them. Code inside Markdown follows
+ * the TERMINAL font family (one setting fewer, and code looks like the terminal it came from) at
+ * 0.92 of the Markdown size — a relative size, so code stays in proportion when the Markdown size
+ * changes (a terminal-size-based code font would sit far below a 16px body).
+ *
+ * settings.json is hand-editable, so every reader goes through the resolvers below: a size that is
+ * not a finite number answers the default and is clamped to the terminal font's range; a family
+ * that is not a usable string answers its default.
+ */
+
+/** What the Markdown views used before the setting existed — the default keeps the same look. */
+export const DEFAULT_MARKDOWN_FONT_FAMILY = '-apple-system, BlinkMacSystemFont, sans-serif'
+export const DEFAULT_MARKDOWN_FONT_SIZE = 13
+export const MARKDOWN_FONT_SIZE_MIN = 8
+export const MARKDOWN_FONT_SIZE_MAX = 28
+
+/** The code family when the terminal's own `fontFamily` is unusable (the terminal's default). */
+export const DEFAULT_CODE_FONT_FAMILY = 'Menlo, Monaco, "Courier New", monospace'
+
+/** Longest font stack accepted; a longer value is not a font list anyone typed. */
+const FONT_STACK_MAX = 300
+
+/**
+ * A font stack from settings, or `fallback`. Refuses characters that cannot appear in a
+ * `font-family` value but could end the declaration it is set into (`;`, braces, angle brackets,
+ * a backslash, control characters).
+ */
+export function resolveFontStack(value: unknown, fallback: string): string {
+ if (typeof value !== 'string') return fallback
+ const trimmed = value.trim()
+ if (trimmed === '' || trimmed.length > FONT_STACK_MAX) return fallback
+ if (/[;{}<>\\]/.test(trimmed)) return fallback
+ for (const ch of trimmed) {
+ const code = ch.charCodeAt(0)
+ if (code < 0x20 || code === 0x7f) return fallback
+ }
+ return trimmed
+}
+
+export function resolveMarkdownFontFamily(value: unknown): string {
+ return resolveFontStack(value, DEFAULT_MARKDOWN_FONT_FAMILY)
+}
+
+export function resolveMarkdownFontSize(value: unknown): number {
+ if (typeof value !== 'number' || !Number.isFinite(value)) return DEFAULT_MARKDOWN_FONT_SIZE
+ return Math.min(MARKDOWN_FONT_SIZE_MAX, Math.max(MARKDOWN_FONT_SIZE_MIN, Math.round(value)))
+}
+
+/** The family code inside Markdown uses: the terminal's font. */
+export function resolveMarkdownCodeFontFamily(terminalFontFamily: unknown): string {
+ return resolveFontStack(terminalFontFamily, DEFAULT_CODE_FONT_FAMILY)
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 747868bed..3a9e74018 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -7,6 +7,7 @@ import type { AgentIntegrationsSettings } from './agent-integrations'
// Types shared across the main, preload, and renderer processes.
import { TABBAR_HEIGHT_PX } from './window-chrome-metrics'
+import { DEFAULT_MARKDOWN_FONT_FAMILY, DEFAULT_MARKDOWN_FONT_SIZE } from './markdown-font'
import { DEFAULT_WORKTREE_PATH_TEMPLATE } from './worktree'
import type { CloneProgress } from './clone-url'
import type { KeybindingOverrides, TerminalShortcutPolicy } from './keybindings'
@@ -1882,6 +1883,14 @@ export interface Settings {
* the default for anything that is not a finite number. Machine-local: it is one person's
* chrome, not a canvas fact. */
tabBarHeight: number
+ /** Font of the rendered-Markdown reading views — the ⌘M output and chat views and the editor's
+ * Markdown preview (Settings → Appearance). A CSS font stack. Hand-editable; read through
+ * `resolveMarkdownFontFamily` (@shared/markdown-font). Code inside Markdown follows the
+ * terminal `fontFamily` instead. Machine-local, like the terminal font. */
+ markdownFontFamily: string
+ /** Body size (CSS px) of the same views; headings scale from it, code is 0.92 of it. Read
+ * through `resolveMarkdownFontSize`, which clamps to 8–28 and answers 13 for garbage. */
+ markdownFontSize: number
/** Default size (px) for NEW terminal/agent nodes on the canvas. Existing nodes keep
* whatever size they were saved with; other node kinds keep their own defaults. */
defaultNodeWidth: number
@@ -2382,6 +2391,8 @@ export const DEFAULT_SETTINGS: Settings = {
snapToGrid: false,
autoAlignGrid: false,
tabBarHeight: TABBAR_HEIGHT_PX,
+ markdownFontFamily: DEFAULT_MARKDOWN_FONT_FAMILY,
+ markdownFontSize: DEFAULT_MARKDOWN_FONT_SIZE,
defaultNodeWidth: 640,
defaultNodeHeight: 440,
sidebarAutoCollapse: true,