Code Diff
Description
A rendered unified diff, line-by-line or side-by-side
CodeDiff renders unified-diff text (the output of git diff, for example) using the diff2html library. The slim UI bundle and its CSS ship with Tesserae, so there is no preload step.
OutputFormat picks between Format.LineByLine (additions and deletions one after the other, in a single column) and Format.SideBySide (the original on the left, the new file on the right). DrawFileList adds a summary list of the files in the diff above it, and LineMatching controls how diff2html pairs lines between the two sides (None, Lines or Words).
HighlightCode asks diff2html to syntax-highlight the result. That relies on a globally available hljs (highlight.js); it is a no-op when highlight.js is not loaded.
Samples
Line by line
Side by side, with a file list
API reference
public class CodeDiff : ComponentBase<CodeDiff, HTMLElement>A component that renders a unified diff using the diff2html library. The slim UI bundle and its CSS are bundled with Tesserae and always available - no preload step is required.
- Namespace
- Tesserae
- Inheritance
- ComponentBase<CodeDiff, HTMLElement> → CodeDiff
Constructors
| Name | Description |
|---|---|
| CodeDiff | Initializes a new CodeDiff for the given unified diff text. |
Properties
| Name | Description |
|---|---|
| DiffText | Gets or sets the unified diff text to render. |
| OutputFormat | Gets or sets the output layout (line-by-line or side-by-side). |
| DrawFileList | When true, a summary list of files in the diff is rendered above the diff. |
| HighlightCode | When true, asks diff2html to call highlightCode() after drawing. This relies on a globally-available hljs (highlight.js); it is a no-op if highlight.js is not loaded. |
| LineMatching | Controls how diff2html matches lines between the two sides. |
public string DiffText { get ; set ; }Gets or sets the unified diff text to render.
public Format OutputFormat { get ; set ; }Gets or sets the output layout (line-by-line or side-by-side).
public bool DrawFileList { get ; set ; }When true, a summary list of files in the diff is rendered above the diff.
public bool HighlightCode { get ; set ; }When true, asks diff2html to call highlightCode() after drawing. This relies on a globally-available hljs (highlight.js); it is a no-op if highlight.js is not loaded.
Methods
| Name | Description |
|---|---|
| Render | Renders the component. |
See also
- Annotated Text Editor — an editable surface for the same text.
- Wrapping a JavaScript library — how a component like this is built.
- Components overview