Diff Module

The Diff module provides a dedicated API for diff and merge. In the source code available on GitHub there are 2 main modules:

Base API Module

The Base API module implements the DiffManager Role and provides a generic diff and 3-way merge component. Since the data type is generic, you will have to convert the data you need to diff into lists. The final diff will be between these lists.

To display a diff for a text you can choose between:

Display API module

This module displays a DiffResult obtained with the base API in various formats. The 2 supported diff formats are Unified and Inline

Inline Diff

An Inline diff is made of a list of chunks, each marked as added, removed or unmodified. Below, you can see what the diff looks like when the changes are computed at character level

InlineDiffCharLevel.png

or at word level

InlineDiffWordLevel.png

Unified Diff

A unified diff is a list of blocks grouping modifications that are close to one another. The distance between 2 changes in the same block should be less than 2 times the size of the context. The context size is the number of unmodified elements included before and after a change so that the modification can be placed in context.

In case a splitter is provided (word, character), the unified diff also displays the modifications made on the elements in inline format. If the compared elements are lines of text and a word splitter in provided, you should see the unified diff below:

UnifiedDiffLineLevel.png

Expose the API in Velocity

To expose the Diff module API in Velocity, you can use script services as follows:

Compute the differences between two lists of elements

{{velocity}}
#set ($diffResult = $services.diff.diff($previous, $next, $configuration))
{{/velocity}}

Display the differences between two texts in the unified format

{{velocity}}
#set($blocks = $services.diff.display.unified($previous, $next))
#foreach ($block in $blocks)
  $block
#end
{{/velocity}}

   

Search this space