This page is part of a static HTML representation of the TiddlyWiki at https://tiddlywiki.com/

DiffTextWidget

2 janvier 2026 à 13h26

Introduction

Depuis<<:>> 5.1.16 The diff text widget analyses the differences between a pair of source and destination text strings and displays the results as highlighted insertions and deletions (similar to the "track changes" function of a word processor).

<$diff-text source="This is the original text" dest="This is the text to compare to" mode="words>
    These are the <<diff-count>> differences:
</$diff-text>

Content and Attributes

The content of the $diff-text widget is displayed immediately before the differences. Within the content, the variable diff-count is available, containing the number of differences found. If the widget has no content then it automatically transcludes the tiddler $:/language/Diffs/CountMessage.

Note
The algorithm counts changes as both insertion and deletion, and therefore the number of differences can be higher than expected.
AttributeDescription
sourceThe source text
destThe destination text
cleanupOptional post-processing to improve readability (default is semantic)
editcost Depuis<<:>> 5.4.0 Threshold parameter for efficiency cleanup mode (default is 4)
mode Depuis<<:>> 5.4.0 Specifies the granularity at which differences are computed and displayed (default is chars)

cleanup / editcost

The cleanup attribute determines which optional post-processing should be applied to the diffs:

  • none: No cleanup is performed
  • semantic (default): Optimizes the differences for readability
  • efficiency: Optimizes the differences to minimise the number of operations for subsequent processing
    • When using efficiency mode, the editcost parameter controls the cost threshold for the cleanup algorithm, determining how aggressively the diff algorithm merges nearby edits for better human readability (default value is 4).
Note
Note that in many cases the results will be the same regardless of the cleanup option. See the docs of the underlying library for more details

mode

The mode attribute determines how differences are computed and displayed:

  • chars: Compares differences at the character level for precise change detection
  • words: Compares differences at the word level for more readable text comparisons
  • lines: Compares differences at the line level for better visibility of structural changes

Examples

A basic example:

<$reveal default="
4 différences
The quslick brown fox jumleaps
" type="match" text="NO-SUCH-VAR">
e.g.
</$reveal> <$reveal default="
4 différences
The quslick brown fox jumleaps
" type="nomatch" text="NO-SUCH-VAR">

In words mode, differences are computed at the words level:

<$reveal default="
4 différences
The quick slick brown fox jumpsleaps
" type="match" text="NO-SUCH-VAR">
e.g.
</$reveal> <$reveal default="
4 différences
The quick slick brown fox jumpsleaps
" type="nomatch" text="NO-SUCH-VAR">

To see the effects of all parameters, use this example:

7 différences
This is a test tiddler is called SampleTiddlerFirstSecond.↩︎
It is used in [[DiffTextWidget]].↩︎
You can modifyedit its content.

mode

cleanup

editcost: 4