-
Notifications
You must be signed in to change notification settings - Fork 0
/
Footnote.js
89 lines (80 loc) · 2.46 KB
/
Footnote.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Footnote.js
import { Node } from '@tiptap/core';
import markdownitFootnotes from 'markdown-it-footnote';
import { Schema, DOMParser } from 'prosemirror-model';
export default Node.create({
name: 'footnote',
group: 'block',
content: 'block*',
// defining: true,
// selectable: true,
// draggable: true,
addAttributes() {
return {
id: {
default: null,
},
href: {
default: null,
},
content: {
default: null,
},
};
},
addStorage() {
return {
markdown: {
serialize(state, node) {
console.log(node.content);
state.write("[^" + (node.attrs.id.replace("fn", '')) + "]: ");
state.renderContent(node);
state.flushClose(1);
state.closeBlock(node);
},
parse: {
setup(markdownit) {
// console.log("parsed footnote");
// markdownit.use(markdownitFootnotes, 'footnote');
},
}
}
}
},
parseHTML() {
return [
{
tag: 'li.footnote-item',
getAttrs: (node) => ({
id: node.getAttribute('id'),
href: node.querySelector("a").getAttribute('href'),
content: Array.from(node.querySelector("p").childNodes)
.filter(child => child.nodeName.toLowerCase() !== 'a')
.map(child => child.textContent)
.join(''),
}),
getContent: (node) => {
console.log(node.childNodes[1])
return DOMParser.fromSchema(this.editor.schema).parseSlice(node.childNodes[1]).content;
},
priority: 200
},
];
},
renderHTML({ node }) {
return [
'p',
{ class: 'footnote-item', id: node.attrs.id },
[
'a',
{ href: node.attrs.id.replace('fn', '#fnref'), class: 'footnote-backref' },
node.attrs.id.replace('fn', '')+": "
],
[
'p',
{ class: 'footnote-text', style:"display:inline-block" },
0
]
]
}
});