mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
support style tags - cheerio parses them as special section in the html
This commit is contained in:
parent
5015222f45
commit
36f1edfc1f
@ -57,7 +57,7 @@ _.forEach(reactSupportedAttributes, function (attributeReactName) {
|
|||||||
function concatChildren(children) {
|
function concatChildren(children) {
|
||||||
var res = '';
|
var res = '';
|
||||||
_.forEach(children, function (child) {
|
_.forEach(children, function (child) {
|
||||||
if (child.indexOf(' /*') !== 0 && child) {
|
if (child && child.indexOf(' /*') !== 0 ) {
|
||||||
res += ',' + child;
|
res += ',' + child;
|
||||||
} else {
|
} else {
|
||||||
res += child;
|
res += child;
|
||||||
@ -258,7 +258,7 @@ function hasNonSimpleChildren(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function convertHtmlToReact(node, context) {
|
function convertHtmlToReact(node, context) {
|
||||||
if (node.type === 'tag') {
|
if (node.type === 'tag' || node.type === 'style') {
|
||||||
context = {
|
context = {
|
||||||
boundParams: _.clone(context.boundParams),
|
boundParams: _.clone(context.boundParams),
|
||||||
injectedFunctions: context.injectedFunctions,
|
injectedFunctions: context.injectedFunctions,
|
||||||
@ -302,9 +302,9 @@ function convertHtmlToReact(node, context) {
|
|||||||
if (node.attribs[ifProp]) {
|
if (node.attribs[ifProp]) {
|
||||||
data.condition = node.attribs[ifProp].trim();
|
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);
|
return convertHtmlToReact(child, context);
|
||||||
}));
|
})) : '';
|
||||||
|
|
||||||
if (hasNonSimpleChildren(node)) {
|
if (hasNonSimpleChildren(node)) {
|
||||||
data.body = shouldUseCreateElement(context) ? tagTemplateCreateElement(data) : tagTemplate(data);
|
data.body = shouldUseCreateElement(context) ? tagTemplateCreateElement(data) : tagTemplate(data);
|
||||||
|
5
test/data/style.rt
Normal file
5
test/data/style.rt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<div>
|
||||||
|
<style>
|
||||||
|
{'.test {color:red}'}
|
||||||
|
</style>
|
||||||
|
</div>
|
1
test/data/style.rt.html
Normal file
1
test/data/style.rt.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<div><style>.test {color:red}</style></div>
|
@ -113,7 +113,7 @@ function normalizeHtml(html) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('html tests', function (t) {
|
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);
|
t.plan(files.length);
|
||||||
|
|
||||||
files.forEach(check);
|
files.forEach(check);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user