@kerebron/extension-menu 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +80 -0
  2. package/assets/custom-menu.css +26 -6
  3. package/assets/menu.css +2 -2
  4. package/esm/_dnt.polyfills.d.ts +101 -0
  5. package/esm/_dnt.polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.polyfills.js +127 -0
  7. package/esm/_dnt.shims.d.ts +1 -5
  8. package/esm/_dnt.shims.d.ts.map +1 -1
  9. package/esm/_dnt.shims.js +1 -5
  10. package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
  11. package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
  12. package/esm/editor/src/utilities/getShadowRoot.js +16 -0
  13. package/esm/editor/src/utilities/mod.d.ts +6 -0
  14. package/esm/editor/src/utilities/mod.d.ts.map +1 -0
  15. package/esm/editor/src/utilities/mod.js +5 -0
  16. package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
  17. package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
  18. package/esm/editor/src/utilities/toRawTextResult.js +21 -0
  19. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
  20. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
  21. package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
  22. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
  23. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
  24. package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
  25. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
  26. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
  27. package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
  28. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
  29. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
  30. package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
  31. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
  32. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
  33. package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
  34. package/esm/extension-autocomplete/src/mod.d.ts +3 -0
  35. package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
  36. package/esm/extension-autocomplete/src/mod.js +2 -0
  37. package/esm/extension-autocomplete/src/types.d.ts +60 -0
  38. package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
  39. package/esm/extension-autocomplete/src/types.js +1 -0
  40. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
  41. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
  42. package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
  43. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
  44. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
  45. package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
  46. package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
  47. package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
  48. package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
  49. package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
  50. package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
  51. package/esm/extension-lsp/src/LSPClient.js +449 -0
  52. package/esm/extension-lsp/src/LspStatus.d.ts +34 -0
  53. package/esm/extension-lsp/src/LspStatus.d.ts.map +1 -0
  54. package/esm/extension-lsp/src/LspStatus.js +127 -0
  55. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
  56. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
  57. package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
  58. package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
  59. package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
  60. package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
  61. package/esm/extension-lsp/src/workspace.d.ts +62 -0
  62. package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
  63. package/esm/extension-lsp/src/workspace.js +168 -0
  64. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
  65. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
  66. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
  67. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
  68. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
  69. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
  70. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
  71. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
  72. package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
  73. package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
  74. package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
  75. package/esm/extension-markdown/src/MarkdownParser.js +249 -0
  76. package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
  77. package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
  78. package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
  79. package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
  80. package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
  81. package/esm/extension-markdown/src/PositionMapper.js +100 -0
  82. package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
  83. package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
  84. package/esm/extension-markdown/src/TokenSource.js +39 -0
  85. package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
  86. package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
  87. package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
  88. package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
  89. package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
  90. package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
  91. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
  92. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
  93. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
  94. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
  95. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
  96. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
  97. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
  98. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
  99. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
  100. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
  101. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
  102. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
  103. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
  104. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
  105. package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
  106. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
  107. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
  108. package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
  109. package/esm/extension-markdown/src/types.d.ts +28 -0
  110. package/esm/extension-markdown/src/types.d.ts.map +1 -0
  111. package/esm/extension-markdown/src/types.js +131 -0
  112. package/esm/extension-markdown/src/utils.d.ts +8 -0
  113. package/esm/extension-markdown/src/utils.d.ts.map +1 -0
  114. package/esm/extension-markdown/src/utils.js +86 -0
  115. package/esm/extension-menu/src/CustomMenuPlugin.d.ts +7 -3
  116. package/esm/extension-menu/src/CustomMenuPlugin.d.ts.map +1 -1
  117. package/esm/extension-menu/src/CustomMenuPlugin.js +60 -4
  118. package/esm/extension-menu/src/ExtensionCustomMenu.d.ts +6 -2
  119. package/esm/extension-menu/src/ExtensionCustomMenu.d.ts.map +1 -1
  120. package/esm/extension-menu/src/ExtensionCustomMenu.js +36 -1
  121. package/esm/extension-menu/src/menu.d.ts +1 -1
  122. package/esm/extension-menu/src/mod.d.ts +1 -0
  123. package/esm/extension-menu/src/mod.d.ts.map +1 -1
  124. package/esm/extension-menu/src/mod.js +1 -0
  125. package/esm/extension-yjs/src/CollaborationStatus.d.ts +59 -0
  126. package/esm/extension-yjs/src/CollaborationStatus.d.ts.map +1 -0
  127. package/esm/extension-yjs/src/CollaborationStatus.js +286 -0
  128. package/esm/tree-sitter-shim/src/main.d.ts +15 -0
  129. package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
  130. package/esm/tree-sitter-shim/src/main.js +25 -0
  131. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
  132. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
  133. package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
  134. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
  135. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
  136. package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
  137. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
  138. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
  139. package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
  140. package/esm/wasm/src/mod.d.ts +12 -0
  141. package/esm/wasm/src/mod.d.ts.map +1 -0
  142. package/esm/wasm/src/mod.js +48 -0
  143. package/esm/wasm/wasm.d.ts +138 -0
  144. package/esm/wasm/wasm.d.ts.map +1 -0
  145. package/esm/wasm/wasm.js +120 -0
  146. package/package.json +3 -2
