Skip to content

Commit

Permalink
Merge pull request #26 from lightman76/dont_escape_style_element_content
Browse files Browse the repository at this point in the history
Fix for problem outputting style elements
  • Loading branch information
ntharim committed Jan 22, 2017
2 parents 77b635e + 5967b0a commit 6398a95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -26,7 +26,9 @@ function toHTML(node, parent) {
if (isVNode(node)) {
return openTag(node) + tagContent(node) + closeTag(node);
} else if (isVText(node)) {
if (parent && parent.tagName.toLowerCase() === 'script') return String(node.text);
if (parent && (parent.tagName.toLowerCase() === 'script'
|| parent.tagName.toLowerCase() === 'style'))
return String(node.text);
return escape(String(node.text));
}

Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Expand Up @@ -77,6 +77,13 @@ describe('toHTML()', function () {
assert.equal(toHTML(node), '<div style="background: black; color: red; z-index: 1;"></div>');
});

it('should render style element correctly', function(){
var node = new VNode('style',{},[
new VText(".logo {background-image: url('/mylogo.png');}")
]);
assert.equal(toHTML(node),"<style>.logo {background-image: url('/mylogo.png');}</style>");
});

it('should render data- attributes for dataset properties', function () {
var node = new VNode('div', {
dataset: {
Expand Down

0 comments on commit 6398a95

Please sign in to comment.