Introduction
Introduced in v5.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.
| Attribute | Description |
|---|---|
source | The source text |
dest | The destination text |
cleanup | Optional post-processing to improve readability (default is semantic) |
editcost | New in v5.4.0 Threshold parameter for efficiency cleanup mode (default is 4) |
mode | New in v5.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
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:
<$diff-text source="The quick brown fox jumps" dest="The slick brown fox leaps"/>In words mode, differences are computed at the words level:
<$diff-text mode="words" source="The quick brown fox jumps" dest="The slick brown fox leaps"/>To 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