Fix convert &nbps; to proper white spaces with white-space wrap

This commit is contained in:
Rodrigo Fernandes 2016-09-05 22:13:51 +01:00
parent 5303b2ff24
commit 6a47f8f3a5
No known key found for this signature in database
GPG key ID: 08E3C5F38969078E
8 changed files with 114 additions and 84 deletions

View file

@ -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
}); });
}; };

View file

@ -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;

View file

@ -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
}); });
}; };

View file

@ -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 {

View file

@ -9,10 +9,6 @@
function Utils() { function Utils() {
} }
Utils.prototype.convertWhiteSpaceToNonBreakingSpace = function(str) {
return str.slice(0).replace(/ /g, '&nbsp;');
};
Utils.prototype.escape = function(str) { Utils.prototype.escape = function(str) {
return str.slice(0) return str.slice(0)
.replace(/&/g, '&amp;') .replace(/&/g, '&amp;')

View file

@ -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">&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;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">&nbsp;one&nbsp;context&nbsp;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>';

View file

@ -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">&nbsp;</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">&nbsp;</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&nbsp;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' +

View file

@ -22,18 +22,4 @@ describe('Utils', function() {
assert.equal(expected, result); assert.equal(expected, result);
}); });
}); });
describe('convertWhiteSpaceToNonBreakingSpace', function() {
it('should escape 1 whitespaces with &nbsp;', function() {
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
assert.equal('&nbsp;', result);
});
it('should escape 2 whitespaces with &nbsp;', function() {
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
assert.equal('&nbsp;&nbsp;', result);
});
it('should escape 4 whitespaces with &nbsp;', function() {
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
assert.equal('&nbsp;&nbsp;&nbsp;&nbsp;', result);
});
});
}); });