I needed to divide the paragraph
into sections based on its entityRanges
.
Here is what the original paragraph looks like:
{
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'
}
}]
}
However, I was expecting the following results:
{
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.'
}]
}
I aimed to break down the text
into multiple segments based on its offset
& length
values.
For instance, in the given example, customer support
is the offset value.
Thus, it should be divided in the following sequence:
- Do you have questions or comments and do you wish to contact ABC? Please visit our
- customer support
- page.
All of the above segments need to be moved to a new object called embbeded
.