@@ -0,0 +1,240 @@
1
+ import { Token } from './types.js';
2
+ const blankMark = { open: '', close: '', mixable: true };
3
+ const blankNode = { open: '', close: '' };
4
+ function generateInlineTokens(input) {
5
+ const tokens = [];
6
+ let currentPos = -1;
7
+ let currentText = '';
8
+ for (const [text, inlinePos] of input) {
9
+ if (true || currentPos !== inlinePos) {
10
+ if (currentText.length > 0) {
11
+ const token = new Token('text', '', 0);
12
+ token.meta = 'generateInline1';
13
+ token.map = [currentPos];
14
+ token.content = currentText;
15
+ tokens.push(token);
16
+ }
17
+ currentText = '';
18
+ currentPos = inlinePos;
19
+ }
20
+ currentText += text;
21
+ }
22
+ if (currentText.length > 0) {
23
+ const token = new Token('text', '', 0);
24
+ token.meta = 'generateInline2';
25
+ token.map = [currentPos];
26
+ token.content = currentText;
27
+ tokens.push(token);
28
+ }
29
+ return tokens;
30
+ }
31
+ export class DocumentMarkdownInlineTokenizer {
32
+ constructor(nodes, marks, options) {
33
+ Object.defineProperty(this, "nodes", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: nodes
38
+ });
39
+ Object.defineProperty(this, "marks", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: marks
44
+ });
45
+ Object.defineProperty(this, "options", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: options
50
+ });
51
+ }
52
+ getMark(name) {
53
+ let info = this.marks[name];
54
+ if (!info) {
55
+ // if (this.options.strict !== false) {
56
+ // throw new Error(
57
+ // `Mark type \`${name}\` not supported by Markdown renderer`,
58
+ // );
59
+ // }
60
+ return blankMark;
61
+ }
62
+ return info;
63
+ }
64
+ renderInline(parent, currentPos, level) {
65
+ const active = [];
66
+ const trailing = [];
67
+ const inlineTokens = [];
68
+ const progress = (node, offset, index) => {
69
+ const inlinePos = currentPos + offset;
70
+ let marks = node ? node.marks : [];
71
+ // Remove marks from `hard_break` that are the last node inside
72
+ // that mark to prevent parser edge cases with new lines just
73
+ // before closing marks.
74
+ // TODO:
75
+ if (node && node.type.name === this.options.hardBreakNodeName) {
76
+ marks = marks.filter((m) => {
77
+ if (index + 1 == parent.childCount)
78
+ return false;
79
+ let next = parent.child(index + 1);
80
+ return m.isInSet(next.marks) &&
81
+ (!next.isText || /\S/.test(next.text));
82
+ });
83
+ }
84
+ const leading = trailing.splice(0, trailing.length);
85
+ // If whitespace has to be expelled from the node, adjust
86
+ // leading and trailing accordingly.
87
+ if (node.isText && marks.some((mark) => {
88
+ let info = this.getMark(mark.type.name);
89
+ return info && info.expelEnclosingWhitespace && !mark.isInSet(active);
90
+ })) {
91
+ let [_, lead, rest] = /^(\s*)(.*)$/m.exec(node.text);
92
+ if (lead) {
93
+ leading.push([lead, inlinePos]);
94
+ node = rest ? node.withText(rest) : null;
95
+ if (!node)
96
+ marks = active;
97
+ }
98
+ }
99
+ if (node.isText && marks.some((mark) => {
100
+ let info = this.getMark(mark.type.name);
101
+ return info && info.expelEnclosingWhitespace &&
102
+ (index == parent.childCount - 1 ||
103
+ !mark.isInSet(parent.child(index + 1).marks));
104
+ })) {
105
+ let [_, rest, trail] = /^(.*?)(\s*)$/m.exec(node.text);
106
+ if (trail) {
107
+ trailing.push([trail, inlinePos]);
108
+ node = rest ? node.withText(rest) : null;
109
+ if (!node)
110
+ marks = active;
111
+ }
112
+ }
113
+ let inner = marks.length ? marks[marks.length - 1] : null;
114
+ let noEsc = inner && this.getMark(inner.type.name).escape === false;
115
+ let len = marks.length - (noEsc ? 1 : 0);
116
+ // Try to reorder 'mixable' marks, such as em and strong, which
117
+ // in Markdown may be opened and closed in different order, so
118
+ // that order of the marks for the token matches the order in
119
+ // active.
120
+ outer: for (let i = 0; i < len; i++) {
121
+ let mark = marks[i];
122
+ if (!this.getMark(mark.type.name).mixable)
123
+ break;
124
+ for (let j = 0; j < active.length; j++) {
125
+ let other = active[j];
126
+ if (!this.getMark(other.type.name).mixable)
127
+ break;
128
+ if (mark.eq(other)) {
129
+ if (i > j) {
130
+ marks = marks.slice(0, j).concat(mark).concat(marks.slice(j, i))
131
+ .concat(marks.slice(i + 1, len));
132
+ }
133
+ else if (j > i) {
134
+ marks = marks.slice(0, i).concat(marks.slice(i + 1, j)).concat(mark).concat(marks.slice(j, len));
135
+ }
136
+ continue outer;
137
+ }
138
+ }
139
+ }
140
+ // Find the prefix of the mark set that didn't change
141
+ let keep = 0;
142
+ while (keep < Math.min(active.length, len) && marks[keep].eq(active[keep]))
143
+ ++keep;
144
+ // Close the marks that need to be closed
145
+ while (keep < active.length) {
146
+ const x = active.pop();
147
+ this.markString(x, false, inlineTokens);
148
+ }
149
+ // Output any previously expelled trailing whitespace outside the marks
150
+ inlineTokens.push(...generateInlineTokens(leading.splice(0, leading.length)));
151
+ // Open the marks that need to be opened
152
+ while (active.length < len) {
153
+ let add = marks[active.length];
154
+ active.push(add);
155
+ this.markString(add, true, inlineTokens);
156
+ }
157
+ // Render the node. Special case code marks, since their content
158
+ // may not be escaped.
159
+ if (noEsc && node.isText) {
160
+ this.markString(inner, true, inlineTokens);
161
+ if (node.text) {
162
+ const token = new Token('text', '', 0);
163
+ token.meta = 'noEscText';
164
+ token.map = [inlinePos];
165
+ token.content = node.text;
166
+ inlineTokens.push(token);
167
+ }
168
+ this.markString(inner, false, inlineTokens);
169
+ }
170
+ else {
171
+ const nodeSpec = this.nodes[node.type.name]
172
+ ? this.nodes[node.type.name](node, currentPos)
173
+ : blankNode;
174
+ let tag = '';
175
+ if (node.type.spec.toDOM) {
176
+ const dom = node.type.spec.toDOM(node);
177
+ if (Array.isArray(dom) && dom.length > 0) {
178
+ tag = dom[0];
179
+ }
180
+ }
181
+ if (nodeSpec.selfClose) {
182
+ if (typeof nodeSpec.selfClose === 'string') {
183
+ const token = new Token(nodeSpec.selfClose, tag, 0);
184
+ token.meta = 'nodeSpec.selfClose';
185
+ token.level = level;
186
+ token.map = [inlinePos];
187
+ inlineTokens.push(token);
188
+ }
189
+ else {
190
+ const token = nodeSpec.selfClose(node);
191
+ token.meta = '!nodeSpec.selfClose';
192
+ token.level = level;
193
+ token.map = [inlinePos];
194
+ inlineTokens.push(token);
195
+ }
196
+ }
197
+ }
198
+ };
199
+ parent.forEach((child, offset, index) => progress(child, offset, index));
200
+ // Close the marks that need to be closed
201
+ while (active.length > 0) {
202
+ const x = active.pop();
203
+ this.markString(x, false, inlineTokens);
204
+ }
205
+ // Output any previously expelled trailing whitespace outside the marks
206
+ inlineTokens.push(...generateInlineTokens(trailing.splice(0, trailing.length)));
207
+ return inlineTokens;
208
+ }
209
+ markString(mark, open, tokens) {
210
+ let info = this.getMark(mark.type.name);
211
+ let value = open ? info.open : info.close;
212
+ if (!value) {
213
+ /** Skip unknown marks (like textColor, highlight) - they'll be lost in markdown but won't crash */
214
+ console.warn('Unsupported mark type for markdown: ' + mark.type.name +
215
+ ', available types: ' +
216
+ Object.keys(this.marks).join(', ') + '. Mark will be ignored.');
217
+ return;
218
+ }
219
+ const token = typeof value == 'string' ? value : value(mark);
220
+ let tag = '';
221
+ if (mark.type.spec.toDOM) {
222
+ const dom = mark.type.spec.toDOM(mark, true);
223
+ if (Array.isArray(dom) && dom.length > 0) {
224
+ tag = dom[0];
225
+ }
226
+ }
227
+ if (typeof value === 'string') {
228
+ const token = new Token(value, tag, open ? 1 : -1);
229
+ token.meta = 'markString';
230
+ tokens.push(token);
231
+ }
232
+ else {
233
+ const token = value(mark);
234
+ if (token) {
235
+ token.meta = token.meta || 'markString()';
236
+ tokens.push(token);
237
+ }
238
+ }
239
+ }
240
+ }
@@ -0,0 +1,26 @@
1
+ import type { Node } from 'prosemirror-model';
2
+ import { Token } from './types.js';
3
+ import { DocumentMarkdownInlineTokenizer, DocumentMarkdownTokenizerSpec, MarkTokenizerSpec } from './DocumentMarkdownInlineTokenizer.js';
4
+ export declare class DocumentMarkdownTokenizer {
5
+ readonly nodes: {
6
+ [node: string]: (node: Node, index: number) => DocumentMarkdownTokenizerSpec;
7
+ };
8
+ readonly marks: {
9
+ [mark: string]: MarkTokenizerSpec;
10
+ };
11
+ readonly options: {
12
+ hardBreakNodeName: string;
13
+ };
14
+ private tokens;
15
+ inlineTokenizer: DocumentMarkdownInlineTokenizer;
16
+ constructor(nodes: {
17
+ [node: string]: (node: Node, index: number) => DocumentMarkdownTokenizerSpec;
18
+ }, marks: {
19
+ [mark: string]: MarkTokenizerSpec;
20
+ }, options?: {
21
+ hardBreakNodeName: string;
22
+ });
23
+ iterateNode(node: Node, currentPos: number, level?: number): void;
24
+ serialize(content: Node, options?: {}): Token[];
25
+ }
26
+ //# sourceMappingURL=DocumentMarkdownTokenizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocumentMarkdownTokenizer.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/DocumentMarkdownTokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,EAC7B,iBAAiB,EAClB,MAAM,sCAAsC,CAAC;AAI9C,qBAAa,yBAAyB;IAKlC,QAAQ,CAAC,KAAK,EAAE;QACd,CAAC,IAAI,EAAE,MAAM,GAAG,CACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,KACV,6BAA6B,CAAC;KACpC;IACD,QAAQ,CAAC,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE;IACrD,QAAQ,CAAC,OAAO,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE;IAXjD,OAAO,CAAC,MAAM,CAAoB;IAClC,eAAe,EAAE,+BAA+B,CAAC;gBAGtC,KAAK,EAAE;QACd,CAAC,IAAI,EAAE,MAAM,GAAG,CACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,KACV,6BAA6B,CAAC;KACpC,EACQ,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE,EAC5C,OAAO,GAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAE5C;IASH,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,SAAK;IA8EtD,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,GAAE,EAAO,GAAG,KAAK,EAAE;CAIpD"}
@@ -0,0 +1,115 @@
1
+ import { Token } from './types.js';
2
+ import { DocumentMarkdownInlineTokenizer, } from './DocumentMarkdownInlineTokenizer.js';
3
+ const blankNode = { open: '', close: '' };
4
+ export class DocumentMarkdownTokenizer {
5
+ constructor(nodes, marks, options = {
6
+ hardBreakNodeName: 'hard_break',
7
+ }) {
8
+ Object.defineProperty(this, "nodes", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: nodes
13
+ });
14
+ Object.defineProperty(this, "marks", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: marks
19
+ });
20
+ Object.defineProperty(this, "options", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: options
25
+ });
26
+ Object.defineProperty(this, "tokens", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: []
31
+ });
32
+ Object.defineProperty(this, "inlineTokenizer", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ this.inlineTokenizer = new DocumentMarkdownInlineTokenizer(nodes, marks, options);
39
+ }
40
+ iterateNode(node, currentPos, level = -1) {
41
+ const nodeSpec = this.nodes[node.type.name]
42
+ ? this.nodes[node.type.name](node, currentPos)
43
+ : blankNode;
44
+ let tag = '';
45
+ if (node.type.spec.toDOM) {
46
+ const dom = node.type.spec.toDOM(node);
47
+ if (Array.isArray(dom) && dom.length > 0) {
48
+ tag = dom[0];
49
+ }
50
+ }
51
+ if (nodeSpec.open) {
52
+ if (typeof nodeSpec.open === 'string') {
53
+ const token = new Token(nodeSpec.open, tag, 1);
54
+ token.level = level;
55
+ token.meta = 'nodeSpec.open';
56
+ token.map = [currentPos];
57
+ this.tokens.push(token);
58
+ }
59
+ else {
60
+ const token = nodeSpec.open(node);
61
+ token.level = level;
62
+ token.meta = 'nodeSpec.open()';
63
+ token.map = [currentPos];
64
+ this.tokens.push(token);
65
+ }
66
+ }
67
+ if (nodeSpec.selfClose) {
68
+ if (typeof nodeSpec.selfClose === 'string') {
69
+ const token = new Token(nodeSpec.selfClose, tag, 0);
70
+ token.level = level;
71
+ token.map = [currentPos];
72
+ this.tokens.push(token);
73
+ }
74
+ else {
75
+ const token = nodeSpec.selfClose(node);
76
+ token.level = level;
77
+ token.map = [currentPos];
78
+ this.tokens.push(token);
79
+ }
80
+ return;
81
+ }
82
+ if (node.inlineContent) {
83
+ const token = new Token('inline', '', 0);
84
+ token.level = level + 1;
85
+ token.map = [currentPos];
86
+ this.tokens.push(token);
87
+ token.children = this.inlineTokenizer.renderInline(node, currentPos + 1, level + 1);
88
+ }
89
+ else if (node.childCount > 0) {
90
+ node.forEach((child, offset) => {
91
+ this.iterateNode(child, currentPos + offset + 1, level + 1);
92
+ });
93
+ }
94
+ if (nodeSpec.close) {
95
+ if (typeof nodeSpec.close === 'string') {
96
+ const token = new Token(nodeSpec.close, tag, -1);
97
+ token.meta = 'nodeSpec.close';
98
+ token.level = level;
99
+ // token.map = [currentPos];
100
+ this.tokens.push(token);
101
+ }
102
+ else {
103
+ const token = nodeSpec.close(node);
104
+ token.meta = 'nodeSpec.close()';
105
+ token.level = level;
106
+ // token.map = [currentPos];
107
+ this.tokens.push(token);
108
+ }
109
+ }
110
+ }
111
+ serialize(content, options = {}) {
112
+ this.iterateNode(content, -1); // doc does not have index, so I put -1 for correct calculation
113
+ return this.tokens;
114
+ }
115
+ }
@@ -0,0 +1,22 @@
1
+ import type { Node, Schema } from 'prosemirror-model';
2
+ import { Slice } from 'prosemirror-model';
3
+ import { type Converter, type CoreEditor, Extension } from '../../editor/src/mod.js';
4
+ import { MarkdownResult } from './pmToMdConverter.js';
5
+ import type { Token } from './types.js';
6
+ export interface MdConfig {
7
+ sourceMap?: boolean;
8
+ dispatchSourceMap?: boolean;
9
+ debugTokens?: boolean;
10
+ serializerDebug?: (...args: any[]) => void;
11
+ cdnUrl?: string;
12
+ }
13
+ export type { Token };
14
+ export declare class ExtensionMarkdown extends Extension {
15
+ protected config: Partial<MdConfig>;
16
+ name: string;
17
+ constructor(config?: Partial<MdConfig>);
18
+ getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
19
+ toMarkdown(source: Node): MarkdownResult;
20
+ fromMarkdown(source: string): Promise<Slice>;
21
+ }
22
+ //# sourceMappingURL=ExtensionMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionMarkdown.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/ExtensionMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EACL,cAAc,EAGf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,QAAQ;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,YAAY,EAAE,KAAK,EAAE,CAAC;AAEtB,qBAAa,iBAAkB,SAAQ,SAAS;cAGR,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC;IAF/D,IAAI,SAAc;gBAEoB,MAAM,GAAE,OAAO,CAAC,QAAQ,CAAM;IAI3D,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAmB5B,UAAU,CAAC,MAAM,EAAE,IAAI,GAAG,cAAc;IAWlC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;CAiBnD"}
@@ -0,0 +1,48 @@
1
+ import { Slice } from 'prosemirror-model';
2
+ import { Extension } from '../../editor/src/mod.js';
3
+ import { pmToMdConverter, syncPmToMdConverter, } from './pmToMdConverter.js';
4
+ import { mdToPmConverter, mdToPmConverterText } from './mdToPmConverter.js';
5
+ export class ExtensionMarkdown extends Extension {
6
+ constructor(config = {}) {
7
+ super(config);
8
+ Object.defineProperty(this, "config", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: config
13
+ });
14
+ Object.defineProperty(this, "name", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: 'markdown'
19
+ });
20
+ }
21
+ getConverters(editor, schema) {
22
+ return {
23
+ 'text/x-markdown': {
24
+ fromDoc: (source) => pmToMdConverter(source, { cdnUrl: this.editor.config.cdnUrl, ...this.config }, schema, editor),
25
+ toDoc: (source) => mdToPmConverter(source, {
26
+ cdnUrl: this.editor.config.cdnUrl,
27
+ ...this.config,
28
+ }, schema),
29
+ },
30
+ };
31
+ }
32
+ toMarkdown(source) {
33
+ return syncPmToMdConverter(source, {
34
+ sourceMap: true,
35
+ }, this.editor.schema, this.editor);
36
+ }
37
+ async fromMarkdown(source) {
38
+ const doc = await mdToPmConverterText(source, { cdnUrl: this.editor.config.cdnUrl, ...this.config }, this.editor.schema);
39
+ const fragment = doc.content;
40
+ if (fragment.content.length === 1) {
41
+ const first = fragment.content[0];
42
+ if (first.type.name === 'paragraph') {
43
+ return new Slice(first.content, 0, 0);
44
+ }
45
+ }
46
+ return new Slice(fragment, 0, 0);
47
+ }
48
+ }
@@ -0,0 +1,61 @@
1
+ import type { Token } from './types.js';
2
+ import { Attrs, Mark, MarkType, Node, NodeType, Schema } from 'prosemirror-model';
3
+ export declare class MarkdownParseState {
4
+ readonly schema: Schema;
5
+ readonly tokenHandlers: {
6
+ [token: string]: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void;
7
+ };
8
+ stack: {
9
+ type: NodeType;
10
+ attrs: Attrs | null;
11
+ content: Node[];
12
+ marks: readonly Mark[];
13
+ }[];
14
+ constructor(schema: Schema, tokenHandlers: {
15
+ [token: string]: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void;
16
+ });
17
+ top(): {
18
+ type: NodeType;
19
+ attrs: Attrs | null;
20
+ content: Node[];
21
+ marks: readonly Mark[];
22
+ };
23
+ push(elt: Node): void;
24
+ addText(text: string): void;
25
+ openMark(mark: Mark): void;
26
+ closeMark(mark: MarkType): void;
27
+ parseTokens(toks: Token[]): void;
28
+ addNode(type: NodeType, attrs: Attrs | null, content?: readonly Node[]): Node | null;
29
+ openNode(type: NodeType, attrs: Attrs | null): void;
30
+ closeNode(): Node | null;
31
+ importNodes(nodes: readonly Node[]): void;
32
+ }
33
+ export interface ParseSpec {
34
+ node?: string;
35
+ block?: string;
36
+ mark?: string;
37
+ custom?: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void;
38
+ attrs?: Attrs | null;
39
+ getAttrs?: (token: Token, tokenStream: Token[], index: number) => Attrs | null;
40
+ noCloseToken?: boolean;
41
+ ignore?: boolean;
42
+ }
43
+ interface MarkdownTokenizer {
44
+ parse(markdown: string, markdownEnv?: Record<string, any>): Array<Token>;
45
+ }
46
+ export declare class MarkdownParser {
47
+ readonly schema: Schema;
48
+ readonly tokenizer: MarkdownTokenizer;
49
+ readonly tokens: {
50
+ [name: string]: ParseSpec;
51
+ };
52
+ tokenHandlers: {
53
+ [token: string]: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void;
54
+ };
55
+ constructor(schema: Schema, tokenizer: MarkdownTokenizer, tokens: {
56
+ [name: string]: ParseSpec;
57
+ });
58
+ parse(text: string, markdownEnv?: Record<string, any>): Node;
59
+ }
60
+ export {};
61
+ //# sourceMappingURL=MarkdownParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkdownParser.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/MarkdownParser.ts"],"names":[],"mappings":"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"}