rich-text 的nodes 该怎么书写
发布于 6 年前 作者 aqian 11248 次浏览 来自 问答

看了文档 一头雾水,需要一个 正确的 nodes 的 格式。

如:    小明 回复 煞笔:你在干什么?

*如果我不使用 html标签形式,直接通过 官方文档上 nodes 的编写格式该怎么写

nodes: [{
      name: 'div',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: red;'
      },
      children: [{
        type: 'text',
        text: 'Hello World!'
      }]
    }]

参照以上的 结构形式  该怎么写。

**反正我是按照文档描述没写出来,以下贴出我写的吧,跪求大佬指点。。。

nodes: [{
    name: 'div',
    attrs: {
      class: 'div_class',
      style: 'line-height: 60px; color: red;'
    },
    children: [{
      type: 'text',
      text: '小明',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: red;'
      }
    },
    {
      type:'text',
      text:'回复',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: black;'
      }
    },
    {
      type:'text',
      text:'煞笔',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: red;'
      }
    },
    {
      type:'text',
      text:'你在干什么',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: black;'
      }
    }
    ]
  }]
2 回复

可以使用下这个包,传入 html 字符串,自动解析成对应 nodes 节点

https://github.com/zhuping/octoparse2

回到顶部