From 5967b0a337ed416882d5e26ccc5df7b470b30b73 Mon Sep 17 00:00:00 2001 From: Andrew Delpha Date: Tue, 17 Jan 2017 14:11:08 -0600 Subject: [PATCH] Added fix for outputting style elements. The content of the style element was being escaped like a text node when it should be special cased (as script tags were). --- index.js | 4 +++- test/test.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2115542..0a40cf0 100644 --- a/index.js +++ b/index.js @@ -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)); } diff --git a/test/test.js b/test/test.js index a44d41c..80a648a 100644 --- a/test/test.js +++ b/test/test.js @@ -77,6 +77,13 @@ describe('toHTML()', function () { assert.equal(toHTML(node), '
'); }); + it('should render style element correctly', function(){ + var node = new VNode('style',{},[ + new VText(".logo {background-image: url('/mylogo.png');}") + ]); + assert.equal(toHTML(node),""); + }); + it('should render data- attributes for dataset properties', function () { var node = new VNode('div', { dataset: {