Skip to content
Snippets Groups Projects
Commit 34cd9c6e authored by chris's avatar chris
Browse files

use note groups for save

parent 9b82dd88
No related branches found
No related tags found
1 merge request!294Inline question
......@@ -50,7 +50,7 @@ const Editoria = () => {
value={demo}
// readonly
layout={layout}
// onChange={source => console.log(source)}
onChange={source => console.log(source)}
user={user}
/>
</>
......
/* 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,
......
const footnote = {
group: 'notes, inline',
group: 'notes inline',
content: 'inline*',
inline: true,
atom: true,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment