Skip to content

Commit f051180

Browse files
committed
update readme for unidiff
1 parent b95d2e6 commit f051180

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ DiffPlex is C# library to generate textual diffs. It targets `netstandard1.0+`.
55

66
# About the API
77

8-
The DiffPlex library currently exposes two interfaces for generating diffs:
8+
The DiffPlex library currently exposes several interfaces and classes for generating diffs:
99

1010
* `IDiffer` (implemented by the `Differ` class) - This is the core diffing class. It exposes the low level functions to generate differences between texts.
1111
* `ISidebySideDiffer` (implemented by the `SideBySideDiffer` class) - This is a higher level interface. It consumes the `IDiffer` interface and generates a `SideBySideDiffModel`. This is a model which is suited for displaying the differences of two pieces of text in a side by side view.
12+
* `UnidiffRenderer` - A renderer class that generates unified diff (unidiff) format output compatible with Git, patch utilities, and other standard diff tools.
1213

1314
## Examples
1415

@@ -24,6 +25,10 @@ For use of the `ISidebySideDiffer` interface see:
2425
* `DiffController.cs` and associated MVC views in the `WebDiffer` project
2526
* `TextBoxDiffRenderer.cs` in the `SilverlightDiffer` project
2627

28+
For use of the `UnidiffRenderer` class see:
29+
30+
* `Program.cs` in the `DiffPlex.ConsoleRunner` project
31+
2732
## Sample code
2833

2934
```csharp
@@ -133,6 +138,41 @@ Currently provided implementations:
133138
- `LineEndingsPreservingChunker`
134139
- `WordChunker`
135140

141+
## UnidiffRenderer Class
142+
143+
The `UnidiffRenderer` class provides functionality to generate unified diff (unidiff) format output, which is the standard format used by Git, patch utilities, and other diff tools.
144+
145+
```csharp
146+
// Static method for simple usage
147+
string unidiff = UnidiffRenderer.GenerateUnidiff(
148+
oldText: "old content",
149+
newText: "new content",
150+
oldFileName: "file1.txt",
151+
newFileName: "file2.txt"
152+
);
153+
154+
// Instance usage with custom settings
155+
var renderer = new UnidiffRenderer(contextLines: 5);
156+
string unidiff = renderer.Generate(oldText, newText, "before.txt", "after.txt");
157+
```
158+
159+
Key features:
160+
- Generates standard unified diff format compatible with Git and patch tools
161+
- Configurable number of context lines around changes
162+
- Support for custom file names in diff headers
163+
- Options to ignore whitespace and case differences
164+
165+
Example output:
166+
```
167+
--- before.txt
168+
+++ after.txt
169+
@@ -1,4 +1,4 @@
170+
Line 1
171+
-Old line 2
172+
+New line 2
173+
Line 3
174+
Line 4
175+
```
136176

137177
## ISideBySideDifferBuilder Interface
138178

unidiffTest.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Create a temporary file for the old version
44
TEMP_FILE=$(mktemp)
55

6-
FILE_PATH="DiffPlex/Renderer/Unidiff.cs"
6+
FILE_PATH="README.md"
77

88
# Get the previous version of Program.cs from git history
9-
git show HEAD~1:$FILE_PATH > "$TEMP_FILE"
9+
git show HEAD~20:$FILE_PATH > "$TEMP_FILE"
1010

1111
# Run the ConsoleRunner with file mode
1212
dotnet run --project DiffPlex.ConsoleRunner file "$TEMP_FILE" "$FILE_PATH"

0 commit comments

Comments
 (0)