html-to-vdom
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -61,7 +61,9 @@ var decode = require('ent').decode; | ||
convert: function (node, getVNodeKey) { | ||
if (node.type === 'tag') { | ||
if (node.type === 'tag' || node.type === 'script' || node.type === 'style') { | ||
return converter.convertTag(node, getVNodeKey); | ||
} | ||
else if (node.type === 'text') { | ||
} else if (node.type === 'text') { | ||
return new VText(decode(node.data)); | ||
} else { | ||
// converting an unsupported node, return an empty text node instead. | ||
return new VText(''); | ||
} | ||
@@ -68,0 +70,0 @@ }, |
{ | ||
"name": "html-to-vdom", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "Converts html into a vtree", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -75,1 +75,2 @@ html-to-vdom [![Build Status](https://travis-ci.org/TimBeyer/html-to-vdom.svg?branch=master)](https://travis-ci.org/TimBeyer/html-to-vdom) | ||
* [@bregenspan](https://github.com/bregenspan) for making the dataset conversion standards-compliant | ||
* [@jesseditson](https://github.com/jesseditson) for adding `<script>` and `<style>` tag support |
@@ -303,2 +303,57 @@ var VNode = require('virtual-dom/vnode/vnode'); | ||
}); | ||
describe('when converting HTML containing a script tag', function () { | ||
it('converts to a virtualdom node', function () { | ||
var html = '<div><script src="foo.js">alert("bar!");</script></div>'; | ||
var converted = convertHTML(html); | ||
var script = converted.children[0]; | ||
should.exist(script); | ||
script.tagName.should.eql('script'); | ||
script.children.length.should.eql(1); | ||
script.children[0].text.should.eql('alert("bar!");'); | ||
}); | ||
}); | ||
describe('when converting HTML containing a style tag', function () { | ||
it('converts to a virtualdom node', function () { | ||
var html = '<div><style>h1 {color:red;} p {color:blue;} </style></div>'; | ||
var converted = convertHTML(html); | ||
var script = converted.children[0]; | ||
should.exist(script); | ||
script.tagName.should.eql('style'); | ||
script.children.length.should.eql(1); | ||
script.children[0].text.should.eql('h1 {color:red;} p {color:blue;} '); | ||
}); | ||
}); | ||
describe('when converting HTML containing CDATA', function () { | ||
it('returns an empty string instead (cdata is unsupported)', function () { | ||
var html = '<![CDATA[ Within this Character Data block I can\ | ||
use double dashes as much as I want (along with <, &, \', and ")\ | ||
*and* %MyParamEntity; will be expanded to the text\ | ||
"Has been expanded" ... however, I can\'t use\ | ||
the CEND sequence (if I need to use it I must escape one of the\ | ||
brackets or the greater-than sign).\ | ||
]]>'; | ||
var converted = convertHTML(html); | ||
converted.text.should.eql(''); | ||
}); | ||
}); | ||
describe('when converting HTML containing a directive', function () { | ||
it('returns an empty string instead (directives are unsupported)', function () { | ||
var html = '<!DOCTYPE html>'; | ||
var converted = convertHTML(html); | ||
converted.text.should.eql(''); | ||
}); | ||
}); | ||
describe('when converting HTML containing a comment', function () { | ||
it('returns an empty string instead (comments are unsupported)', function () { | ||
var html = '<div><!-- some comment --></div>'; | ||
var converted = convertHTML(html); | ||
var comment = converted.children[0]; | ||
comment.text.should.eql(''); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26255
14
418
76