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

alter footnote schema only on export

parent 3ef41380
No related branches found
No related tags found
1 merge request!168Fix rerender notes
......@@ -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>
......
......@@ -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,
......
// 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: [
{
......
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