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.
| Attribute | Description |
|---|---|
source | The source text |
dest | The destination text |
cleanup | Optional 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 performedsemantic(default): Optimizes the differences for readabilityefficiency: Optimizes the differences to minimise the number of operations for subsequent processing- When using
efficiencymode, theeditcostparameter 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).
- When using
- 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 detectionwords: Compares differences at the word level for more readable text comparisonslines: Compares differences at the line level for better visibility of structural changes
Examples
A basic example:
The quslick brown fox jumleapse.g.
</$reveal>
<$reveal default="The quslick brown fox jumleapsIn words mode, differences are computed at the words level:
The quick slick brown fox jumpsleapse.g.
</$reveal>
<$reveal default="The quick slick brown fox jumpsleapsTo see the effects of all parameters, use this example:
This is a test tiddler is called SampleTiddlerFirstSecond.↩︎
It is used in [[DiffTextWidget]].↩︎
You can modifyedit its content.mode
cleanup
editcost: 4