User:Cacycle/diff.js: Difference between revisions

Content deleted Content added
1.0.18 (September 13, 2014) split around newlines, fixes bubbling
1.0.19 (September 14, 2014) paragraph split after newline, bubbling to sliding
Line 3:
// ==UserScript==
// @name wDiff
// @version 1.0.1819
// @date September 1314, 2014
// @description improved word-based diff library with block move detection
// @homepage https://en.wikipedia.org/wiki/User:Cacycle/diff
Line 31:
* Block move detection and visualization
* Minimizing length of moved vs. static blocks
* Bubbling upSliding of ambiguous unresolved regions to next line break
* Optional omission of unchanged irrelevant parts from the output
* Fully customizable
Line 143:
wDiff.regExpSplit = {
 
// paragraphs: before and after newline
paragraph: /.*\n/g,
 
// sentences: after .spaces
Line 161:
}
 
// regExps for bubbling upsliding gaps
if (wDiff.regExpBubbleStopregExpSlideStop === undefined) { wDiff.regExpBubbleStopregExpSlideStop = /\n$/; }
if (wDiff.regExpBubbleClosingregExpSlideClosing === undefined) { wDiff.regExpBubbleClosingregExpSlideClosing = /^[\s)\]}>\-–—.,:;?!’\/\\=+]/; }
 
// regExp for counting words
Line 551:
wDiff.CalculateDiff(text, symbols, 'word', true);
 
// bubbleslide up gaps
wDiff.BubbleUpGapsSlideGaps(text.newText, text.oldText);
wDiff.BubbleUpGapsSlideGaps(text.oldText, text.newText);
 
// split tokens into chars in selected unresolved gaps
Line 562:
wDiff.CalculateDiff(text, symbols, 'character', true);
 
// bubbleslide up gaps
wDiff.BubbleUpGapsSlideGaps(text.newText, text.oldText);
wDiff.BubbleUpGapsSlideGaps(text.oldText, text.newText);
}
 
Line 961:
 
 
// wDiff.BubbleUpGapsSlideGaps: move gaps with ambiguous identical fronts and backs up
// start ambiguous gap borders after line breaks and text section closing characters
// changes: text (text.newText or text.oldText) .tokens list
// called from: wDiff.Diff()
 
wDiff.BubbleUpGapsSlideGaps = function (text, textLinked) {
 
// cycle through tokens list
Line 981:
else if ( (gapStart !== null) && (text.tokens[i].link !== null) ) {
 
// bubbleslide down as deep as possible
var front = gapStart;
var back = i;
Line 1,009:
(text.tokens[frontTest].token == text.tokens[backTest].token)
) {
if (wDiff.regExpBubbleStopregExpSlideStop.test(text.tokens[frontTest].token) === true) {
frontStop = frontTest;
break;
}
else if ( (frontStop === null) && (wDiff.regExpBubbleClosingregExpSlideClosing.test(text.tokens[frontTest].token) === true) ) {
frontStop = frontTest;
}
Line 1,020:
}
 
// actually bubbleslide up to last line break or closing text
if (frontStop !== null) {
while (
Line 1,513:
// repeat from start after conversion
if (unlinked === true) {
wDiff.BubbleUpGapsSlideGaps(text.newText, text.oldText);
wDiff.BubbleUpGapsSlideGaps(text.oldText, text.newText);
 
// repeat block detection from start