From c7f38c5a0cf6d6471ce211e073cab63182512cba Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Sat, 26 Sep 2020 01:00:17 +0300 Subject: [PATCH] alter footnote schema only on export --- editors/editoria/src/Editoria.js | 8 +----- wax-prosemirror-core/src/Wax.js | 12 ++++++++- .../src/nodes/footNoteNode.js | 26 +------------------ 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/editors/editoria/src/Editoria.js b/editors/editoria/src/Editoria.js index 4cd67c916..ef823aeea 100644 --- a/editors/editoria/src/Editoria.js +++ b/editors/editoria/src/Editoria.js @@ -40,12 +40,6 @@ const user = { username: 'demo', }; -function decodeHtml(html) { - var txt = document.createElement('textarea'); - txt.innerHTML = html; - return txt.value; -} - const Editoria = () => ( <Fragment> <GlobalStyle /> @@ -58,7 +52,7 @@ const Editoria = () => ( // value={`<p class="paragraph">This is the first paragraph</p><p class="paragraph">This is the second paragraph</p><p class="author">This is an author</p>`} layout={EditoriaLayout} // debug - onChange={source => console.log(source)} + // onChange={source => console.log(source)} user={user} /> </Fragment> diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index f93d2b76f..6c5c30e87 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -90,11 +90,21 @@ const Wax = props => { }; const parse = parser(schema); - const serialize = serializer(schema); WaxOptions.doc = parse(editorContent); const finalOnChange = debounce( value => { + /* 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 = function (node) { + old.apply(this, arguments); + return ['footnote', node.attrs, 0]; + }; + } + + const serialize = serializer(schema); WaxOnchange(serialize(value)); }, 1000, diff --git a/wax-prosemirror-schema/src/nodes/footNoteNode.js b/wax-prosemirror-schema/src/nodes/footNoteNode.js index 237864946..582da4bc0 100644 --- a/wax-prosemirror-schema/src/nodes/footNoteNode.js +++ b/wax-prosemirror-schema/src/nodes/footNoteNode.js @@ -1,27 +1,3 @@ -// TODO Write the node in WaxSchema -const getHTMLString = node => { - const { textContent } = node; - - if (textContent) { - let strContent = textContent; - for (let i = 0; i < node.content.content.length; i += 1) { - for (let j = 0; j < node.content.content[i].marks.length; j += 1) { - const mark = node.content.content[i].marks[j]; - - const { type: markType } = mark; - const domDetails = markType.spec.toDOM(mark); - const htmlAttrs = Object.keys(domDetails[1]).reduce( - (str, key) => `${str}${key}="${domDetails[1][key]}"`, - '', - ); - const htmlTag = domDetails[0]; - strContent = `<${htmlTag} ${htmlAttrs}>${strContent}</${htmlTag}>`; - } - } - return strContent; - } -}; - const footnote = { group: 'inline', content: 'inline*', @@ -31,7 +7,7 @@ const footnote = { id: { default: '' }, }, toDOM: node => { - return ['footnote', node.attrs, 0]; + return ['footnote', node.attrs]; }, parseDOM: [ { -- GitLab