I’ve attempted the below as a straw man to see if I can get some from of metadata into a ProseMirror doc in as simple a way as possible. To do that each node would need a title in the UI, and rather than mapping decorations forever I thought I’d just add text to the DOMOutputSpec. It’s pretty trivial to do and yet doesn’t work in either Firefox or Chrome (cursoring backwards from the content of, say, the imageAlt
node puts the cursor into the h2
tag). I just wondered whether this was supposed to be supported?
const image = schema =>
schema.spec.nodes.append({
image: {
group: 'block',
content: 'imageCaption imageAlt',
attrs: {
src: {}
},
parseDOM: [
{
tag: 'div.image-embed',
attrs: dom => ({
src: dom.querySelector('[data-image]').src
})
}
],
toDOM: node => [
'div',
{ class: 'image-embed' },
['img', { src: node.attrs.src, 'data-image': true }],
['div', 0]
],
defining: true,
isolating: true
},
imageCaption: {
toDOM: () => ['div', ['h2', 'Caption'], ['div', 0]],
content: 'inline*',
defining: true,
isolating: true
},
imageAlt: {
toDOM: () => ['div', ['h2', 'Alt'], ['div', 0]],
content: 'inline*',
defining: true,
isolating: true
}
});