Merge pull request #98 from rtfpessoa/fix-nbsp-properly
Fix convert &nbps; to proper white spaces with white-space wrap
This commit is contained in:
commit
1f2ffdbe42
9 changed files with 117 additions and 86 deletions
1
docs/assets
Symbolic link
1
docs/assets
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
../dist
|
||||||
|
|
@ -120,15 +120,15 @@
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
processedOldLines +=
|
processedOldLines +=
|
||||||
that.makeLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
that.makeLineHtml(file.isCombined, deleteType, oldLine.oldNumber, oldLine.newNumber,
|
||||||
diff.first.line, diff.first.prefix);
|
diff.first.line, diff.first.prefix);
|
||||||
processedNewLines +=
|
processedNewLines +=
|
||||||
that.makeLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
that.makeLineHtml(file.isCombined, insertType, newLine.oldNumber, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines += processedOldLines + processedNewLines;
|
lines += processedOldLines + processedNewLines;
|
||||||
lines += that._processLines(oldLines.slice(common), newLines.slice(common));
|
lines += that._processLines(file.isCombined, oldLines.slice(common), newLines.slice(common));
|
||||||
});
|
});
|
||||||
|
|
||||||
oldLines = [];
|
oldLines = [];
|
||||||
|
|
@ -145,9 +145,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
|
|
@ -164,37 +164,46 @@
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype._processLines = function(oldLines, newLines) {
|
LineByLinePrinter.prototype._processLines = function(isCombined, oldLines, newLines) {
|
||||||
var lines = '';
|
var lines = '';
|
||||||
|
|
||||||
for (var i = 0; i < oldLines.length; i++) {
|
for (var i = 0; i < oldLines.length; i++) {
|
||||||
var oldLine = oldLines[i];
|
var oldLine = oldLines[i];
|
||||||
var oldEscapedLine = utils.escape(oldLine.content);
|
var oldEscapedLine = utils.escape(oldLine.content);
|
||||||
lines += this.makeLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
lines += this.makeLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j = 0; j < newLines.length; j++) {
|
for (var j = 0; j < newLines.length; j++) {
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[j];
|
||||||
var newEscapedLine = utils.escape(newLine.content);
|
var newEscapedLine = utils.escape(newLine.content);
|
||||||
lines += this.makeLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
lines += this.makeLineHtml(isCombined, newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, content, prefix) {
|
LineByLinePrinter.prototype.makeLineHtml = function(isCombined, type, oldNumber, newNumber, content, possiblePrefix) {
|
||||||
var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', {
|
var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', {
|
||||||
oldNumber: utils.valueOrEmpty(oldNumber),
|
oldNumber: utils.valueOrEmpty(oldNumber),
|
||||||
newNumber: utils.valueOrEmpty(newNumber)
|
newNumber: utils.valueOrEmpty(newNumber)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var lineWithoutPrefix = content;
|
||||||
|
var prefix = possiblePrefix;
|
||||||
|
|
||||||
|
if (!prefix) {
|
||||||
|
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
|
||||||
|
prefix = lineWithPrefix.prefix;
|
||||||
|
lineWithoutPrefix = lineWithPrefix.line;
|
||||||
|
}
|
||||||
|
|
||||||
return hoganUtils.render(genericTemplatesPath, 'line',
|
return hoganUtils.render(genericTemplatesPath, 'line',
|
||||||
{
|
{
|
||||||
type: type,
|
type: type,
|
||||||
lineClass: 'd2h-code-linenumber',
|
lineClass: 'd2h-code-linenumber',
|
||||||
contentClass: 'd2h-code-line',
|
contentClass: 'd2h-code-line',
|
||||||
prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix),
|
prefix: prefix,
|
||||||
content: content && utils.convertWhiteSpaceToNonBreakingSpace(content),
|
content: lineWithoutPrefix,
|
||||||
lineNumber: lineNumberTemplate
|
lineNumber: lineNumberTemplate
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,24 @@
|
||||||
function PrinterUtils() {
|
function PrinterUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrinterUtils.prototype.separatePrefix = function(isCombined, line) {
|
||||||
|
var prefix;
|
||||||
|
var lineWithoutPrefix;
|
||||||
|
|
||||||
|
if (isCombined) {
|
||||||
|
prefix = line.substring(0, 2);
|
||||||
|
lineWithoutPrefix = line.substring(2);
|
||||||
|
} else {
|
||||||
|
prefix = line.substring(0, 1);
|
||||||
|
lineWithoutPrefix = line.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'prefix': prefix,
|
||||||
|
'line': lineWithoutPrefix
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
PrinterUtils.prototype.getHtmlId = function(file) {
|
PrinterUtils.prototype.getHtmlId = function(file) {
|
||||||
var hashCode = function(text) {
|
var hashCode = function(text) {
|
||||||
var i, chr, len;
|
var i, chr, len;
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,10 @@
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
fileHtml.left +=
|
fileHtml.left +=
|
||||||
that.generateSingleLineHtml(deleteType, oldLine.oldNumber,
|
that.generateSingleLineHtml(file.isCombined, deleteType, oldLine.oldNumber,
|
||||||
diff.first.line, diff.first.prefix);
|
diff.first.line, diff.first.prefix);
|
||||||
fileHtml.right +=
|
fileHtml.right +=
|
||||||
that.generateSingleLineHtml(insertType, newLine.newNumber,
|
that.generateSingleLineHtml(file.isCombined, insertType, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,7 +133,7 @@
|
||||||
var oldSlice = oldLines.slice(common);
|
var oldSlice = oldLines.slice(common);
|
||||||
var newSlice = newLines.slice(common);
|
var newSlice = newLines.slice(common);
|
||||||
|
|
||||||
var tmpHtml = that.processLines(oldSlice, newSlice);
|
var tmpHtml = that.processLines(file.isCombined, oldSlice, newSlice);
|
||||||
fileHtml.left += tmpHtml.left;
|
fileHtml.left += tmpHtml.left;
|
||||||
fileHtml.right += tmpHtml.right;
|
fileHtml.right += tmpHtml.right;
|
||||||
}
|
}
|
||||||
|
|
@ -154,11 +154,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
fileHtml.left += that.generateSingleLineHtml(file.isCombined, line.type, line.oldNumber, escapedLine, prefix);
|
||||||
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.left += that.generateSingleLineHtml(file.isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
|
|
@ -175,7 +175,7 @@
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
};
|
};
|
||||||
|
|
||||||
SideBySidePrinter.prototype.processLines = function(oldLines, newLines) {
|
SideBySidePrinter.prototype.processLines = function(isCombined, oldLines, newLines) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var fileHtml = {};
|
var fileHtml = {};
|
||||||
fileHtml.left = '';
|
fileHtml.left = '';
|
||||||
|
|
@ -201,14 +201,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldLine && newLine) {
|
if (oldLine && newLine) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
||||||
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
|
||||||
} else if (oldLine) {
|
} else if (oldLine) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
||||||
fileHtml.right += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.right += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
} else if (newLine) {
|
} else if (newLine) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.left += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
|
||||||
} else {
|
} else {
|
||||||
console.error('How did it get here?');
|
console.error('How did it get here?');
|
||||||
}
|
}
|
||||||
|
|
@ -217,14 +217,23 @@
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
};
|
};
|
||||||
|
|
||||||
SideBySidePrinter.prototype.generateSingleLineHtml = function(type, number, content, prefix) {
|
SideBySidePrinter.prototype.generateSingleLineHtml = function(isCombined, type, number, content, possiblePrefix) {
|
||||||
|
var lineWithoutPrefix = content;
|
||||||
|
var prefix = possiblePrefix;
|
||||||
|
|
||||||
|
if (!prefix) {
|
||||||
|
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
|
||||||
|
prefix = lineWithPrefix.prefix;
|
||||||
|
lineWithoutPrefix = lineWithPrefix.line;
|
||||||
|
}
|
||||||
|
|
||||||
return hoganUtils.render(genericTemplatesPath, 'line',
|
return hoganUtils.render(genericTemplatesPath, 'line',
|
||||||
{
|
{
|
||||||
type: type,
|
type: type,
|
||||||
lineClass: 'd2h-code-side-linenumber',
|
lineClass: 'd2h-code-side-linenumber',
|
||||||
contentClass: 'd2h-code-side-line',
|
contentClass: 'd2h-code-side-line',
|
||||||
prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix),
|
prefix: prefix,
|
||||||
content: content && utils.convertWhiteSpaceToNonBreakingSpace(content),
|
content: lineWithoutPrefix,
|
||||||
lineNumber: number
|
lineNumber: number
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@
|
||||||
display: -ms-flexbox;
|
display: -ms-flexbox;
|
||||||
display: flex;
|
display: flex;
|
||||||
-webkit-box-align: center;
|
-webkit-box-align: center;
|
||||||
-ms-flex-align: center;
|
-ms-flex-align: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
|
@ -98,18 +98,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-line {
|
.d2h-code-line {
|
||||||
display: block;
|
display: inline-block;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin-left: 80px;
|
margin-left: 80px;
|
||||||
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-side-line {
|
.d2h-code-side-line {
|
||||||
display: block;
|
display: inline-block;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
height: 18px;
|
height: 20px;
|
||||||
line-height: 18px;
|
line-height: 20px;
|
||||||
margin-left: 50px;
|
margin-left: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,17 +131,23 @@
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
background-color: #97f295;
|
background-color: #97f295;
|
||||||
border-radius: 0.2em;
|
border-radius: 0.2em;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-line-prefix {
|
.d2h-code-line-prefix {
|
||||||
float: left;
|
display: inline;
|
||||||
background: none;
|
background: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
word-wrap: normal;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-line-ctn {
|
.d2h-code-line-ctn {
|
||||||
|
display: inline;
|
||||||
background: none;
|
background: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
word-wrap: normal;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
.line-num1 {
|
.line-num1 {
|
||||||
|
|
@ -353,7 +361,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.selecting-left .d2h-code-line::-moz-selection,
|
.selecting-left .d2h-code-line::-moz-selection,
|
||||||
.selecting-left .d2h-code-line *::-moz-selection
|
.selecting-left .d2h-code-line *::-moz-selection,
|
||||||
.selecting-right td.d2h-code-linenumber::-moz-selection,
|
.selecting-right td.d2h-code-linenumber::-moz-selection,
|
||||||
.selecting-left .d2h-code-side-line::-moz-selection,
|
.selecting-left .d2h-code-side-line::-moz-selection,
|
||||||
.selecting-left .d2h-code-side-line *::-moz-selection,
|
.selecting-left .d2h-code-side-line *::-moz-selection,
|
||||||
|
|
@ -363,7 +371,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.selecting-left .d2h-code-line::selection,
|
.selecting-left .d2h-code-line::selection,
|
||||||
.selecting-left .d2h-code-line *::selection
|
.selecting-left .d2h-code-line *::selection,
|
||||||
.selecting-right td.d2h-code-linenumber::selection,
|
.selecting-right td.d2h-code-linenumber::selection,
|
||||||
.selecting-left .d2h-code-side-line::selection,
|
.selecting-left .d2h-code-side-line::selection,
|
||||||
.selecting-left .d2h-code-side-line *::selection,
|
.selecting-left .d2h-code-side-line *::selection,
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,6 @@
|
||||||
function Utils() {
|
function Utils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.prototype.convertWhiteSpaceToNonBreakingSpace = function(str) {
|
|
||||||
return str.slice(0).replace(/ /g, ' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
Utils.prototype.escape = function(str) {
|
Utils.prototype.escape = function(str) {
|
||||||
return str.slice(0)
|
return str.slice(0)
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ describe('LineByLinePrinter', function() {
|
||||||
|
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var lineByLinePrinter = new LineByLinePrinter({});
|
var lineByLinePrinter = new LineByLinePrinter({});
|
||||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
var fileHtml = lineByLinePrinter.makeLineHtml(false,
|
||||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', 'test');
|
diffParser.LINE_TYPE.INSERTS, '', 30, 'test', '+');
|
||||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||||
|
|
@ -36,8 +36,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-prefix">test</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
' <span class="d2h-code-line-ctn">test</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -48,8 +48,8 @@ describe('LineByLinePrinter', function() {
|
||||||
it('should work for deletions', function() {
|
it('should work for deletions', function() {
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var lineByLinePrinter = new LineByLinePrinter({});
|
var lineByLinePrinter = new LineByLinePrinter({});
|
||||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
var fileHtml = lineByLinePrinter.makeLineHtml(false,
|
||||||
diffParser.LINE_TYPE.DELETES, 30, '', '-', 'test');
|
diffParser.LINE_TYPE.DELETES, 30, '', 'test', '-');
|
||||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-del">\n' +
|
' <td class="d2h-code-linenumber d2h-del">\n' +
|
||||||
|
|
@ -58,8 +58,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-del">\n' +
|
' <td class="d2h-del">\n' +
|
||||||
' <div class="d2h-code-line d2h-del">\n' +
|
' <div class="d2h-code-line d2h-del">\n' +
|
||||||
' <span class="d2h-code-line-prefix">test</span>\n' +
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">-</span>\n' +
|
' <span class="d2h-code-line-ctn">test</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -70,8 +70,8 @@ describe('LineByLinePrinter', function() {
|
||||||
it('should convert indents into non breakin spaces (2 white spaces)', function() {
|
it('should convert indents into non breakin spaces (2 white spaces)', function() {
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var lineByLinePrinter = new LineByLinePrinter({});
|
var lineByLinePrinter = new LineByLinePrinter({});
|
||||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
var fileHtml = lineByLinePrinter.makeLineHtml(false,
|
||||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
|
diffParser.LINE_TYPE.INSERTS, '', 30, ' test', '+');
|
||||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||||
|
|
@ -80,8 +80,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-prefix"> test</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
' <span class="d2h-code-line-ctn"> test</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -92,8 +92,8 @@ describe('LineByLinePrinter', function() {
|
||||||
it('should convert indents into non breakin spaces (4 white spaces)', function() {
|
it('should convert indents into non breakin spaces (4 white spaces)', function() {
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var lineByLinePrinter = new LineByLinePrinter({});
|
var lineByLinePrinter = new LineByLinePrinter({});
|
||||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
var fileHtml = lineByLinePrinter.makeLineHtml(false,
|
||||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
|
diffParser.LINE_TYPE.INSERTS, '', 30, ' test', '+');
|
||||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||||
|
|
@ -102,8 +102,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-prefix"> test</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
' <span class="d2h-code-line-ctn"> test</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -114,8 +114,8 @@ describe('LineByLinePrinter', function() {
|
||||||
it('should convert indents into non breakin spaces (one tab)', function() {
|
it('should convert indents into non breakin spaces (one tab)', function() {
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var lineByLinePrinter = new LineByLinePrinter({});
|
var lineByLinePrinter = new LineByLinePrinter({});
|
||||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
var fileHtml = lineByLinePrinter.makeLineHtml(false,
|
||||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', Utils.escape('\ttest'));
|
diffParser.LINE_TYPE.INSERTS, '', 30, Utils.escape('\ttest'), '+');
|
||||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||||
|
|
@ -125,8 +125,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-prefix"> test</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
' <span class="d2h-code-line-ctn"> test</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -452,7 +452,7 @@ describe('LineByLinePrinter', function() {
|
||||||
newNumber: 1
|
newNumber: 1
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var html = lineByLinePrinter._processLines(oldLines, newLines);
|
var html = lineByLinePrinter._processLines(false, oldLines, newLines);
|
||||||
|
|
||||||
var expected =
|
var expected =
|
||||||
'<tr>\n' +
|
'<tr>\n' +
|
||||||
|
|
@ -462,7 +462,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-del">\n' +
|
' <td class="d2h-del">\n' +
|
||||||
' <div class="d2h-code-line d2h-del">\n' +
|
' <div class="d2h-code-line d2h-del">\n' +
|
||||||
' <span class="d2h-code-line-ctn">-test</span>\n' +
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
||||||
|
' <span class="d2h-code-line-ctn">test</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr><tr>\n' +
|
'</tr><tr>\n' +
|
||||||
|
|
@ -472,7 +473,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-ctn">+test1r</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
|
' <span class="d2h-code-line-ctn">test1r</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -540,7 +542,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-cntx">\n' +
|
' <td class="d2h-cntx">\n' +
|
||||||
' <div class="d2h-code-line d2h-cntx">\n' +
|
' <div class="d2h-code-line d2h-cntx">\n' +
|
||||||
' <span class="d2h-code-line-ctn"> one context line</span>\n' +
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
||||||
|
' <span class="d2h-code-line-ctn">one context line</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr><tr>\n' +
|
'</tr><tr>\n' +
|
||||||
|
|
@ -572,7 +575,8 @@ describe('LineByLinePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-line d2h-ins">\n' +
|
' <div class="d2h-code-line d2h-ins">\n' +
|
||||||
' <span class="d2h-code-line-ctn">+test2r</span>\n' +
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
||||||
|
' <span class="d2h-code-line-ctn">test2r</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ describe('SideBySidePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-cntx">\n' +
|
' <td class="d2h-cntx">\n' +
|
||||||
' <div class="d2h-code-side-line d2h-cntx">\n' +
|
' <div class="d2h-code-side-line d2h-cntx">\n' +
|
||||||
' <span class="d2h-code-line-prefix"> </span>\n' +
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">context</span>\n' +
|
' <span class="d2h-code-line-ctn">context</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
|
|
@ -120,7 +120,7 @@ describe('SideBySidePrinter', function() {
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-cntx">\n' +
|
' <td class="d2h-cntx">\n' +
|
||||||
' <div class="d2h-code-side-line d2h-cntx">\n' +
|
' <div class="d2h-code-side-line d2h-cntx">\n' +
|
||||||
' <span class="d2h-code-line-prefix"> </span>\n' +
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
||||||
' <span class="d2h-code-line-ctn">context</span>\n' +
|
' <span class="d2h-code-line-ctn">context</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
|
|
@ -141,7 +141,7 @@ describe('SideBySidePrinter', function() {
|
||||||
' <td class="d2h-ins">\n' +
|
' <td class="d2h-ins">\n' +
|
||||||
' <div class="d2h-code-side-line d2h-ins">\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">another added</span>\n' +
|
' <span class="d2h-code-line-ctn">another added</span>\n' +
|
||||||
' </div>\n' +
|
' </div>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>';
|
'</tr>';
|
||||||
|
|
@ -156,7 +156,7 @@ describe('SideBySidePrinter', function() {
|
||||||
|
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var sideBySidePrinter = new SideBySidePrinter({});
|
var sideBySidePrinter = new SideBySidePrinter({});
|
||||||
var fileHtml = sideBySidePrinter.generateSingleLineHtml(
|
var fileHtml = sideBySidePrinter.generateSingleLineHtml(false,
|
||||||
diffParser.LINE_TYPE.INSERTS, 30, 'test', '+');
|
diffParser.LINE_TYPE.INSERTS, 30, 'test', '+');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
||||||
|
|
@ -176,7 +176,7 @@ describe('SideBySidePrinter', function() {
|
||||||
|
|
||||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
var sideBySidePrinter = new SideBySidePrinter({});
|
var sideBySidePrinter = new SideBySidePrinter({});
|
||||||
var fileHtml = sideBySidePrinter.generateSingleLineHtml(
|
var fileHtml = sideBySidePrinter.generateSingleLineHtml(false,
|
||||||
diffParser.LINE_TYPE.DELETES, 30, 'test', '-');
|
diffParser.LINE_TYPE.DELETES, 30, 'test', '-');
|
||||||
var expected = '<tr>\n' +
|
var expected = '<tr>\n' +
|
||||||
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
||||||
|
|
@ -366,7 +366,7 @@ describe('SideBySidePrinter', function() {
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var sideBySidePrinter = new SideBySidePrinter({matching: 'lines'});
|
var sideBySidePrinter = new SideBySidePrinter({matching: 'lines'});
|
||||||
var html = sideBySidePrinter.processLines(oldLines, newLines);
|
var html = sideBySidePrinter.processLines(false, oldLines, newLines);
|
||||||
var expectedLeft =
|
var expectedLeft =
|
||||||
'<tr>\n' +
|
'<tr>\n' +
|
||||||
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,4 @@ describe('Utils', function() {
|
||||||
assert.equal(expected, result);
|
assert.equal(expected, result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('convertWhiteSpaceToNonBreakingSpace', function() {
|
|
||||||
it('should escape 1 whitespaces with ', function() {
|
|
||||||
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
|
|
||||||
assert.equal(' ', result);
|
|
||||||
});
|
|
||||||
it('should escape 2 whitespaces with ', function() {
|
|
||||||
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
|
|
||||||
assert.equal(' ', result);
|
|
||||||
});
|
|
||||||
it('should escape 4 whitespaces with ', function() {
|
|
||||||
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
|
|
||||||
assert.equal(' ', result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue