zpin-templates
Advanced tools
Comparing version 0.0.28 to 0.0.29
@@ -9,3 +9,2 @@ 'use strict'; | ||
var escodegen = require('escodegen'); | ||
var parse5 = require('parse5'); | ||
var reactDOMSupport = require('./reactDOMSupport'); | ||
@@ -65,2 +64,3 @@ var reactNativeSupport = require('./reactNativeSupport'); | ||
var htmlNode = "rt-html"; | ||
var htmlNodeIndex = 0; | ||
/** | ||
@@ -157,3 +157,3 @@ * @param {Options} options | ||
var functionBody = 'return ' + convertHtmlToReact(templateProp.content, context); | ||
var functionBody = 'return ' + convertHtmlToReact(templateProp.content, context, html); | ||
context.boundParams = oldBoundParams; | ||
@@ -349,3 +349,4 @@ | ||
*/ | ||
function convertHtmlToReact(node, context, resourcePath) { | ||
function convertHtmlToReact(node, context, resourcePath, html) { | ||
// console.log("convertHtmlToReact",html) | ||
//解决rt不支持script标签 | ||
@@ -487,3 +488,3 @@ if (node.type == "script") { | ||
var children = _.map(node.children, function (child) { | ||
var code = convertHtmlToReact(child, context, resourcePath); | ||
var code = convertHtmlToReact(child, context, resourcePath, html); | ||
validateJS(code, child, context); | ||
@@ -499,5 +500,7 @@ return code; | ||
} else if (node.name === htmlNode) { | ||
// let $ = cheerio.load(node); | ||
console.log(node, parse5.serialize(node)); | ||
data.body = '[React.createElement(\'div\',{dangerouslySetInnerHTML:{__html: \'<p id="Test">html</p>\'}})]'; | ||
var $ = cheerio.load(html); | ||
// console.log($('rt-html').eq(htmlNodeIndex).html,htmlNodeIndex) | ||
var innerHtml = $('rt-html').eq(htmlNodeIndex++).html().replace(/[\r\n]/g, '').trim(); | ||
console.log(node, innerHtml); | ||
data.body = '[React.createElement(\'div\',{dangerouslySetInnerHTML:{__html:\'' + innerHtml + '\'}})]'; | ||
console.log(data.body, _typeof(data.body)); | ||
@@ -651,2 +654,3 @@ } else { | ||
function convertTemplateToReact(html, options, resourcePath) { | ||
htmlNodeIndex = 0; | ||
var context = require('./context'); | ||
@@ -663,2 +667,3 @@ return convertRT(html, context, options, resourcePath); | ||
}); | ||
utils.validate(context.options, context, context.reportContext, rootNode.root()[0]); | ||
@@ -720,3 +725,3 @@ var rootTags = _.filter(rootNode.root()[0].children, { type: 'tag' }); | ||
} | ||
return convertHtmlToReact(firstTag, context, resourcePath); | ||
return convertHtmlToReact(firstTag, context, resourcePath, html); | ||
} | ||
@@ -732,3 +737,2 @@ | ||
options = getOptions(options); | ||
var context = defaultContext(html, options, reportContext); | ||
@@ -735,0 +739,0 @@ var body = parseAndConvertHtmlToReact(html, context, resourcePath); |
{ | ||
"name": "zpin-templates", | ||
"version": "0.0.28", | ||
"version": "0.0.29", | ||
"description": "Light weight templates for react -> write html get valid react code", | ||
@@ -42,3 +42,2 @@ "main": "index.js", | ||
"optionator": "^0.8.2", | ||
"parse5": "^3.0.1", | ||
"text-table": "^0.2.0" | ||
@@ -45,0 +44,0 @@ }, |
@@ -6,3 +6,2 @@ 'use strict'; | ||
const escodegen = require('escodegen'); | ||
const parse5 = require('parse5'); | ||
const reactDOMSupport = require('./reactDOMSupport'); | ||
@@ -73,2 +72,3 @@ const reactNativeSupport = require('./reactNativeSupport'); | ||
const htmlNode="rt-html"; | ||
let htmlNodeIndex=0; | ||
/** | ||
@@ -171,3 +171,3 @@ * @param {Options} options | ||
const functionBody = 'return ' + convertHtmlToReact(templateProp.content, context); | ||
const functionBody = 'return ' + convertHtmlToReact(templateProp.content, context,html); | ||
context.boundParams = oldBoundParams; | ||
@@ -366,3 +366,4 @@ | ||
*/ | ||
function convertHtmlToReact(node, context,resourcePath) { | ||
function convertHtmlToReact(node, context,resourcePath,html) { | ||
// console.log("convertHtmlToReact",html) | ||
//解决rt不支持script标签 | ||
@@ -502,3 +503,3 @@ if(node.type=="script"){ | ||
const children = _.map(node.children, child => { | ||
const code = convertHtmlToReact(child, context,resourcePath); | ||
const code = convertHtmlToReact(child, context,resourcePath,html); | ||
validateJS(code, child, context); | ||
@@ -513,5 +514,7 @@ return code; | ||
}else if(node.name === htmlNode){ | ||
// let $ = cheerio.load(node); | ||
console.log(node,parse5.serialize(node)); | ||
data.body = `[React.createElement('div',{dangerouslySetInnerHTML:{__html: '<p id="Test">html</p>'}})]`; | ||
let $ = cheerio.load(html); | ||
// console.log($('rt-html').eq(htmlNodeIndex).html,htmlNodeIndex) | ||
let innerHtml=$('rt-html').eq(htmlNodeIndex++).html().replace(/[\r\n]/g,'').trim(); | ||
console.log(node,innerHtml) | ||
data.body = `[React.createElement('div',{dangerouslySetInnerHTML:{__html:'${innerHtml}'}})]`; | ||
console.log(data.body,typeof data.body) | ||
@@ -657,2 +660,3 @@ } else { | ||
function convertTemplateToReact(html, options,resourcePath) { | ||
htmlNodeIndex=0; | ||
const context = require('./context'); | ||
@@ -669,2 +673,3 @@ return convertRT(html, context, options,resourcePath); | ||
}); | ||
utils.validate(context.options, context, context.reportContext, rootNode.root()[0]); | ||
@@ -727,3 +732,3 @@ let rootTags = _.filter(rootNode.root()[0].children, {type: 'tag'}); | ||
} | ||
return convertHtmlToReact(firstTag, context,resourcePath); | ||
return convertHtmlToReact(firstTag, context,resourcePath,html); | ||
} | ||
@@ -739,3 +744,2 @@ | ||
options = getOptions(options); | ||
const context = defaultContext(html, options, reportContext); | ||
@@ -742,0 +746,0 @@ const body = parseAndConvertHtmlToReact(html, context,resourcePath); |
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
279286
10
3745
- Removedparse5@^3.0.1
- Removed@types/node@22.5.5(transitive)
- Removedparse5@3.0.3(transitive)
- Removedundici-types@6.19.8(transitive)