parent
3ad45ff86e
commit
3c06b401b9
6 changed files with 33 additions and 18 deletions
|
|
@ -196,6 +196,7 @@ The HTML output accepts a Javascript object with configuration. Possible options
|
||||||
- `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none`
|
- `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
|
- `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`
|
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`
|
||||||
|
- `maxLineSizeInBlockForComparison`: maximum number os characters of the bigger line in a block to apply comparison, default is `200`
|
||||||
- `maxLineLengthHighlight`: only perform diff changes highlight if lines are smaller than this, default is `10000`
|
- `maxLineLengthHighlight`: only perform diff changes highlight if lines are smaller than this, default is `10000`
|
||||||
- `templates`: object with previously compiled templates to replace parts of the html
|
- `templates`: object with previously compiled templates to replace parts of the html
|
||||||
- `rawTemplates`: object with raw not compiled templates to replace parts of the html
|
- `rawTemplates`: object with raw not compiled templates to replace parts of the html
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
matching: 'none',
|
matching: 'none',
|
||||||
matchWordsThreshold: 0.25,
|
matchWordsThreshold: 0.25,
|
||||||
matchingMaxComparisons: 2500,
|
matchingMaxComparisons: 2500,
|
||||||
|
maxLineSizeInBlockForComparison: 200,
|
||||||
maxLineLengthHighlight: 10000,
|
maxLineLengthHighlight: 10000,
|
||||||
renderNothingWhenEmpty: false
|
renderNothingWhenEmpty: false
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,17 @@
|
||||||
var deleteType;
|
var deleteType;
|
||||||
|
|
||||||
var comparisons = oldLines.length * newLines.length;
|
var comparisons = oldLines.length * newLines.length;
|
||||||
var maxComparisons = that.config.matchingMaxComparisons || 2500;
|
|
||||||
var doMatching = comparisons < maxComparisons && (that.config.matching === 'lines' ||
|
var maxLineSizeInBlock = Math.max.apply(null,
|
||||||
that.config.matching === 'words');
|
[0].concat((oldLines.concat(newLines)).map(
|
||||||
|
function(elem) {
|
||||||
|
return elem.content.length;
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
|
||||||
|
var doMatching = comparisons < that.config.matchingMaxComparisons &&
|
||||||
|
maxLineSizeInBlock < that.config.maxLineSizeInBlockForComparison &&
|
||||||
|
(that.config.matching === 'lines' || that.config.matching === 'words');
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
|
|
|
||||||
|
|
@ -96,9 +96,14 @@
|
||||||
var deleteType;
|
var deleteType;
|
||||||
|
|
||||||
var comparisons = oldLines.length * newLines.length;
|
var comparisons = oldLines.length * newLines.length;
|
||||||
var maxComparisons = that.config.matchingMaxComparisons || 2500;
|
|
||||||
var doMatching = comparisons < maxComparisons && (that.config.matching === 'lines' ||
|
var maxLineSizeInBlock = Math.max.apply(null, (oldLines.concat(newLines)).map(function(elem) {
|
||||||
that.config.matching === 'words');
|
return elem.length;
|
||||||
|
}));
|
||||||
|
|
||||||
|
var doMatching = comparisons < that.config.matchingMaxComparisons &&
|
||||||
|
maxLineSizeInBlock < that.config.maxLineSizeInBlockForComparison &&
|
||||||
|
(that.config.matching === 'lines' || that.config.matching === 'words');
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
|
|
|
||||||
|
|
@ -372,23 +372,23 @@ describe('LineByLinePrinter', function() {
|
||||||
' <div class="d2h-code-line d2h-info">@@ -1 +1 @@</div>\n' +
|
' <div class="d2h-code-line d2h-info">@@ -1 +1 @@</div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr><tr>\n' +
|
'</tr><tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-del d2h-change">\n' +
|
' <td class="d2h-code-linenumber d2h-del">\n' +
|
||||||
' <div class="line-num1">1</div>\n' +
|
' <div class="line-num1">1</div>\n' +
|
||||||
'<div class="line-num2"></div>\n' +
|
'<div class="line-num2"></div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-del d2h-change">\n' +
|
' <td class="d2h-del">\n' +
|
||||||
' <div class="d2h-code-line d2h-del d2h-change">\n' +
|
' <div class="d2h-code-line d2h-del">\n' +
|
||||||
' <span class="d2h-code-line-prefix">-</span>\n' +
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn"><del>test</del></span>\n' +
|
' <span class="d2h-code-line-ctn"><del>test</del></span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr><tr>\n' +
|
'</tr><tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-ins d2h-change">\n' +
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||||
' <div class="line-num1"></div>\n' +
|
' <div class="line-num1"></div>\n' +
|
||||||
'<div class="line-num2">1</div>\n' +
|
'<div class="line-num2">1</div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins d2h-change">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins d2h-change">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-prefix">+</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
|
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
|
|
|
||||||
|
|
@ -253,11 +253,11 @@ describe('SideBySidePrinter', function() {
|
||||||
' <div class="d2h-code-side-line d2h-info">@@ -1 +1 @@</div>\n' +
|
' <div class="d2h-code-side-line d2h-info">@@ -1 +1 @@</div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr><tr>\n' +
|
'</tr><tr>\n' +
|
||||||
' <td class="d2h-code-side-linenumber d2h-del d2h-change">\n' +
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
||||||
' 1\n' +
|
' 1\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-del d2h-change">\n' +
|
' <td class="d2h-del">\n' +
|
||||||
' <div class="d2h-code-side-line d2h-del d2h-change">\n' +
|
' <div class="d2h-code-side-line d2h-del">\n' +
|
||||||
' <span class="d2h-code-line-prefix">-</span>\n' +
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn"><del>test</del></span>\n' +
|
' <span class="d2h-code-line-ctn"><del>test</del></span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
|
|
@ -277,11 +277,11 @@ describe('SideBySidePrinter', function() {
|
||||||
' <div class="d2h-code-side-line d2h-info"></div>\n' +
|
' <div class="d2h-code-side-line d2h-info"></div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr><tr>\n' +
|
'</tr><tr>\n' +
|
||||||
' <td class="d2h-code-side-linenumber d2h-ins d2h-change">\n' +
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
||||||
' 1\n' +
|
' 1\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins d2h-change">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-side-line d2h-ins d2h-change">\n' +
|
' <div class="d2h-code-side-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-prefix">+</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
|
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue