I override update to convert all sequences like sometext to just bold text without asteriskes (like in Typora or HyperMD). The conversion is done, but when I enter any symbol right after convertion appeared, the source sequence returns. On a short videocast I show that (also with DOM model changes in chrome dev tools: https://screencast-o-matic.com/watch/cYlFiw84e6 . The source code from update provided below:
view.state.doc.descendants((node, pos) => {
if (node.type.name === 'text') {
nodeWithPos = findParentNodeOfType(mySchema.nodes.boldContainer)(TextSelection.create(view.state.doc, pos, pos))
if (!nodeWithPos) {
let matches = node.textContent.matchAll(/(\*\*)(.+)(\*\*)/gi)
matches = Array.from(matches)
matches.forEach(element => {
const newNode = mySchema.node('boldContainer', {}, [
mySchema.node('hidden', {}, mySchema.text('**')),
mySchema.node('boldText', { text: element[2] }, mySchema.text(element[2])),
mySchema.node('hidden', {}, mySchema.text('**'))
])
tr.replaceWith(pos + element.index, pos + element.index + element[0].length, newNode)
${selection.anchor} (size before resolving: ${tr.doc.content.size})`)
})
}
}
})
view.dispatch(tr)
return false;
I appreciate any ideas!