【发布时间】:2019-10-08 17:21:14
【问题描述】:
我想根据entityRanges 分解paragraph。
所以实际的段落看起来像这样,
{
type: 'paragraph',
depth: 1,
text: 'Do you have questions or comments and do you wish to contact ABC? Please visit our customer support page.',
entityRanges: [{
type: 'LINK',
offset: 83,
length: 16,
data: {
target: '_self',
url: '/index.htm'
}
}]
}
但我的预期结果应该如下所示,
{
type: 'paragraph',
depth: 1,
text: 'Do you have questions or comments and do you wish to contact ABC? Please visit our customer support page.',
entityRanges: [{
type: 'LINK',
offset: 83,
length: 16,
data: {
target: '_self',
url: '/index.htm'
}
}],
embbeded: [{
type: 'text',
text: 'Do you have questions or comments and do you wish to contact ABC? Please visit our '
}, {
type: 'link',
text: 'customer support',
data: {
target: '_self',
url: '/index.htm'
}
}, {
type: 'text',
text: 'page.'
}]
}
我想根据 offset 和 length 的值将 text 分解为多个部分。
根据示例,customer support 是偏移值。
所以它应该按以下顺序分解
- 您有问题或需要联系 ABC 吗? 请访问我们的
- 客户支持
- 页面。
以上所有部分都需要推送到新对象embbeded。
【问题讨论】:
标签: javascript arrays typescript lodash