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


or at word level


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:


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

#set ($diffResult = $services.diff.diff($previous, $next, $configuration))

Display the differences between two texts in the unified format

#set($blocks = $services.diff.display.unified($previous, $next))
#foreach ($block in $blocks)


Related Pages

Search this space


Most popular tags

Failed to execute the [groovy] macro
  1. access rights
  2. activity stream
  3. annotation
  4. attachment
  5. comment
  6. Document Tree Macro
  7. export
  8. Extension Manager
  9. Flamingo skin
  10. global user
  11. Groovy event listener
  12. group
  13. nested page
  14. search
  15. skin
  16. syntax
  17. user
  18. user profile
  19. velocity macros
  20. wiki
  21. wysiwyg
  22. XWiki Applications
  23. xwikiattachment_archive table
  24. xwikiattachment table
  25. xwikiattrecyclebin table
  26. xwikiproperties table

[Display all tags from this space]