Code Diff
Compare two code blocks side by side with aligned additions and deletions.
Stable
- Introduced
- v0.1.5
- Supported through
- Latest
CodeDiff compares two fenced code blocks. The first block is the old version; the second is the new version.
Beforetsx
Aftertsx
Deleted: 123231321
Added: 123
Added: 231
Added: 321
Deleted lines appear on the left in red, and added lines appear on the right in green. Missing counterparts reserve an empty space. Each side retains its original line numbers. Long lines wrap, and paired rows always share the same height.
Unchanged lines and titles
Unchanged lines appear on both sides. Use a code fence's title to label each version; otherwise, the headers display Before and After.
Before: greeting.tsxtsx
After: greeting.tsxtsx
export function Greeting() {
export function Greeting() {
Deleted: return <p>Hello</p>
Added: const name = "Code Atlas"
Added: return <p>Hello, {name}!</p>
}
}
Exactly two fenced code blocks are required. Syntax highlighting follows each fence's language and supports light and dark themes.
CodeDiff Props2 properties
| Property | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Exactly two fenced code blocks, ordered as old and new versions. |
className | string | - | Additional classes for the diff container. |

