From 53958687a63671150a1dec768d612cbe5b1178bc Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sat, 5 Oct 2019 10:47:43 +0100 Subject: [PATCH] fix: Bring char by char option back --- README.md | 1 + src/diff2html.js | 1 + src/printer-utils.js | 4 ++-- test/printer-utils-tests.js | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 03ca023..c1424a6 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ The HTML output accepts a Javascript object with configuration. Possible options - `inputFormat`: the format of the input data: `'diff'` or `'json'`, default is `'diff'` - `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'` - `showFiles`: show a file list before the diff: `true` or `false`, default is `false` + - `diffStyle`: show differences level in each line: `word` or `char`, default is `word` - `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none` - `matchWordsThreshold`: similarity threshold for word matching, default is 0.25 - `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500` diff --git a/src/diff2html.js b/src/diff2html.js index 715ff30..4d4155d 100644 --- a/src/diff2html.js +++ b/src/diff2html.js @@ -17,6 +17,7 @@ inputFormat: 'diff', outputFormat: 'line-by-line', showFiles: false, + diffStyle: 'word', matching: 'none', matchWordsThreshold: 0.25, matchingMaxComparisons: 2500, diff --git a/src/printer-utils.js b/src/printer-utils.js index d6edef8..d4a61be 100644 --- a/src/printer-utils.js +++ b/src/printer-utils.js @@ -159,7 +159,7 @@ } var diff; - if (config.charByChar) { + if (config.diffStyle === 'char') { diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2); } else { diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2); @@ -168,7 +168,7 @@ var highlightedLine = ''; var changedWords = []; - if (!config.charByChar && config.matching === 'words') { + if (config.diffStyle === 'word' && config.matching === 'words') { var treshold = 0.25; if (typeof (config.matchWordsThreshold) !== 'undefined') { diff --git a/test/printer-utils-tests.js b/test/printer-utils-tests.js index 4d603b9..b3c8213 100644 --- a/test/printer-utils-tests.js +++ b/test/printer-utils-tests.js @@ -99,7 +99,7 @@ describe('Utils', function() { var result = PrinterUtils.diffHighlight( '-var myVar = 2;', '+var myVariable = 3;', - {charByChar: true} + { diffStyle: 'char' } ); assert.deepEqual({ @@ -118,6 +118,7 @@ describe('Utils', function() { ' -var myVar = 2;', ' +var myVariable = 3;', { + diffStyle: 'word', isCombined: true, matching: 'words', matchWordsThreshold: 1.00