Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9247461
feat(mobile): refine Markdown blocks and Mermaid diagrams
niconicohu Oct 16, 2026
7a620d6
fix(mobile): leave inline code readable when Android rejects a theme …
niconicohu Oct 16, 2026
5c1ac13
fix(mobile): reduce inline code measurement allocations
niconicohu Oct 16, 2026
a42e3dc
fix(mobile): retain markdown fallbacks across layout changes
niconicohu Oct 16, 2026
412efef
Merge main and keep Markdown tables readable and diagrams legible
niconicohu Oct 17, 2026
688b8ee
Keep custom Mermaid node labels readable across light and dark surfaces
niconicohu Oct 17, 2026
ba52b5b
Keep mobile ER rows and Gantt labels readable in both themes
niconicohu Oct 17, 2026
ba6e62f
Serialize page Mermaid renders across diagrams and theme changes
niconicohu Oct 17, 2026
4df7520
chore: remove unrelated formatting from markdown changes
niconicohu Oct 17, 2026
3915c81
fix(markdown): distinguish table code and retry themed diagrams
niconicohu Oct 17, 2026
fd41f4f
Merge current main into Markdown rendering
niconicohu Oct 17, 2026
308cba9
Merge main page rendering and simplify Markdown presentation
niconicohu Oct 17, 2026
0eab49e
test(mobile): typecheck page text and quote contrast assertions
niconicohu Oct 17, 2026
74d26a4
fix(mobile): isolate diagram timeouts and comment code surfaces
niconicohu Oct 17, 2026
d028cef
fix(mobile): bound diagram queue waiting without concurrent renders
niconicohu Oct 17, 2026
91822d5
Merge main tool palette additions into Markdown rendering
niconicohu Oct 18, 2026
ede38bb
Retain markdown palettes with main composer tokens
niconicohu Oct 18, 2026
6353427
fix(markdown): keep rounded table borders visible on dark surfaces
niconicohu Oct 19, 2026
5485322
fix(markdown): include CJK emphasis in the formatting improvements
niconicohu Oct 21, 2026
5c7b6fe
Merge upstream/main and preserve dark terminal fallback with bottom-r…
niconicohu Oct 21, 2026
c029467
Merge main security updates into mobile Markdown rendering
niconicohu Oct 22, 2026
0171cec
Merge current main browser prop extraction into mobile Markdown
niconicohu Oct 22, 2026
a0878d8
Merge upstream/main into mobile Markdown rendering
niconicohu Oct 22, 2026
0ba3984
Merge upstream main into mobile Markdown rendering
niconicohu Oct 23, 2026
41f6c69
Merge main and reuse upstream CJK markdown parsing
niconicohu Oct 23, 2026
ee1ae3c
Merge upstream main and adapt Mermaid DOM fixture
niconicohu Oct 25, 2026
4fc2396
Fix mobile Markdown compatibility with current lint and module paths
niconicohu Oct 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions config/scripts/mobile-web-app-mermaid-render.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const diagramDir = join(mobileDir, 'src/components/pr-sidebar')
const FIXTURE =
'graph TD\n A[Start] --> B{Choice}\n B -->|yes| C[Ship it]\n B -->|no| D[Fix it]\n D --> A'

const CUSTOM =
'flowchart LR\n A[Done] --> B[Now] --> C[Next]\n classDef done fill:#e8f5e9,stroke:#43a047\n classDef current fill:#fff3cd,stroke:#e0a800\n classDef future fill:#f5f5f5,stroke:#999\n class A done\n class B current\n class C future'

/** A second valid diagram for the source change: a different shape, so a stale SVG is visible. */
const SECOND = 'graph LR\n One --> Two\n Two --> Three'

Expand Down Expand Up @@ -274,6 +277,36 @@ function normaliseSvg(html, id) {
.replace(/ xmlns:xlink="[^"]*"/g, '')
}

function flowchartLabelColors() {
return Array.from(document.querySelectorAll('svg .node')).flatMap((node) => {
const shape = node.querySelector('.label-container')
return shape
? Array.from(node.querySelectorAll('text, .nodeLabel')).map((text) => [
getComputedStyle(shape).fill,
text.localName === 'text' || text.localName === 'tspan'
? getComputedStyle(text).fill
: getComputedStyle(text).color
])
: []
})
}

function labelContrast([background, foreground]) {
const luminance = (color) =>
color
.match(/[\d.]+/g)
.slice(0, 3)
.map(Number)
.map((v) => {
v /= 255
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4
})
.reduce((sum, v, i) => sum + v * [0.2126, 0.7152, 0.0722][i], 0)
const a = luminance(background),
b = luminance(foreground)
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
}

