Javascript 通过文本/字符串反应本机生成组件

Javascript 通过文本/字符串反应本机生成组件,javascript,regex,reactjs,react-native,Javascript,Regex,Reactjs,React Native,我是使用React Native编程的新手。我想问,有没有最好的方法通过字符串/文本呈现react本机组件 例如,字符串故事: var story = "You face the bear please select your action: [[Choices]] [[Choice, Section="1"]] Fight using the sword [[Choice]] [[Choice, Section="1"]] Use the torch [[Choice]] [[Choice

我是使用React Native编程的新手。我想问,有没有最好的方法通过字符串/文本呈现react本机组件

例如,字符串故事:

var story = "You face the bear please select your action:
[[Choices]]  
[[Choice, Section="1"]] Fight using the sword [[Choice]]
[[Choice, Section="1"]] Use the torch [[Choice]]
[[Choice, Section="2"]] Run Away [[Choice]]
[[Choices]]";
使用此字符串,生成的组件为:

<Text>You face the bear please select your action</Text>
<View>
    <Button title="Fight using the sword" onPress={() => this.goToSection("1")}/>
    <Button title="Use the torch" onPress={() => this.goToSection("1")}/>
    <Button title="Run Away" onPress={() => this.goToSection("2")}/>
</View>
你面对熊,请选择你的行动
this.goToSection(“1”)}/>
this.goToSection(“1”)}/>
this.goToSection(“2”)}/>
我需要的方式转换用户输入(文本),并自动生成从他们的看法。
谢谢。

您对<代码>故事的结构是否有意见?把它变成一个对象/数组会容易得多。故事成分的顺序可以不同,例如:可以是选项,选项,然后是文本。但是,
[[Choices]]
标记后面必须至少有一个
[[Choice]]]
标记并成为
。你能举个例子把它做成一个对象/数组吗?我会有这样的东西:
{title:'你面对熊,请选择你的动作:',选项:[{section:1,title:'用剑战斗'},{section:2,title:'用火炬'}]
-这是可能的吗?我的要求是创建自定义文本编辑器,供用户用于输入故事。自定义文本编辑器必须能够将特定标记转换为React本机组件(如stackoverflow格式化示例
这将成为代码
)。如果我将其转换为对象/数组,我认为这必须是两倍的工作,因为我必须将字符串转换为对象,然后从对象渲染视图。是否有更简单且性能良好的方法将字符串转换为视图组件?或者有另一种方法,如react native library for text editor,但可以自定义?