diff-match-patch-line-and-unicode-aware-word
v0.2.2
Published
An extension module that adds line-mode and Unicode-aware word-mode on diff-match-patch.
Downloads
4
Maintainers
Readme
Diff Patch Merge Line and Unicode-Aware Word
What's this
An extension module that adds line-mode and word-mode diffs on google-diff-match-patch hosted as diff-patch-merge at NPM, originally by Neil Fraser, while respecting Unicode character sets and some general liquistic behaviors (e.g., hyphens and apostrophes are parts of words, but underscores are not) when identifying word breaks. This is based on karak's [diff-match-patch-line-and-word](https://github.com/karak/diff-match-patch-line-and-word
Support for languages using marks (vowel marks above/below/inside consonants), left-to-right scripts, accented letters and similar items have been tested. PLEASE NOTE: Lines containing mixed scripts may give unexpected results and are considered unsupported. If you identify issues, please give complete examples indicating the two inputs, the incorrect results, the expected results and the name of the script used.
TypeScript is also supported.
API
Methods
diff_lineMode
Execute diff_main line-by-line.
Parameter
|Parameter|Type |Description| |---------|------|-----------| |text1 |string|Old text to compare.| |text2 |string|New text to compare.|
Return value
|Type|Description| |----|-----------| |Array of diff_patch_merge.Diff|result diff tuples.|
diff_wordMode
Execute diff_main word-by-word.
The signature is same.
How to use
Just import after node-diff-patch-merge.
Example:
import { diff_match_patch } from 'diff-match-patch';
import 'diff-match-patch-line-and-unicode-aware-word'; // import globally to patch the class.
const dmp = new diff_match_patch();
const oldText = 'He writes the letter.';
const newText = 'She wrote the letters.';
const diffs = dmp.diff_lineMode(oldText, newText);
const html = dmp.diff_prettyHtml(diffs));
document.write(html);