Skip to content

Commit 29fe96d

Browse files
authored
Update code diff example (#929)
* clarify diff setup * update example to `text`
1 parent af47b10 commit 29fe96d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

code.mdx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,19 @@ sayHello();
302302

303303
### Diff
304304

305-
Add single line comments with `[!code ++]` and `[!code --]` to mark added and removed lines. You can also mark multiple lines with a single comment, such as `[!code ++:3]` or `[!code --:5]`.
305+
Show a visual diff of added or removed lines in your code blocks. Added lines are highlighted in green and removed lines are highlighted in red.
306+
307+
To create diffs, add these special comments at the end of lines in your code block:
308+
309+
- `// [!code ++]`: Mark a line as added (green highlight).
310+
- `// [!code --]`: Mark a line as removed (red highlight).
311+
312+
For multiple consecutive lines, specify the number of lines after a colon:
313+
314+
- `// [!code ++:3]`: Mark the current line plus the next two lines as added.
315+
- `// [!code --:5]`: Mark the current line plus the next four lines as removed.
316+
317+
The comment syntax must match your programming language (for example, `//` for JavaScript or `#` for Python).
306318

307319
```js Diff Example icon="code" lines
308320
const greeting = "Hello, World!"; // [!code ++]
@@ -313,12 +325,12 @@ function sayHello() {
313325
sayHello();
314326
```
315327

316-
````mdx
328+
````text
317329
```js Diff Example icon="code" lines
318-
const greeting = "Hello, World!"; // [\!code ++]
330+
const greeting = "Hello, World!"; // [!code ++]
319331
function sayHello() {
320-
console.log("Hello, World!"); // [\!code --]
321-
console.log(greeting); // [\!code ++]
332+
console.log("Hello, World!"); // [!code --]
333+
console.log(greeting); // [!code ++]
322334
}
323335
sayHello();
324336
```

0 commit comments

Comments
 (0)