DiffPlex Documentation

repository·master·Indexed 22 days ago

https://github.com/mmanela/diffplex

A C# library for generating textual diffs, including line, character, and word-level comparisons, three-way merges, and unified diff formats. It targets netstandard1.0+ and provides UI components for various platforms, including Blazor, WPF, WinUI3 (DiffPlex.Windows), and Windows Forms.

Tokens
6.1K
Snippets
22
Records
33
Agent score
79%

What's inside DiffPlex

  1. Overview of DiffPlex.Blazor features and styling

    master

    DiffPlex.Blazor is a Blazor web application that demonstrates how to use the DiffPlex library for web-based text diffing.

    Key Features

    • Side-by-Side Diff Viewer: Split-pane view for comparing texts.
    • Inline Diff Viewer: Unified view with change indicators.
    • Unified Diff Format: Support for Git-style unified diff output.
    • Real-time Updates: Live rendering as text is edited.

    Visual Styling

    The components use CSS to provide a GitHub-like visualization:

    • Green: Added lines.
    • Red: Deleted lines.
    • Yellow: Modified lines.
    • Layout: Includes line numbers, change type indicators, and monospace fonts for alignment.
  2. Overview of DiffPlex API

    master

    DiffPlex is a C# library for generating textual diffs, targeting netstandard1.0+. The API is organized into several specialized interfaces and classes depending on your use case:

    • Low-level diffing: Use IDiffer (implemented by Differ) to generate raw differences between texts at various granularities (lines, characters, words, or custom chunks).
    • Side-by-side visualization: Use ISidebySideDiffer (implemented by SideBySideDiffer) to generate a SideBySideDiffModel, which is optimized for UI components that display two texts next to each other.
    • Three-way diff and merge: Use IThreeWayDiffer (implemented by ThreeWayDiffer) to compare a base text against two modified versions. This is used to detect changes and resolve conflicts during merges.
    • Standard diff formats: Use UnidiffRenderer to generate unified diff (unidiff) output compatible with Git and standard patch utilities.
  3. Understand the Bootstrap package structure

    master

    The Bootstrap distribution includes compiled and minified versions of CSS and JS, along with source maps and fonts. The directory structure typically looks like this:

    • css/: Contains bootstrap.css, bootstrap.min.css (minified), and bootstrap-theme.css (optional theme). Includes .map files for CSS source maps.
    • js/: Contains bootstrap.js and bootstrap.min.js.
    • fonts/: Contains Glyphicons assets (e.g., .eot, .svg, .ttf, .woff, .woff2).
    bootstrap/
    ├── css/
    │   ├── bootstrap.css
    │   ├── bootstrap.css.map
    │   ├── bootstrap.min.css
    │   ├── bootstrap.min.css.map
    │   ├── bootstrap-theme.css
    │   ├── bootstrap-theme.css.map
    │   ├── bootstrap-theme.min.css
    │   └── bootstrap-theme.min.css.map
    ├── js/
    │   ├── bootstrap.js
    │   └── bootstrap.min.js
    └── fonts/
        ├── glyphicons-halflings-regular.eot
        ├── glyphicons-halflings-regular.svg
        ├── glyphicons-halflings-regular.ttf
        ├── glyphicons-halflings-regular.woff
        └── glyphicons-halflings-regular.woff2
  4. Add text diff rendering to a Windows App SDK application

    master
    To implement text diff rendering in a Windows App SDK application, use the DiffTextView class. You can initialize an instance of DiffTextView within your MainWindow.xaml and its corresponding code-behind file MainWindow.xaml.cs to render text differences in your UI.
  5. Build the DiffPlex App for Windows App SDK

    master

    When building the DiffPlex App, follow these requirements:

    • Deployment Mode: Ensure the project runs in Package mode, as the configuration is set up for MSIX packaging.
    • CPU Architecture: Supported platforms are x64, x86, and arm64.
    • Output Behavior:
      • In Debug mode, the app will output test data of texture diffs.
      • In Release mode, the app will output empty data.
  6. Use DiffPlex WinForms controls

    master

    The DiffPlex.Wpf assembly also includes a Windows Forms control (a WPF element host control) for use in WinForms applications. It targets .NET 8, .NET 6, .NET Framework 4.8, and .NET Framework 4.6.

    1. Install the DiffPlex.Wpf NuGet package.
    2. Add the namespace: using DiffPlex.WindowsForms.Controls;
    3. Instantiate and add the DiffViewer to your form.
    using DiffPlex.WindowsForms.Controls;
    
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
    
            var diffView = new DiffViewer
            {
                Margin = new Padding(0),
                Dock = DockStyle.Fill,
                OldText = oldText,
                NewText = newText
            };
            Controls.Add(diffView);
        }
    }
  7. Use DiffPlex WPF controls

    master

    The DiffPlex.Wpf library provides controls for rendering textual diffs in WPF applications. It supports .NET 9, .NET 8, .NET 6, .NET Framework 4.8, and .NET Framework 4.6.

    1. Install the DiffPlex.Wpf NuGet package.
    2. Add the namespace to your XAML root node: xmlns:diffplex="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf"
    3. Choose a control:
      • DiffViewer: Standard viewer with view mode switching via OldText and NewText.
      • SideBySideDiffViewer: Side-by-side viewer using a SideBySideDiffModel.
      • InlineDiffViewer: Inline (unified) viewer using a DiffPaneModel.

    Example using DiffViewer:

    <diffplex:DiffViewer x:Name="DiffView" />
    using DiffPlex.Wpf.Controls;
    // ...
    DiffView.OldText = oldText;
    DiffView.NewText = newText;
  8. Use the DiffViewer in a WPF application

    master
    The DiffPlex.Wpf library provides a DiffViewer control designed for displaying diffs within a WPF application. In a typical implementation, you can place the DiffViewer in your XAML (e.g., in MainWindow.xaml) to visualize differences between text segments. You can also implement UI controls, such as buttons, to allow users to switch between different view modes.
  9. Run Bootstrap documentation locally

    master

    The documentation is built with Jekyll and can be run on your local machine:

    1. Install Jekyll and Ruby dependencies using bundle install. Note: Windows users may need to follow an unofficial guide to set up Jekyll correctly.
    2. From the root /bootstrap directory, run bundle exec jekyll serve.
    3. Access the documentation at http://localhost:9001 in your browser.
    bundle install
    bundle exec jekyll serve
  10. Run the sample Blazor application

    master

    To explore the interactive side-by-side rendering, inline diff view, and three-way merge capabilities in a Blazor environment, you can run the provided sample application.

    cd DiffPlex.Blazor
    dotnet run
  11. Use DiffPlex WinUI 3 elements

    master

    The DiffPlex.Windows library allows you to render textual diffs in applications targeting the Windows App SDK.

    1. Install the DiffPlex.Windows NuGet package.
    2. Add the namespace to your XAML root node: xmlns:diffplex="using:DiffPlex.UI"
    3. Use the DiffTextView element in your XAML.
    4. Populate the view using the SetText method in your code-behind.
    <diffplex:DiffTextView x:Name="DiffView" />
    using DiffPlex.UI;
    // ...
    DiffView.SetText(OldText, NewText);
  12. Use DiffViewer in a Windows Forms application

    master
    To render text diffs in a Windows Forms application, you can use the DiffViewer class. In your form (e.g., MainForm.cs), initialize an instance of DiffViewer to handle the rendering of differences between text inputs. You can also implement UI controls, such as buttons, to allow users to switch between different view modes during runtime.