support style tags - cheerio parses them as special section in the html

This commit is contained in:
avim 2015-01-19 16:22:42 +02:00
parent 5015222f45
commit 36f1edfc1f
4 changed files with 11 additions and 5 deletions

View File

@ -57,7 +57,7 @@ _.forEach(reactSupportedAttributes, function (attributeReactName) {
function concatChildren(children) {
var res = '';
_.forEach(children, function (child) {
if (child.indexOf(' /*') !== 0 && child) {
if (child && child.indexOf(' /*') !== 0 ) {
res += ',' + child;
} else {
res += child;
@ -258,7 +258,7 @@ function hasNonSimpleChildren(node) {
}
function convertHtmlToReact(node, context) {
if (node.type === 'tag') {
if (node.type === 'tag' || node.type === 'style') {
context = {
boundParams: _.clone(context.boundParams),
injectedFunctions: context.injectedFunctions,
@ -302,9 +302,9 @@ function convertHtmlToReact(node, context) {
if (node.attribs[ifProp]) {
data.condition = node.attribs[ifProp].trim();
}
data.children = concatChildren(_.map(node.children, function (child) {
data.children = node.children ? concatChildren(_.map(node.children, function (child) {
return convertHtmlToReact(child, context);
}));
})) : '';
if (hasNonSimpleChildren(node)) {
data.body = shouldUseCreateElement(context) ? tagTemplateCreateElement(data) : tagTemplate(data);

5
test/data/style.rt Normal file
View File

@ -0,0 +1,5 @@
<div>
<style>
{'.test {color:red}'}
</style>
</div>

1
test/data/style.rt.html Normal file
View File

@ -0,0 +1 @@
<div><style>.test {color:red}</style></div>

View File

@ -113,7 +113,7 @@ function normalizeHtml(html) {
}
test('html tests', function (t) {
var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt','custom-element.rt'];
var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt'];
t.plan(files.length);
files.forEach(check);