User:Cacycle/diff.js: Difference between revisions

Content deleted Content added
1.0.21 (September 14, 2014) fix split regexps (split newlines), css clean up, show blanks on hover, - wDiff.DebugGaps
1.0.22 (September 15, 2014) fix newline and space markup
Line 3:
// ==UserScript==
// @name wDiff
// @version 1.0.2122
// @date September 1415, 2014
// @description improved word-based diff library with block move detection
// @homepage https://en.wikipedia.org/wiki/User:Cacycle/diff
Line 2,421:
string = wDiff.HtmlEscape(string);
 
// add 'same' (unchanged) text and moved block
if (type == 'same') {
if (color !== null) {
diff += wDiff.HtmlFormatBlock(string);
string = string.replace(/\n/g, wDiff.htmlNewline);
}
else {
diff += string;
}
diff += string;
}
 
Line 2,437 ⟶ 2,439:
diff += wDiff.htmlDeleteStart;
}
diff += stringwDiff.replaceHtmlFormatBlock(/\n/g, wDiff.htmlNewlinestring) + wDiff.htmlDeleteEnd;
}
 
Line 2,448 ⟶ 2,450:
diff += wDiff.htmlInsertStart;
}
diff += stringwDiff.replaceHtmlFormatBlock(/\n/g, wDiff.htmlNewlinestring) + wDiff.htmlInsertEnd;
}
}
Line 2,480 ⟶ 2,482:
 
// get moved block text
var movedTextstring = '';
for (var block = groups[movedGroup].blockStart; block <= groups[movedGroup].blockEnd; block ++) {
if (blocks[block].type != 'ins') {
movedTextstring += blocks[block].string;
}
}
Line 2,489 ⟶ 2,491:
// display as deletion at original position
if (wDiff.showBlockMoves === false) {
ifstring = (wDiff.regExpBlankBlock.testHtmlEscape(movedTextstring) === true) {;
if (wDiff.regExpBlankBlock.test(string) === true) {
mark = wDiff.htmlDeleteStartBlank;
}
Line 2,495 ⟶ 2,498:
mark = wDiff.htmlDeleteStart;
}
mark += wDiff.HtmlEscapeHtmlFormatBlock(movedTextstring) + wDiff.htmlDeleteEnd;
}
 
Line 2,506 ⟶ 2,509:
mark = wDiff.htmlMarkRight;
}
mark = wDiff.HtmlCustomize(mark, markColor, movedTextstring);
}
 
Line 2,592 ⟶ 2,595:
 
 
//
// wDiff.HtmlEscape: replace html-sensitive characters in output text with character entities
// input: text
Line 2,608 ⟶ 2,610:
 
 
// wDiff.HtmlFormatBlock: markup newlines and spaces in blocks
// called from: wDiff.Diff(), wDiff.AssembleDiff()
//
 
// wDiff.HtmlFormat: tidy html, keep newlines and multiple spaces, add container
wDiff.HtmlFormatBlock = function (string) {
// spare blanks in tags
text.diffstring = text.diffstring.replace(/(<[^>]*>)|( )/g, function (p, p1, p2) {
if (p2 == ' ') {
return wDiff.htmlSpace;
}
return p1;
});
string = string.replace(/\n/g, wDiff.htmlNewline);
return string;
};
 
 
// wDiff.HtmlFormat: tidy html, keepjoin newlineschained andmarkup, multiplemarkup spacestabs, add container
// changes: text.diff
// called from: wDiff.Diff(), wDiff.AssembleDiff()
Line 2,617 ⟶ 2,636:
text.diff = text.diff.replace(/<\/(\w+)><!--wDiff(Delete|Insert)--><\1\b[^>]*\bclass="wDiff\2"[^>]*>/g, '');
text.diff = text.diff.replace(/\t/g, wDiff.htmlTab);
text.diff = text.diff.replace(/(<[^>]*>)|( )/g, function (p, p1, p2) {
if (p2 == ' ') {
return wDiff.htmlSpace;
}
return p1;
});
text.diff = wDiff.htmlContainerStart + wDiff.htmlFragmentStart + text.diff + wDiff.htmlFragmentEnd + wDiff.htmlContainerEnd;
return;