describeMermaid(
'mermaid on the page',
() => {
Expand All @@ -289,6 +322,20 @@ describeMermaid(
await browser?.close()
})

it('keeps custom light fills readable in the phone page', async () => {
const { page } = await openPage(browser)
try {
await show(page, CUSTOM)
const pairs = await page.evaluate(flowchartLabelColors)
expect(pairs.length).toBeGreaterThanOrEqual(3)
for (const pair of pairs) {
expect(labelContrast(pair)).toBeGreaterThanOrEqual(4.5)
}
} finally {
await page.close()
}
}, 600_000)

it('paints the diagram with no violation and no JIT', async () => {
const { page, consoleErrors } = await openPage(browser)
const fetched = []
Expand Down
4 changes: 4 additions & 0 deletions mobile/src/components/MobileMarkdown.file-links.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
vi.mock('../platform/clipboard', () => ({
useClipboardWriter: () => ({ writeText: async () => {} })
}))
vi.mock('lucide-react-native', () => ({ Copy: 'Copy', Check: 'Check' }))
import { createElement } from 'react'
import { act, create, type ReactTestRenderer, type ReactTestInstance } from 'react-test-renderer'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down
31 changes: 27 additions & 4 deletions mobile/src/components/MobileMarkdown.rendering.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
vi.mock('./MobileMarkdownCodeBlock', () => ({
MobileMarkdownCodeBlock: ({
code,
language,
fontSize,
lineHeight
}: {
code: string
language?: string
fontSize?: number
lineHeight?: number
}) =>
createElement(
'View',
null,
language ? createElement('Text', null, language) : null,
createElement('Text', { style: { fontSize, lineHeight } }, code)
)
}))
vi.mock('../platform/clipboard', () => ({
useClipboardWriter: () => ({ writeText: async () => {} })
}))
vi.mock('lucide-react-native', () => ({ Check: 'Check', Copy: 'Copy' }))
import { createElement } from 'react'
import { act, create, type ReactTestInstance, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -61,7 +84,7 @@ describe('MobileMarkdown rendering', () => {
[
'C1: nested lists keep their own markers and numbers',
'1. **Frontend**\n - React\n - Vite\n2. Backend',
['1.', 'Frontend', '-', 'React', '-', 'Vite', '2.', 'Backend']
['1.', 'Frontend', '•', 'React', '•', 'Vite', '2.', 'Backend']
],
[
'C1: blank lines keep one list, and a list cut short keeps its numbers',
Expand All @@ -71,7 +94,7 @@ describe('MobileMarkdown rendering', () => {
[
'C1: a wrapped item stays one item',
'- a long item\nwrapped at sixty\n- next',
['-', 'a long item\nwrapped at sixty', '-', 'next']
['•', 'a long item\nwrapped at sixty', '•', 'next']
],
[
'C1: a number starting a wrapped line is not a list',
Expand Down Expand Up @@ -115,7 +138,7 @@ describe('MobileMarkdown rendering', () => {
[
'C18: blocks inside a quote',
'> - a\n>\n> ```sh\n> ls\n> ```\n> > inner',
['-', 'a', 'sh', 'ls', 'inner']
['•', 'a', 'sh', 'ls', 'inner']
],
['C19: underlined headings and closing hashes', 'Title\n=====\n\n## Sub ##', ['Title', 'Sub']],
[
Expand Down Expand Up @@ -220,7 +243,7 @@ describe('MobileMarkdown tone', () => {
expect(styleOf(renderer!.root, 'Title').fontSize).toBe(30)
expect(styleOf(renderer!.root, 'quoted').fontSize).toBe(26)
expect(styleOf(renderer!.root, 'const a = 1').fontSize).toBe(24)
expect(styleOf(renderer!.root, 'code').fontSize).toBe(24)
expect(styleOf(renderer!.root, 'code').fontSize).toBeCloseTo(23.4)
expect(styleOf(renderer!.root, 'Cell').fontSize).toBe(24)
})
})
28 changes: 14 additions & 14 deletions mobile/src/components/MobileMarkdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMobileTheme } from '../theme/use-mobile-theme'
import { INLINE_TEXT_SELECTION } from './inline-text-selection'
import { memo, useContext, useMemo, type ReactNode } from 'react'
import { Text as NativeText, View } from 'react-native'
import { View, Text as NativeText } from 'react-native'
import { MARKDOWN_TONES, scaledMarkdownText, styles } from './mobile-markdown-styles'
import { renderBlocks, type MarkdownBlockContext } from './mobile-markdown-blocks'
import { MarkdownText } from './mobile-markdown-text'
Expand All @@ -9,14 +10,15 @@ import { useMobileMarkdownTree } from './use-mobile-markdown-tree'
import type { NativeChatVisualDirective } from '../../../src/shared/native-chat-visual-directive'

type Props = {
tone?: 'default' | 'onBright'
content?: string
fallback?: string
/** Enables iOS range selection for native-chat transcript prose. */
rangeSelectable?: boolean
/** Forward long presses from interactive Android transcript spans to the message. */
onLongPress?: () => void
/** Multiplier for every text size. Defaults to 1; the chat view passes >1 so its prose reads
* larger than the compact base. */
/** Multiplier for prose font size (paragraphs, lists, quotes). Defaults to 1;
* the chat view passes >1 so agent prose reads larger than the compact base. */
textScale?: number
/** When provided, detected file paths and file-target hrefs render as tappable
* and invoke this with the path text (worktree-relative or absolute, with an
Expand All @@ -29,8 +31,6 @@ type Props = {
/** The text is still being appended to: markup its end leaves open is closed, as on desktop,
* and a diagram stays code until the text stops. */
growing?: boolean
/** The surface under the text: `onBright` for your own message's light fill. */
tone?: keyof typeof MARKDOWN_TONES
}

function MobileMarkdownContent({
Expand All @@ -43,29 +43,27 @@ function MobileMarkdownContent({
growing = false,
tone: toneName = 'default'
}: Props) {
useMobileTheme()

// Interactive children own their touches and must forward the row action.
const setup = useContext(MarkdownTextContext)
const tone = MARKDOWN_TONES[toneName]
const text = content?.trim() ?? ''
const { root, directives } = useMobileMarkdownTree(text, renderVisual !== undefined, growing)
if (!text) {
return fallback ? (
<MarkdownText selectable={rangeSelectable} style={styles.paragraph}>
<MarkdownText selectable={rangeSelectable} style={[styles.paragraph, tone.text]}>
{fallback}
</MarkdownText>
) : null
}
const tone = MARKDOWN_TONES[toneName]
const ctx: MarkdownBlockContext = {
growing,
codeSelectable: !setup.androidTranscript,
textScale,
onOpenFile,
tone,
textScale,
// Zoomed list text has read a size above the sheet's since it first scaled; kept as it was.
listText: [
styles.listText,
scaledMarkdownText({ fontSize: 14, lineHeight: 20 }, textScale),
tone.text
],
listText: [styles.listText, scaledMarkdownText(styles.listText, textScale), tone.text],
rowLongPress: setup.androidTranscript ? setup.onLongPress : undefined,
directives,
renderVisual,
Expand All @@ -83,6 +81,8 @@ function MobileMarkdownContent({
}

function MobileMarkdownInner(props: Props): React.JSX.Element | null {
useMobileTheme()

const { rangeSelectable = false, onLongPress } = props
// Other Markdown surfaces retain their existing selection behavior.
const androidTranscript = rangeSelectable && !INLINE_TEXT_SELECTION
Expand Down
56 changes: 56 additions & 0 deletions mobile/src/components/MobileMarkdownCodeBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createElement } from 'react'
import { act, create } from 'react-test-renderer'
import { afterEach, expect, it, vi } from 'vitest'
import { applyMobileColorScheme } from '../theme/mobile-theme'
const clipboard = vi.hoisted(() => ({ writeText: vi.fn(async (_value: string) => {}) }))
vi.mock('../platform/clipboard', () => ({ useClipboardWriter: () => clipboard }))
vi.mock('lucide-react-native', () => ({ Copy: 'Copy', Check: 'Check' }))
vi.mock('react-native', () => ({
Text: 'Text',
View: 'View',
Pressable: 'Pressable',
ScrollView: 'ScrollView',
StyleSheet: { create: (style: unknown) => style, hairlineWidth: 1 }
}))
import { MobileMarkdownCodeBlock } from './MobileMarkdownCodeBlock'
afterEach(() => {
applyMobileColorScheme('dark')
clipboard.writeText.mockReset()
})
it('renders line numbers separately and copies exactly the code without the gutter', async () => {
const code = 'const value = "世界😀"\n\tvalue\n'
let tree!: ReturnType<typeof create>
act(() => {
tree = create(
createElement(MobileMarkdownCodeBlock, {
code,
language: 'ts',
fontSize: 15,
lineHeight: 21.25
})
)
})
try {
const gutter = tree.root
.findAll((node) => String(node.type) === 'Text')
.find((node) => node.props.importantForAccessibility === 'no-hide-descendants')!
expect(gutter.props.children).toBe('1\n2\n3')
expect(gutter.props.selectable).toBe(false)
const button = () => tree.root.find((node) => String(node.type) === 'Pressable')
await act(async () => {
await button().props.onPress()
})
expect(clipboard.writeText).toHaveBeenCalledWith(code)
expect(button().props.accessibilityLabel).toBe('Code copied')
const color = () =>
tree.root
.findAll((node) => String(node.type) === 'Text')
.find((node) => node.props.children === 'const')?.props.style.color
act(() => applyMobileColorScheme('light'))
expect(color()).toBe('#cf222e')
act(() => applyMobileColorScheme('dark'))
expect(color()).toBe('#ff7b72')
} finally {
act(() => tree.unmount())
}
})
Loading