make matching configurable
This commit is contained in:
parent
8c059d30da
commit
94516c835b
4 changed files with 32 additions and 8 deletions
|
|
@ -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'`
|
||||
- `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`
|
||||
- `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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,19 @@
|
|||
var oldLines = [];
|
||||
var newLines = [];
|
||||
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){
|
||||
var oldLines = match[0];
|
||||
var newLines = match[1];
|
||||
|
|
@ -89,10 +101,10 @@
|
|||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
|
||||
|
||||
processedOldLines +=
|
||||
generateLineHtml(diffParser.LINE_TYPE.DELETE_CHANGES, oldLine.oldNumber, oldLine.newNumber,
|
||||
generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
||||
diff.first.line, diff.first.prefix);
|
||||
processedNewLines +=
|
||||
generateLineHtml(diffParser.LINE_TYPE.INSERT_CHANGES, newLine.oldNumber, newLine.newNumber,
|
||||
generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
||||
diff.second.line, diff.second.prefix);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
var highlightedLine = '';
|
||||
|
||||
var changedWords = [];
|
||||
if (!config.charByChar && config.matchWords) {
|
||||
if (!config.charByChar && config.matching === 'words') {
|
||||
var treshold = 0.25;
|
||||
if (typeof(config.matchWordsThreshold) !== "undefined") {
|
||||
treshold = config.matchWordsThreshold;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,19 @@
|
|||
var oldLines = [];
|
||||
var newLines = [];
|
||||
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){
|
||||
var oldLines = match[0];
|
||||
var newLines = match[1];
|
||||
|
|
@ -113,10 +125,10 @@
|
|||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
|
||||
|
||||
fileHtml.left +=
|
||||
generateSingleLineHtml(diffParser.LINE_TYPE.DELETE_CHANGES, oldLine.oldNumber,
|
||||
generateSingleLineHtml(deleteType, oldLine.oldNumber,
|
||||
diff.first.line, diff.first.prefix);
|
||||
fileHtml.right +=
|
||||
generateSingleLineHtml(diffParser.LINE_TYPE.INSERT_CHANGES, newLine.newNumber,
|
||||
generateSingleLineHtml(insertType, newLine.newNumber,
|
||||
diff.second.line, diff.second.prefix);
|
||||
}
|
||||
if (max > common) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue