Javascript 如何在react native中解析html
因此,我有以下格式的html字符串:Javascript 如何在react native中解析html,javascript,html,react-native,Javascript,Html,React Native,因此,我有以下格式的html字符串: Our society reflects, and is a reflection of, the <del>individual</del><add>person</add> (you and I) , and the <del>individual</del><add>person</add> is a <del>reflection</de
Our society reflects, and is a reflection of, the <del>individual</del><add>person</add> (you and I) , and the <del>individual</del><add>person</add> is a <del>reflection</del><add>manifestation</add> of society (hologram/holon ).
但是在react native中,我发现
找不到变量:document
,似乎我需要一个web视图来执行此操作。是否有其他方法可以解析此字符串?如果文本中没有嵌套节点或
s,则快速而肮脏的解决方案是匹配以标记开头、以该标记结尾或不包含标记的子字符串:
const str=`我们的社会反映了个人(你和我),也是个人的反映,个人是社会的反映(全息图/全息图);
console.log(str.match(/[^\如果文本中没有嵌套节点,也没有
s,那么一个快速而肮脏的解决方案将是匹配以标记开头、以该标记结尾或不包含标记的子字符串:
const str=`我们的社会反映了个人(你和我),也是个人的反映,个人是社会的反映(全息图/全息图);
console.log(str.match(/[^\您在这里有几个选项,就像您提到的,您可以使用这样的WebView:
<WebView source={{html:"your_html_string"}} />
您也可以使用如下npm包:
或者您可以自己解析字符串,并使用
元素将其转换为JSX标记
import { Text } from 'react-native';
import React, { Component } from 'react';
class del extends Text {
render() {
return (
<Text style={{textDecoration:'line-through'}} ...this.props>{super.render()}</Text>
)
}
}
class add extends Text {
render() {
return (
<Text style={{textDecoration:'underline line-through'}} ...this.props>{super.render()}</Text>
)
}
}
export default MyScreen extends Component {
render() {
return (
<Text>"Our society reflects, and is a reflection of, the"
<del>"individual"</del>
<add>"person"</add>
"(you and I) , and the"
<del>"individual"</del>
<add>"person"</add>
"is a "
<del>"reflection"</del>
<add>"manifestation"</add>
"of society (hologram/holon )."
</Text>
)
}
}
从'react native'导入{Text};
从“React”导入React,{Component};
类del扩展文本{
render(){
返回(
{super.render()}
)
}
}
类添加扩展文本{
render(){
返回(
{super.render()}
)
}
}
导出默认MyScreen扩展组件{
render(){
返回(
“我们的社会反映并反映了
“个人”
“人”
(你和我),以及
“个人”
“人”
“是一个”
“反思”
“表现”
“社会(全息图/全息图)。”
)
}
}
您在这里有几个选项,就像您提到的,您可以使用这样的WebView:
<WebView source={{html:"your_html_string"}} />
您也可以使用如下npm包:
或者您可以自己解析字符串,并使用
元素将其转换为JSX标记
import { Text } from 'react-native';
import React, { Component } from 'react';
class del extends Text {
render() {
return (
<Text style={{textDecoration:'line-through'}} ...this.props>{super.render()}</Text>
)
}
}
class add extends Text {
render() {
return (
<Text style={{textDecoration:'underline line-through'}} ...this.props>{super.render()}</Text>
)
}
}
export default MyScreen extends Component {
render() {
return (
<Text>"Our society reflects, and is a reflection of, the"
<del>"individual"</del>
<add>"person"</add>
"(you and I) , and the"
<del>"individual"</del>
<add>"person"</add>
"is a "
<del>"reflection"</del>
<add>"manifestation"</add>
"of society (hologram/holon )."
</Text>
)
}
}
从'react native'导入{Text};
从“React”导入React,{Component};
类del扩展文本{
render(){
返回(
{super.render()}
)
}
}
类添加扩展文本{
render(){
返回(
{super.render()}
)
}
}
导出默认MyScreen扩展组件{
render(){
返回(
“我们的社会反映并反映了
“个人”
“人”
(你和我),以及
“个人”
“人”
“是一个”
“反思”
“表现”
“社会(全息图/全息图)。”
)
}
}