make matching configurable

This commit is contained in:
Wolfgang Illmeyer 2015-12-09 23:17:26 +01:00
parent 8c059d30da
commit 94516c835b
4 changed files with 32 additions and 8 deletions

View file

@ -50,7 +50,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'` - `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'` - `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` - `showFiles`: show a file list before the diff: `true` or `false`, default is `false`
- `matchWords`: matches changed words in diff output lines: `true` or `false`, default is `false` - `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

View file

@ -71,7 +71,19 @@
var oldLines = []; var oldLines = [];
var newLines = []; var newLines = [];
function processChangeBlock() { function processChangeBlock() {
var matches = matcher(oldLines, newLines); var matches;
var insertType;
var deleteType;
var doMatching = config.matching === "lines" || config.matching === "words";
if (doMatching) {
matches = matcher(oldLines, newLines);
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
deleteType = diffParser.LINE_TYPE.DELETE_CHANGES;
} else {
matches = [[oldLines,newLines]];
insertType = diffParser.LINE_TYPE.INSERTS;
deleteType = diffParser.LINE_TYPE.DELETES;
}
matches.forEach(function(match){ matches.forEach(function(match){
var oldLines = match[0]; var oldLines = match[0];
var newLines = match[1]; var newLines = match[1];
@ -89,10 +101,10 @@
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
processedOldLines += processedOldLines +=
generateLineHtml(diffParser.LINE_TYPE.DELETE_CHANGES, oldLine.oldNumber, oldLine.newNumber, generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
diff.first.line, diff.first.prefix); diff.first.line, diff.first.prefix);
processedNewLines += processedNewLines +=
generateLineHtml(diffParser.LINE_TYPE.INSERT_CHANGES, newLine.oldNumber, newLine.newNumber, generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
diff.second.line, diff.second.prefix); diff.second.line, diff.second.prefix);
} }

View file

@ -71,7 +71,7 @@
var highlightedLine = ''; var highlightedLine = '';
var changedWords = []; var changedWords = [];
if (!config.charByChar && config.matchWords) { if (!config.charByChar && config.matching === 'words') {
var treshold = 0.25; var treshold = 0.25;
if (typeof(config.matchWordsThreshold) !== "undefined") { if (typeof(config.matchWordsThreshold) !== "undefined") {
treshold = config.matchWordsThreshold; treshold = config.matchWordsThreshold;

View file

@ -95,7 +95,19 @@
var oldLines = []; var oldLines = [];
var newLines = []; var newLines = [];
function processChangeBlock() { function processChangeBlock() {
var matches = matcher(oldLines, newLines); var matches;
var insertType;
var deleteType;
var doMatching = config.matching === "lines" || config.matching === "words";
if (doMatching) {
matches = matcher(oldLines, newLines);
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
deleteType = diffParser.LINE_TYPE.DELETE_CHANGES;
} else {
matches = [[oldLines,newLines]];
insertType = diffParser.LINE_TYPE.INSERTS;
deleteType = diffParser.LINE_TYPE.DELETES;
}
matches.forEach(function(match){ matches.forEach(function(match){
var oldLines = match[0]; var oldLines = match[0];
var newLines = match[1]; var newLines = match[1];
@ -113,10 +125,10 @@
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
fileHtml.left += fileHtml.left +=
generateSingleLineHtml(diffParser.LINE_TYPE.DELETE_CHANGES, oldLine.oldNumber, generateSingleLineHtml(deleteType, oldLine.oldNumber,
diff.first.line, diff.first.prefix); diff.first.line, diff.first.prefix);
fileHtml.right += fileHtml.right +=
generateSingleLineHtml(diffParser.LINE_TYPE.INSERT_CHANGES, newLine.newNumber, generateSingleLineHtml(insertType, newLine.newNumber,
diff.second.line, diff.second.prefix); diff.second.line, diff.second.prefix);
} }
if (max > common) { if (max > common) {