Diff
Innehåll
Code diff can either be written manually using the diff
language tag:
Input:
```diff
-export function foo(value: string): string {
+export function foo(value: string, param: number): string {
return "bar";
}
```
Output:
-export function foo(value: string): string {
+export function foo(value: string, param: number): string {
return "bar";
}
Each line in a diff should:
- Use
+
to signify an added line. - Use
-
to signify a removed line. - Use
Comparing
Diffs can also be created by comparing two examples by naming the first using name
and comparing with compare
.
The original example may optionally be hidden with the hidden
tag.
Input:
```ts name=original hidden
export function foo(value: string): string {
return "bar";
}
```
```ts compare=original
export function foo(value: string, param: number): string {
return "bar";
}
```
Output:
-export function foo(value: string): string {
+export function foo(value: string, param: number): string {
return "bar";
}
Context lines
To control the number of context lines use context=N
where N
is an integer greater than zero.
This sets the number of lines to show before and after the changed lines.
Default is 3 lines.
For instance, with context=1
we see one line before and after:
line 5
-line 6
+line 6 # change this line
line 7
@@ -19,3 +19,3 @@
line 19
-line 20
+line 20 # and this
line 21
And with context=6
we see four lines instead:
line 2
line 3
line 4
line 5
-line 6
+line 6 # change this line
line 7
line 8
line 9
line 10
@@ -16,9 +16,9 @@
line 16
line 17
line 18
line 19
-line 20
+line 20 # and this
line 21
line 22
line 23
line 24