Skip to content

Commit

Permalink
Add option for parser to keep comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Pulges committed Aug 8, 2014
1 parent 315fccb commit 4d481d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions parser_rules/advanced_unwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ var wysihtml5ParserRules = {
}
}
},

"comments": 1, // if set allows comments to pass

/**
* Tag list
Expand Down
8 changes: 7 additions & 1 deletion src/dom/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ wysihtml5.dom.parse = (function() {
*/
var NODE_TYPE_MAPPING = {
"1": _handleElement,
"3": _handleText
"3": _handleText,
"8": _handleComment
},
// Rename unknown tags to this
DEFAULT_NODE_NAME = "span",
Expand Down Expand Up @@ -593,6 +594,11 @@ wysihtml5.dom.parse = (function() {
}
}

function _handleComment(oldNode) {
if (currentRules.comments) {
return oldNode.ownerDocument.createComment(oldNode.nodeValue);
}
}

// ------------ attribute checks ------------ \\
var attributeCheckMethods = {
Expand Down
8 changes: 8 additions & 0 deletions test/dom/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,12 @@ if (wysihtml5.browser.supported()) {
this.equal(this.sanitize(tester, rules).innerHTML, input5 , "DIV with dimensions and in dom is kept");

});

test("Test keeping comments ", function() {
var rules = {
"comments": 1
},
input = 'Test <!-- some comment -->';
this.equal(this.sanitize(input, rules), input, "Comments are kept if configured to keep");
});
}

0 comments on commit 4d481d0

Please sign in to comment.