diff --git a/lib/HtmlDiff.js b/lib/HtmlDiff.js index cb2ed74..7efa8af 100644 --- a/lib/HtmlDiff.js +++ b/lib/HtmlDiff.js @@ -10,9 +10,10 @@ var diff = require('diff'), * @param {String[]} [options.ignoreAttributes] * @param {String[]} [options.compareAttributesAsJSON] * @param {Boolean} [options.ignoreWhitespaces=true] - * @param {Boolean} [options.ignoreComments] + * @param {Boolean} [options.ignoreComments=true] * @param {Boolean} [options.ignoreEndTags=false] * @param {Boolean} [options.ignoreDuplicateAttributes=false] + * @param {Boolean} [options.ignoreSelfClosingSlash=false] */ var HtmlDiff = function (options) { this.options = defaults(options); diff --git a/lib/defaults.js b/lib/defaults.js index 3324635..fcaf507 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -14,6 +14,7 @@ var presets = { * @param {Boolean} [options.ignoreComments=true] * @param {Boolean} [options.ignoreEndTags=false] * @param {Boolean} [options.ignoreDuplicateAttributes=false] + * @param {Boolean} [options.ignoreSelfClosingSlash=false] * returns {Object} */ module.exports = function (options) { @@ -39,7 +40,8 @@ var presets = { ignoreComments: true, ignoreEndTags: false, - ignoreDuplicateAttributes: false + ignoreDuplicateAttributes: false, + ignoreSelfClosingSlash: false }); }; diff --git a/lib/index.js b/lib/index.js index e5f5d63..fd26e1a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,6 +25,7 @@ HtmlDiff.prototype.tokenize = function (html) { * @param {Boolean} [options.ignoreComments=true] * @param {Boolean} [options.ignoreEndTags=false] * @param {Boolean} [options.ignoreDuplicateAttributes=false] + * @param {Boolean} [options.ignoreSelfClosingSlash=false] */ var HtmlDiffer = function (options) { options = defaults(options); diff --git a/lib/utils/modify.js b/lib/utils/modify.js index 6789b34..28235d0 100644 --- a/lib/utils/modify.js +++ b/lib/utils/modify.js @@ -12,6 +12,7 @@ var SimpleApiParser = require('parse5').SimpleApiParser, * @param {Boolean} [options.ignoreComments=true] * @param {Boolean} [options.ignoreEndTags=false] * @param {Boolean} [options.ignoreDuplicateAttributes=false] + * @param {Boolean} [options.ignoreSelfClosingSlash=false] * returns {String} */ function modify(value, options) { @@ -36,6 +37,9 @@ function modify(value, options) { if (options.ignoreDuplicateAttributes) { attrs = utils.removeDuplicateAttributes(attrs); } + if (options.ignoreSelfClosingSlash) { + selfClosing = false; + } attrs = utils.sortAttrs(attrs) && utils.sortCssClasses(attrs) && diff --git a/test/differ/fixtures/first/strip-self-closing-slash.html b/test/differ/fixtures/first/strip-self-closing-slash.html new file mode 100644 index 0000000..09d5649 --- /dev/null +++ b/test/differ/fixtures/first/strip-self-closing-slash.html @@ -0,0 +1 @@ +
diff --git a/test/differ/fixtures/second/strip-self-closing-slash.html b/test/differ/fixtures/second/strip-self-closing-slash.html new file mode 100644 index 0000000..e123ba7 --- /dev/null +++ b/test/differ/fixtures/second/strip-self-closing-slash.html @@ -0,0 +1 @@ +
diff --git a/test/differ/isEqual.js b/test/differ/isEqual.js index d495cf5..fdb55d5 100644 --- a/test/differ/isEqual.js +++ b/test/differ/isEqual.js @@ -156,4 +156,11 @@ describe('\'isEqual\'', function () { htmlDiffer.isEqual(files.html1, files.html2).must.be.false(); }); + + it('must ignore self closing slash', function () { + var htmlDiffer = new HtmlDiffer({ ignoreSelfClosingSlash: true }), + files = readFiles('strip-self-closing-slash'); + + htmlDiffer.isEqual(files.html1, files.html2).must.be.true(); + }); });