diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js index 42a6908606b13ce6fcb91d68ce0900f3443c2ff1..98a5f9cb5ebc16a5cdfa4a1dc366b826689f87b7 100644 --- a/editors/demo/src/Editoria/Editoria.js +++ b/editors/demo/src/Editoria/Editoria.js @@ -50,7 +50,7 @@ const Editoria = () => { value={demo} // readonly layout={layout} - // onChange={source => console.log(source)} + onChange={source => console.log(source)} user={user} /> </> diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index fb4449b8c5e66da6a27c8a044c1b311b6b2babbb..09f5faf635f4d3239ebcd446b34e2fd95ea5848e 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -1,7 +1,7 @@ /* eslint react/prop-types: 0 */ import React, { useEffect, useState } from 'react'; import debounce from 'lodash/debounce'; - +import { each } from 'lodash'; import { DOMSerializer } from 'prosemirror-model'; import WaxProvider from './WaxContext'; @@ -56,13 +56,21 @@ const Wax = props => { content => { /* HACK alter toDOM of footnote, because of how PM treats inline nodes with content */ - if (schema.nodes.footnote) { - const old = schema.nodes.footnote.spec.toDOM; - schema.nodes.footnote.spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - if (node) return ['footnote', node.attrs, 0]; - }; + + const notes = []; + each(schema.nodes, node => { + if (node.groups.includes('notes')) notes.push(node); + }); + + if (notes.length > 0) { + notes.forEach(note => { + const old = schema.nodes[note.name].spec.toDOM; + schema.nodes[note.name].spec.toDOM = node => { + // eslint-disable-next-line prefer-rest-params + old.apply(this); + if (node) return [note.name, node.attrs, 0]; + }; + }); } if (targetFormat === 'JSON') { @@ -71,13 +79,16 @@ const Wax = props => { const serialize = serializer(schema); WaxOnchange(serialize(content)); } - if (schema.nodes.footnote) { - const old = schema.nodes.footnote.spec.toDOM; - schema.nodes.footnote.spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - if (node) return ['footnote', node.attrs]; - }; + + if (notes.length > 0) { + notes.forEach(note => { + const old = schema.nodes[note.name].spec.toDOM; + schema.nodes[note.name].spec.toDOM = node => { + // eslint-disable-next-line prefer-rest-params + old.apply(this); + if (node) return [note.name, node.attrs]; + }; + }); } }, 1000, diff --git a/wax-prosemirror-schema/src/nodes/footNoteNode.js b/wax-prosemirror-schema/src/nodes/footNoteNode.js index 38b81a21152e0da673594aed101e39f5805db182..ab89aa79a54f3080f52944c39e286df3c4a637d3 100644 --- a/wax-prosemirror-schema/src/nodes/footNoteNode.js +++ b/wax-prosemirror-schema/src/nodes/footNoteNode.js @@ -1,5 +1,5 @@ const footnote = { - group: 'notes, inline', + group: 'notes inline', content: 'inline*', inline: true, atom: true,