Skip to content

Commit 9a89f31

Browse files
authored
Merge pull request #236 from rtfpessoa/fix-char-by-char-diff
fix: Bring char by char option back
2 parents 50cb2bf + 5395868 commit 9a89f31

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ The HTML output accepts a Javascript object with configuration. Possible options
194194
- `inputFormat`: the format of the input data: `'diff'` or `'json'`, default is `'diff'`
195195
- `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'`
196196
- `showFiles`: show a file list before the diff: `true` or `false`, default is `false`
197+
- `diffStyle`: show differences level in each line: `word` or `char`, default is `word`
197198
- `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none`
198199
- `matchWordsThreshold`: similarity threshold for word matching, default is 0.25
199200
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`

src/diff2html.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
inputFormat: 'diff',
1818
outputFormat: 'line-by-line',
1919
showFiles: false,
20+
diffStyle: 'word',
2021
matching: 'none',
2122
matchWordsThreshold: 0.25,
2223
matchingMaxComparisons: 2500,

src/printer-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
}
160160

161161
var diff;
162-
if (config.charByChar) {
162+
if (config.diffStyle === 'char') {
163163
diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
164164
} else {
165165
diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
@@ -168,7 +168,7 @@
168168
var highlightedLine = '';
169169

170170
var changedWords = [];
171-
if (!config.charByChar && config.matching === 'words') {
171+
if (config.diffStyle === 'word' && config.matching === 'words') {
172172
var treshold = 0.25;
173173

174174
if (typeof (config.matchWordsThreshold) !== 'undefined') {

test/printer-utils-tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('Utils', function() {
9999
var result = PrinterUtils.diffHighlight(
100100
'-var myVar = 2;',
101101
'+var myVariable = 3;',
102-
{charByChar: true}
102+
{ diffStyle: 'char' }
103103
);
104104

105105
assert.deepEqual({
@@ -118,6 +118,7 @@ describe('Utils', function() {
118118
' -var myVar = 2;',
119119
' +var myVariable = 3;',
120120
{
121+
diffStyle: 'word',
121122
isCombined: true,
122123
matching: 'words',
123124
matchWordsThreshold: 1.00

0 commit comments

Comments
 (0)