Can replaceWith
have typesAfter
param if it causes a split?
I am using replaceWith(fromBeforeLeftWord, toAfterRightWord, [ leftWord, wrapper, label, rightWord ])
but this doesnt allow me to change the attrs on the spit paragraph node. The replaceWith replaces the words to the left and right in order to trim and add punctuation, But also needs to set the paragraph id and create a nodeView with the same id.
Is there a way to use split and insert a nodeView node at the same time so the transform matches the schema? Without causing InvalidContent
for node type error.
Schema
new Schema({
nodes: {
doc: {
content: 'block+',
selectable: false,
atom: true,
},
wrapper: {
atom: true,
defining: true,
group: 'block',
selectable: false,
content: 'label paragraph',
toDOM: () => ['div', { class: 'wrapper' }, 0],
},
paragraph: {
group: 'para',
atom: true,
defining: true,
selectable: false,
attrs: {
id: { default: 'undefined-para-id' },
},
content: 'text*',
marks: '_',
toDOM: () => [
'p',
{
class: 'paragraph',
style: 'white-space: pre-wrap;',
},
0,
],
},
label: { <--- This is a nodeView
group: 'para',
selectable: false,
attrs: {
paragraphId: { default: null },
},
toDOM: () => ['span'],
},
}
})
The desired output would be:
Before:
<doc>
<div class="wrapper" >
<nodeView id="id1" />
<p id="id1" ><mark id="1.1">Some</mark> <mark id="1.2">text</mark></p>
</div>
</doc>
After: (newId)
<doc>
<div class="wrapper" >
<nodeView id="id1" />
<p id="id1" class="paragraph" ><mark id="1.1">Some</mark></p>
</div>
<div class="wrapper" >
<nodeView id="newId" />
<p id="newId" class="paragraph" ><mark id="2.1">text</mark></p>
</div>
</doc>
Thoughts so far:
The markup I would be inserting as the split would be
<mark id="1.1">/word<mark>
</p>
</div>
<div class="wrapper">
<nodeView id='newId' />
<p id='newId' class='paragraph'>
<mark id="2.1">/word<mark>
Is this a Fragment? If so, how do you create a fragment like this from your schema?
Thanks for any help.