Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@tanstack/ai-client": "^0.11.3",
"@tanstack/ai-openai": "^0.9.5",
"@tanstack/create": "^0.69.0",
"@tanstack/highlight": "^0.0.7",
"@tanstack/highlight": "^0.0.8",
"@tanstack/markdown": "^0.0.11",
"@tanstack/pacer": "^0.21.1",
"@tanstack/react-hotkeys": "^0.10.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/components/markdown/CodeBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderCodeBlockData } from '@tanstack/highlight'
import { defaultHighlighter } from '@tanstack/highlight'
import { renderCodeFence } from '@tanstack/highlight/markdown'
import * as React from 'react'
import { CodeBlockView } from './CodeBlockView'
import { MermaidBlock } from './MermaidBlock'
Expand Down Expand Up @@ -37,7 +38,7 @@ function HighlightedCodeBlock({
title?: string
}) {
const rendered = React.useMemo(() => {
return renderCodeBlockData({ code, lang, title })
return renderCodeFence({ code, lang, title }, defaultHighlighter)
}, [code, lang, title])

return (
Expand Down
20 changes: 6 additions & 14 deletions src/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -707,25 +707,17 @@ pre {
@apply text-black overflow-x-auto relative leading-tight;
}

span.line {
display: inline-block;
width: 100%;
}

pre.has-diff span.diff {
width: calc(100% + 20px);
margin-left: -10px;
padding-right: 20px;
padding-left: 10px;
padding-top: 4px;
padding-bottom: 4px;
.th-line--deleted,
.th-line--inserted {
margin-inline: -1rem;
padding-inline: 1rem;
}

pre.has-diff span.remove {
.th-line--deleted {
background-color: #f43f5e29;
}

pre.has-diff span.add {
.th-line--inserted {
background-color: #10b98129;
}
/* Visually differentiates twoslash code samples */
Expand Down
25 changes: 25 additions & 0 deletions tests/code-highlighting.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { defaultHighlighter } from '@tanstack/highlight'
import { renderCodeFence } from '@tanstack/highlight/markdown'

test('inline diff notation renders as line decorations', () => {
const rendered = renderCodeFence(
{
code: [
`- const oldValue = true // [!code --]`,
`+ const newValue = true // [!code ++]`,
].join('\n'),
lang: 'tsx',
},
defaultHighlighter,
)

assert.equal(
rendered.copyText,
[`- const oldValue = true`, `+ const newValue = true`].join('\n'),
)
assert.match(rendered.htmlMarkup, /th-line--deleted/)
assert.match(rendered.htmlMarkup, /th-line--inserted/)
assert.doesNotMatch(rendered.htmlMarkup, /!code/)
Comment on lines +18 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that each decoration belongs to the correct line.

These assertions only check that both class names appear somewhere. A regression swapping the deleted and inserted classes would still pass. Verify that th-line--deleted is associated with oldValue and th-line--inserted with newValue (and ideally that each occurs exactly once).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/code-highlighting.test.ts` around lines 18 - 24, Strengthen the
assertions around rendered.htmlMarkup so th-line--deleted is verified on the
line containing oldValue and th-line--inserted on the line containing newValue,
rather than only checking that both classes appear globally; also assert each
decoration occurs exactly once if supported by the existing test style.

})
Loading