diff --git a/src/line-by-line-printer.js b/src/line-by-line-printer.js
index b575a0e..b40e2c7 100644
--- a/src/line-by-line-printer.js
+++ b/src/line-by-line-printer.js
@@ -25,6 +25,10 @@
return nunjucksEnv.render('file-diff.html', {'file': file, 'diffs': diffs});
};
+ LineByLinePrinter.prototype.makeLineByLineHtmlWrapper = function(content) {
+ return nunjucksEnv.render('wrapper.html', {'content': content});
+ };
+
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
var that = this;
var htmlDiffs = diffFiles.map(function(file) {
@@ -37,7 +41,7 @@
return that.makeFileDiffHtml(file, diffs);
});
- return '
\n' + htmlDiffs.join('\n') + '
\n';
+ return this.makeLineByLineHtmlWrapper(htmlDiffs.join('\n'));
};
var matcher = Rematch.rematch(function(a, b) {
diff --git a/src/templates/line-by-line/wrapper.html b/src/templates/line-by-line/wrapper.html
new file mode 100644
index 0000000..977d2bc
--- /dev/null
+++ b/src/templates/line-by-line/wrapper.html
@@ -0,0 +1,3 @@
+
+ {{ content }}
+
diff --git a/test/line-by-line-tests.js b/test/line-by-line-tests.js
index 01b7b29..52feef3 100644
--- a/test/line-by-line-tests.js
+++ b/test/line-by-line-tests.js
@@ -1,4 +1,5 @@
var assert = require('assert');
+var Utils = require('../src/utils.js').Utils;
var LineByLinePrinter = require('../src/line-by-line-printer.js').LineByLinePrinter;
@@ -62,6 +63,72 @@ describe('LineByLinePrinter', function() {
' \n' +
'\n';
+ assert.equal(expected, fileHtml);
+ });
+ it('should convert indents into non breakin spaces (2 white spaces)', function() {
+
+ var diffParser = require('../src/diff-parser.js').DiffParser;
+ var lineByLinePrinter = new LineByLinePrinter({});
+ var fileHtml = lineByLinePrinter.makeLineHtml(
+ diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
+ fileHtml = fileHtml.replace(/\n\n+/g, '\n');
+ var expected = '\n' +
+ ' | \n' +
+ ' \n' +
+ ' 30 \n' +
+ ' | \n' +
+ ' \n' +
+ ' \n' +
+ ' test\n' +
+ ' +\n' +
+ ' \n' +
+ ' | \n' +
+ '
\n';
+
+ assert.equal(expected, fileHtml);
+ });
+ it('should convert indents into non breakin spaces (4 white spaces)', function() {
+
+ var diffParser = require('../src/diff-parser.js').DiffParser;
+ var lineByLinePrinter = new LineByLinePrinter({});
+ var fileHtml = lineByLinePrinter.makeLineHtml(
+ diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
+ fileHtml = fileHtml.replace(/\n\n+/g, '\n');
+ var expected = '\n' +
+ ' | \n' +
+ ' \n' +
+ ' 30 \n' +
+ ' | \n' +
+ ' \n' +
+ ' \n' +
+ ' test\n' +
+ ' +\n' +
+ ' \n' +
+ ' | \n' +
+ '
\n';
+
+ assert.equal(expected, fileHtml);
+ });
+ it('should convert indents into non breakin spaces (one tab)', function() {
+
+ var diffParser = require('../src/diff-parser.js').DiffParser;
+ var lineByLinePrinter = new LineByLinePrinter({});
+ var fileHtml = lineByLinePrinter.makeLineHtml(
+ diffParser.LINE_TYPE.INSERTS, '', 30, '+', Utils.escape('\ttest'));
+ fileHtml = fileHtml.replace(/\n\n+/g, '\n');
+ var expected = '\n' +
+ ' | \n' +
+ ' \n' +
+ ' 30 \n' +
+ ' | \n' +
+ ' \n' +
+ ' \n' +
+ ' test\n' +
+ ' +\n' +
+ ' \n' +
+ ' | \n' +
+ '
\n';
+
assert.equal(expected, fileHtml);
});
});
diff --git a/test/utils-tests.js b/test/utils-tests.js
index 69f9ab5..aa2d944 100644
--- a/test/utils-tests.js
+++ b/test/utils-tests.js
@@ -22,4 +22,18 @@ describe('Utils', function() {
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);
+ });
+ });
});