@kerebron/extension-lsp 0.4.1

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 (211) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +82 -0
  3. package/esm/_dnt.polyfills.d.ts +101 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +127 -0
  6. package/esm/_dnt.shims.d.ts +6 -0
  7. package/esm/_dnt.shims.d.ts.map +1 -0
  8. package/esm/_dnt.shims.js +61 -0
  9. package/esm/editor/src/CoreEditor.d.ts +40 -0
  10. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  11. package/esm/editor/src/CoreEditor.js +252 -0
  12. package/esm/editor/src/DummyEditorView.d.ts +60 -0
  13. package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
  14. package/esm/editor/src/DummyEditorView.js +277 -0
  15. package/esm/editor/src/Extension.d.ts +31 -0
  16. package/esm/editor/src/Extension.d.ts.map +1 -0
  17. package/esm/editor/src/Extension.js +53 -0
  18. package/esm/editor/src/ExtensionManager.d.ts +32 -0
  19. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  20. package/esm/editor/src/ExtensionManager.js +260 -0
  21. package/esm/editor/src/Mark.d.ts +23 -0
  22. package/esm/editor/src/Mark.d.ts.map +1 -0
  23. package/esm/editor/src/Mark.js +51 -0
  24. package/esm/editor/src/Node.d.ts +32 -0
  25. package/esm/editor/src/Node.d.ts.map +1 -0
  26. package/esm/editor/src/Node.js +60 -0
  27. package/esm/editor/src/commands/CommandManager.d.ts +23 -0
  28. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  29. package/esm/editor/src/commands/CommandManager.js +118 -0
  30. package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
  31. package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
  32. package/esm/editor/src/commands/baseCommandFactories.js +836 -0
  33. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  34. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  35. package/esm/editor/src/commands/createChainableState.js +29 -0
  36. package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
  37. package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
  38. package/esm/editor/src/commands/keyCommandFactories.js +10 -0
  39. package/esm/editor/src/commands/mod.d.ts +7 -0
  40. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  41. package/esm/editor/src/commands/mod.js +76 -0
  42. package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
  43. package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
  44. package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
  45. package/esm/editor/src/commands/types.d.ts +18 -0
  46. package/esm/editor/src/commands/types.d.ts.map +1 -0
  47. package/esm/editor/src/commands/types.js +1 -0
  48. package/esm/editor/src/mod.d.ts +9 -0
  49. package/esm/editor/src/mod.d.ts.map +1 -0
  50. package/esm/editor/src/mod.js +8 -0
  51. package/esm/editor/src/nodeToTreeString.d.ts +10 -0
  52. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
  53. package/esm/editor/src/nodeToTreeString.js +74 -0
  54. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
  55. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  56. package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
  57. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  58. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  59. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  60. package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
  61. package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
  62. package/esm/editor/src/plugins/keymap/keymap.js +125 -0
  63. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
  64. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  65. package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
  66. package/esm/editor/src/types.d.ts +52 -0
  67. package/esm/editor/src/types.d.ts.map +1 -0
  68. package/esm/editor/src/types.js +1 -0
  69. package/esm/editor/src/ui.d.ts +15 -0
  70. package/esm/editor/src/ui.d.ts.map +1 -0
  71. package/esm/editor/src/ui.js +16 -0
  72. package/esm/editor/src/utilities/SmartOutput.d.ts +41 -0
  73. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
  74. package/esm/editor/src/utilities/SmartOutput.js +228 -0
  75. package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
  76. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  77. package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
  78. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
  79. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  80. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  81. package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
  82. package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
  83. package/esm/editor/src/utilities/getShadowRoot.js +16 -0
  84. package/esm/editor/src/utilities/mod.d.ts +6 -0
  85. package/esm/editor/src/utilities/mod.d.ts.map +1 -0
  86. package/esm/editor/src/utilities/mod.js +5 -0
  87. package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
  88. package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
  89. package/esm/editor/src/utilities/toRawTextResult.js +21 -0
  90. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
  91. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
  92. package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
  93. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
  94. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
  95. package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
  96. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
  97. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
  98. package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
  99. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
  100. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
  101. package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
  102. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
  103. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
  104. package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
  105. package/esm/extension-autocomplete/src/mod.d.ts +3 -0
  106. package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
  107. package/esm/extension-autocomplete/src/mod.js +2 -0
  108. package/esm/extension-autocomplete/src/types.d.ts +60 -0
  109. package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
  110. package/esm/extension-autocomplete/src/types.js +1 -0
  111. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
  112. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
  113. package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
  114. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
  115. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
  116. package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
  117. package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
  118. package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
  119. package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
  120. package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
  121. package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
  122. package/esm/extension-lsp/src/LSPClient.js +449 -0
  123. package/esm/extension-lsp/src/LspWebSocketTransport.d.ts +20 -0
  124. package/esm/extension-lsp/src/LspWebSocketTransport.d.ts.map +1 -0
  125. package/esm/extension-lsp/src/LspWebSocketTransport.js +137 -0
  126. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
  127. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
  128. package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
  129. package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
  130. package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
  131. package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
  132. package/esm/extension-lsp/src/mod.d.ts +5 -0
  133. package/esm/extension-lsp/src/mod.d.ts.map +1 -0
  134. package/esm/extension-lsp/src/mod.js +4 -0
  135. package/esm/extension-lsp/src/types.d.ts +20 -0
  136. package/esm/extension-lsp/src/types.d.ts.map +1 -0
  137. package/esm/extension-lsp/src/types.js +1 -0
  138. package/esm/extension-lsp/src/workspace.d.ts +62 -0
  139. package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
  140. package/esm/extension-lsp/src/workspace.js +168 -0
  141. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
  142. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
  143. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
  144. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
  145. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
  146. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
  147. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
  148. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
  149. package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
  150. package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
  151. package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
  152. package/esm/extension-markdown/src/MarkdownParser.js +249 -0
  153. package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
  154. package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
  155. package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
  156. package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
  157. package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
  158. package/esm/extension-markdown/src/PositionMapper.js +100 -0
  159. package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
  160. package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
  161. package/esm/extension-markdown/src/TokenSource.js +39 -0
  162. package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
  163. package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
  164. package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
  165. package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
  166. package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
  167. package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
  168. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
  169. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
  170. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
  171. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
  172. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
  173. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
  174. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
  175. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
  176. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
  177. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
  178. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
  179. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
  180. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
  181. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
  182. package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
  183. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
  184. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
  185. package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
  186. package/esm/extension-markdown/src/types.d.ts +28 -0
  187. package/esm/extension-markdown/src/types.d.ts.map +1 -0
  188. package/esm/extension-markdown/src/types.js +131 -0
  189. package/esm/extension-markdown/src/utils.d.ts +8 -0
  190. package/esm/extension-markdown/src/utils.d.ts.map +1 -0
  191. package/esm/extension-markdown/src/utils.js +86 -0
  192. package/esm/package.json +3 -0
  193. package/esm/tree-sitter-shim/src/main.d.ts +15 -0
  194. package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
  195. package/esm/tree-sitter-shim/src/main.js +25 -0
  196. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
  197. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
  198. package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
  199. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
  200. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
  201. package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
  202. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
  203. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
  204. package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
  205. package/esm/wasm/src/mod.d.ts +12 -0
  206. package/esm/wasm/src/mod.d.ts.map +1 -0
  207. package/esm/wasm/src/mod.js +48 -0
  208. package/esm/wasm/wasm.d.ts +138 -0
  209. package/esm/wasm/wasm.d.ts.map +1 -0
  210. package/esm/wasm/wasm.js +120 -0
  211. package/package.json +31 -0
@@ -0,0 +1,433 @@
1
+ import { Fragment } from 'prosemirror-model';
2
+ import { Token } from './types.js';
3
+ import { nodeToTreeStringOutput, } from '../../editor/src/mod.js';
4
+ import { MarkdownSerializer } from './MarkdownSerializer.js';
5
+ import { DocumentMarkdownTokenizer } from './DocumentMarkdownTokenizer.js';
6
+ import { SmartOutput } from '../../editor/src/utilities/mod.js';
7
+ function removeMarkedContent(node, markType) {
8
+ if (node.isText) {
9
+ const hasMark = node.marks.some((mark) => mark.type === markType);
10
+ return hasMark ? null : node;
11
+ }
12
+ if (node.isLeaf) {
13
+ return node;
14
+ }
15
+ const newContent = [];
16
+ node.content.forEach((child) => {
17
+ const cleaned = removeMarkedContent(child, markType);
18
+ if (cleaned) {
19
+ newContent.push(cleaned);
20
+ }
21
+ });
22
+ return node.copy(Fragment.fromArray(newContent));
23
+ }
24
+ class MdStashContext {
25
+ constructor() {
26
+ Object.defineProperty(this, "ctxStash", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: []
31
+ });
32
+ Object.defineProperty(this, "currentCtx", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ this.currentCtx = {
39
+ meta: {},
40
+ };
41
+ this.stash();
42
+ }
43
+ stash() {
44
+ this.ctxStash.push(this.currentCtx);
45
+ this.currentCtx = {
46
+ ...structuredClone({ ...this.currentCtx }),
47
+ };
48
+ return this.ctxStash.length - 1;
49
+ }
50
+ unstash() {
51
+ const ctx = this.ctxStash.pop();
52
+ if (!ctx) {
53
+ throw new Error('Unstash failed');
54
+ }
55
+ this.currentCtx = ctx;
56
+ }
57
+ get current() {
58
+ return this.currentCtx;
59
+ }
60
+ }
61
+ export async function pmToMdConverter(document, config, schema, editor) {
62
+ const result = syncPmToMdConverter(document, config, schema, editor);
63
+ return new TextEncoder().encode(result.content);
64
+ }
65
+ export function syncPmToMdConverter(document, config, schema, editor) {
66
+ const ctx = new MdStashContext();
67
+ // TODO: refactor to Tokenizer
68
+ const defaultMarkdownTokenizer = new DocumentMarkdownTokenizer({
69
+ paragraph(node) {
70
+ return {
71
+ open: 'paragraph_open',
72
+ close: 'paragraph_close',
73
+ };
74
+ },
75
+ hr(node) {
76
+ return {
77
+ selfClose: 'hr',
78
+ };
79
+ },
80
+ heading(node) {
81
+ return {
82
+ open: (node) => {
83
+ if (!node.attrs.level) {
84
+ throw new Error('No heading level');
85
+ }
86
+ const token = new Token('heading_open', 'h' + node.attrs.level, 1);
87
+ return token;
88
+ },
89
+ ///////
90
+ close: 'heading_close',
91
+ };
92
+ // state.write(state.repeat('#', node.attrs.level) + ' ');
93
+ // state.renderInline(node, false);
94
+ // state.closeBlock(node);
95
+ },
96
+ blockquote(node) {
97
+ return {
98
+ open: 'blockquote_open',
99
+ close: 'blockquote_close',
100
+ };
101
+ },
102
+ math() {
103
+ return {
104
+ open: 'math_block_open',
105
+ close: 'math_block_close',
106
+ // math_inline
107
+ // selfClose: (node) => {
108
+ // const token = new Token('math', 'math', 0);
109
+ // token.attrSet('content', node.attrs.content);
110
+ // if (node.attrs.type) {
111
+ // }
112
+ // return token;
113
+ // },
114
+ };
115
+ },
116
+ task_list(node) {
117
+ return {
118
+ open: (node) => {
119
+ ctx.stash();
120
+ ctx.current.meta['list_type'] = 'tl';
121
+ ctx.current.meta['list_type_symbol'] = '';
122
+ const token = new Token('task_list_open', 'ul', 1);
123
+ token.attrSet('symbol', '*');
124
+ return token;
125
+ },
126
+ close: (node) => {
127
+ ctx.unstash();
128
+ return new Token('task_list_close', 'ul', -1);
129
+ },
130
+ };
131
+ },
132
+ bullet_list(node) {
133
+ return {
134
+ open: (node) => {
135
+ ctx.stash();
136
+ ctx.current.meta['list_type'] = 'ul';
137
+ ctx.current.meta['list_type_symbol'] = '*';
138
+ const token = new Token('bullet_list_open', 'ul', 1);
139
+ token.attrSet('symbol', '*');
140
+ return token;
141
+ },
142
+ close: (node) => {
143
+ ctx.unstash();
144
+ return new Token('bullet_list_close', 'ul', -1);
145
+ },
146
+ };
147
+ },
148
+ ordered_list(node) {
149
+ return {
150
+ open: (node) => {
151
+ ctx.stash();
152
+ ctx.current.meta['list_type'] = 'ol';
153
+ ctx.current.meta['list_type_symbol'] = node.attrs['type'] ||
154
+ '1';
155
+ const token = new Token('ordered_list_open', 'ol', 1);
156
+ token.attrSet('symbol', node.attrs['type'] || '1');
157
+ return token;
158
+ },
159
+ close: (node) => {
160
+ ctx.unstash();
161
+ return new Token('ordered_list_close', 'ol', -1);
162
+ },
163
+ };
164
+ },
165
+ list_item(node) {
166
+ return {
167
+ open: (node) => {
168
+ const token = new Token('list_item_open', 'li', 1);
169
+ if (ctx.current.meta['list_type'] === 'ul') {
170
+ token.markup = ctx.current.meta['list_type_symbol'] || '-';
171
+ }
172
+ return token;
173
+ },
174
+ close: 'list_item_close',
175
+ };
176
+ },
177
+ task_item(node) {
178
+ return {
179
+ open: (node) => {
180
+ const token = new Token('task_item_open', 'li', 1);
181
+ token.attrSet('checked', node.attrs.checked ? 'checked' : '');
182
+ return token;
183
+ },
184
+ close: 'task_item_close',
185
+ };
186
+ },
187
+ table(node) {
188
+ return {
189
+ open: 'table_open',
190
+ close: 'table_close',
191
+ };
192
+ },
193
+ table_row(node) {
194
+ return {
195
+ open: 'tr_open',
196
+ close: 'tr_close',
197
+ };
198
+ },
199
+ table_cell(node) {
200
+ return {
201
+ open: 'td_open',
202
+ close: 'td_close',
203
+ };
204
+ },
205
+ table_header(node) {
206
+ return {
207
+ open: 'th_open',
208
+ close: 'th_close',
209
+ };
210
+ },
211
+ br(node) {
212
+ return {
213
+ selfClose: 'hardbreak',
214
+ };
215
+ },
216
+ text(node) {
217
+ return {
218
+ selfClose: (node) => {
219
+ const token = new Token('text', '', 0);
220
+ token.content = node.text || '';
221
+ return token;
222
+ },
223
+ };
224
+ },
225
+ code_block(node) {
226
+ return {
227
+ selfClose: (node) => {
228
+ const token = new Token('code_block', 'code', 0);
229
+ token.attrSet('lang', node.attrs.lang);
230
+ token.content = '';
231
+ node.forEach((child, offset) => {
232
+ token.content += child.text || '';
233
+ });
234
+ return token;
235
+ },
236
+ };
237
+ },
238
+ // html(state, node) {
239
+ // const domSerializer = DOMSerializer.fromSchema(schema);
240
+ // const element = domSerializer.serializeNode(node, {
241
+ // document: globalThis.document,
242
+ // });
243
+ // convertDomToLowerCase(element);
244
+ // const xmlSerializer = new XMLSerializer();
245
+ // const html = xmlSerializer.serializeToString(element) + '\n';
246
+ // // state.write(html.replace(/\sxmlns="[^"]*"/, ''));
247
+ // state.write(html);
248
+ // },
249
+ //
250
+ image(node) {
251
+ return {
252
+ selfClose: (node) => {
253
+ const token = new Token('image', 'img', 0);
254
+ token.attrSet('src', node.attrs.src);
255
+ if (node.attrs.title) {
256
+ token.attrSet('title', node.attrs.title);
257
+ }
258
+ return token;
259
+ },
260
+ };
261
+ },
262
+ }, {
263
+ em: {
264
+ open: 'em_open',
265
+ close: 'em_close',
266
+ mixable: true,
267
+ expelEnclosingWhitespace: true,
268
+ },
269
+ underline: {
270
+ open: 'underline_open',
271
+ close: 'underline_close',
272
+ mixable: true,
273
+ expelEnclosingWhitespace: true,
274
+ },
275
+ strong: {
276
+ open: 'strong_open',
277
+ close: 'strong_close',
278
+ mixable: true,
279
+ expelEnclosingWhitespace: true,
280
+ },
281
+ strike: {
282
+ open: 'strike_open',
283
+ close: 'strike_close',
284
+ mixable: true,
285
+ expelEnclosingWhitespace: true,
286
+ },
287
+ math: {
288
+ open: 'math_inline_open',
289
+ close: 'math_inline_close',
290
+ // math_inline
291
+ // selfClose: (node) => {
292
+ // const token = new Token('math', 'math', 0);
293
+ // token.attrSet('content', node.attrs.content);
294
+ // if (node.attrs.type) {
295
+ // }
296
+ // return token;
297
+ // },
298
+ },
299
+ link: {
300
+ open: (mark) => {
301
+ const token = new Token('link_open', 'a', 1);
302
+ token.attrSet('href', mark.attrs.href);
303
+ return token;
304
+ },
305
+ close: 'link_close',
306
+ mixable: true,
307
+ },
308
+ code: {
309
+ // selfClose: (node) => {
310
+ // const token = new Token('code_inline', 'code', 0);
311
+ // token.content = 'TODO_INLINE_CODE';
312
+ // // token.attrSet('content', node.attrs.content);
313
+ // // if (node.attrs.type) {
314
+ // // }
315
+ // return token;
316
+ // },
317
+ // open: (mark: Mark) => {
318
+ // },
319
+ // close: (mark: Mark) => {
320
+ // const token = new Token('code_inline', 'code', 0);
321
+ // token.content = 'TODO_INLINE_CODE';
322
+ // // token.attrSet('content', node.attrs.content);
323
+ // // if (node.attrs.type) {
324
+ // // }
325
+ // return token;
326
+ // },
327
+ open: 'code_open',
328
+ close: 'code_close',
329
+ escape: false,
330
+ },
331
+ // code: {
332
+ // open(_state, _mark, parent, index) {
333
+ // return backticksFor(parent.child(index), -1);
334
+ // },
335
+ // close(_state, _mark, parent, index) {
336
+ // return backticksFor(parent.child(index - 1), 1);
337
+ // },
338
+ // escape: false,
339
+ // }, // bookmark: {
340
+ // open(state, mark) {
341
+ // const id = mark.attrs.id;
342
+ // if (state.alreadyOutputedIds.has(id)) {
343
+ // return '';
344
+ // }
345
+ // state.alreadyOutputedIds.add(id);
346
+ // return `<a id="${id}"></a>`;
347
+ // },
348
+ // close() {
349
+ // return '';
350
+ // },
351
+ // },
352
+ });
353
+ document = removeMarkedContent(document, schema.marks.change);
354
+ // deleteAllMarkedText('change', state, dispatch)
355
+ const tokens = defaultMarkdownTokenizer.serialize(document);
356
+ if (config.debugTokens) {
357
+ const event = new CustomEvent('md:tokens', {
358
+ detail: {
359
+ tokens,
360
+ },
361
+ });
362
+ editor.dispatchEvent(event);
363
+ }
364
+ const markdownSerializerConfig = {
365
+ debug: config.serializerDebug,
366
+ };
367
+ const serializer = new MarkdownSerializer(markdownSerializerConfig);
368
+ const output = serializer.serialize(tokens);
369
+ const event = new CustomEvent('md:output', {
370
+ detail: {
371
+ output,
372
+ },
373
+ });
374
+ editor.dispatchEvent(event);
375
+ const debugMap = {};
376
+ const rawTextMap = [];
377
+ let sourceMap;
378
+ if (config.sourceMap) {
379
+ // https://sourcemaps.info/spec.html
380
+ // https://evanw.github.io/source-map-visualization/
381
+ // https://github.com/evanw/source-map-visualization/blob/gh-pages/code.js
382
+ const debugOutput = new SmartOutput();
383
+ nodeToTreeStringOutput(debugOutput, document);
384
+ debugOutput.getSourceMap((targetRow, targetCol, pos, item) => {
385
+ if (!item) {
386
+ return;
387
+ }
388
+ debugMap[item.pos] = {
389
+ targetRow,
390
+ targetCol,
391
+ };
392
+ });
393
+ sourceMap = output.getSourceMap((targetRow, targetCol, targetPos, item) => {
394
+ if (item?.map) {
395
+ const pos = item.map[0];
396
+ const sourceCol = item.map[2];
397
+ rawTextMap.push({
398
+ nodeIdx: pos,
399
+ targetPos,
400
+ targetRow,
401
+ targetCol,
402
+ sourceCol,
403
+ });
404
+ if (debugMap[pos]) {
405
+ return {
406
+ sourceNo: 0,
407
+ sourceRowPos: debugMap[pos].targetRow,
408
+ sourceColPos: debugMap[pos].targetCol,
409
+ };
410
+ }
411
+ }
412
+ });
413
+ sourceMap.file = 'target.md';
414
+ sourceMap.sources = ['debug.txt'];
415
+ sourceMap.sourcesContent = [debugOutput.toString()];
416
+ }
417
+ if (config.dispatchSourceMap) {
418
+ const event = new CustomEvent('md:sourcemap', {
419
+ detail: {
420
+ sourceMap,
421
+ debugMap,
422
+ rawTextMap,
423
+ },
424
+ });
425
+ editor.dispatchEvent(event);
426
+ }
427
+ return {
428
+ content: output.toString(),
429
+ sourceMap,
430
+ debugMap,
431
+ rawTextMap,
432
+ };
433
+ }
@@ -0,0 +1,4 @@
1
+ import type { TokenHandler } from '../MarkdownSerializer.js';
2
+ export declare function getHtmlBasicTokensHandlers(): Record<string, Array<TokenHandler>>;
3
+ export declare function getBasicTokensHandlers(): Record<string, Array<TokenHandler>>;
4
+ //# sourceMappingURL=basic_token_handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic_token_handlers.d.ts","sourceRoot":"","sources":["../../../../src/extension-markdown/src/token_handlers/basic_token_handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,0BAA0B,CAAC;AAGlC,wBAAgB,0BAA0B,IAAI,MAAM,CAClD,MAAM,EACN,KAAK,CAAC,YAAY,CAAC,CACpB,CAuDA;AAgBD,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CA4G5E"}
@@ -0,0 +1,151 @@
1
+ import { getInlineTokensHandlers } from './inline_token_handlers.js';
2
+ export function getHtmlBasicTokensHandlers() {
3
+ return {
4
+ 'frontmatter': [],
5
+ 'heading_open': [
6
+ (token, ctx) => {
7
+ ctx.current.log(`<${token.tag}>`, token);
8
+ },
9
+ ],
10
+ 'heading_close': [
11
+ (token, ctx) => {
12
+ ctx.current.log(`</${token.tag}>\n`, token);
13
+ },
14
+ ],
15
+ 'paragraph_open': [
16
+ (token, ctx) => {
17
+ ctx.current.log('<p>', token);
18
+ },
19
+ ],
20
+ 'paragraph_close': [
21
+ (token, ctx) => {
22
+ ctx.current.log('</p>\n', token);
23
+ },
24
+ ],
25
+ 'fence': [
26
+ (token, ctx) => {
27
+ ctx.current.log('<pre>' + token.content + '</pre>\n', token);
28
+ // ctx.current.log('```' + token.info + '\n' + token.content + '```\n\n', token);
29
+ },
30
+ ],
31
+ 'code_block': [
32
+ (token, ctx) => {
33
+ ctx.current.log('<pre>' + token.content + '</pre>\n', token);
34
+ // ctx.current.log(
35
+ // token.content
36
+ // .split('\n')
37
+ // .map((t) => t ? (' ' + t) : '')
38
+ // .join('\n') + '\n', token
39
+ // );
40
+ },
41
+ ],
42
+ 'hr': [
43
+ (token, ctx) => {
44
+ ctx.current.log('<hr />\n', token);
45
+ },
46
+ ],
47
+ 'html_block': [
48
+ (token, ctx) => {
49
+ ctx.current.log(token.content, token);
50
+ },
51
+ ],
52
+ };
53
+ }
54
+ function getHeaderTokensHandlers() {
55
+ const entriesBasic = Object.entries(getBasicTokensHandlers())
56
+ .filter((entry) => ['heading_close'].includes(entry[0]));
57
+ const entriesInline = Object.entries(getInlineTokensHandlers())
58
+ .filter((entry) => ['text', 'link_open', 'link_close'].includes(entry[0]));
59
+ return {
60
+ ...Object.fromEntries(entriesInline),
61
+ ...Object.fromEntries(entriesBasic),
62
+ 'default': [],
63
+ };
64
+ }
65
+ export function getBasicTokensHandlers() {
66
+ return {
67
+ 'frontmatter': [
68
+ (token, ctx) => {
69
+ ctx.current.log('---' + '\n' + token.content + '\n---\n\n', token);
70
+ },
71
+ ],
72
+ 'heading_open': [
73
+ (token, ctx) => {
74
+ ctx.stash('getBasicTokensHandlers.heading_open');
75
+ ctx.current.handlers = getHeaderTokensHandlers();
76
+ if (token.markup === '---') {
77
+ return;
78
+ }
79
+ ctx.current.log('#'.repeat(+token.tag.substring(1)) + ' ', token);
80
+ },
81
+ ],
82
+ 'heading_close': [
83
+ (token, ctx) => {
84
+ if (token.markup === '---') {
85
+ ctx.current.log('\n' + token.markup + '\n', token);
86
+ }
87
+ ctx.current.log('\n', token);
88
+ ctx.unstash('getBasicTokensHandlers.heading_close');
89
+ },
90
+ ],
91
+ 'paragraph_open': [
92
+ (token, ctx) => {
93
+ ctx.current.log('', token);
94
+ // Skip, as paragraphs are implied by newlines
95
+ },
96
+ ],
97
+ 'paragraph_close': [
98
+ (token, ctx) => {
99
+ if (ctx.output.colPos !== 0) {
100
+ ctx.current.log('\n', token);
101
+ }
102
+ },
103
+ ],
104
+ 'fence': [
105
+ (token, ctx) => {
106
+ const content = token.content.endsWith('\n')
107
+ ? token.content
108
+ : token.content + '\n';
109
+ if (token.info === 'latex') {
110
+ ctx.current.log('$$' + '\n' + content + '$$\n\n', token);
111
+ }
112
+ else {
113
+ const lang = token.attrGet('lang') || '';
114
+ ctx.current.log('```' + lang + '\n' + content + '```\n\n', token);
115
+ }
116
+ },
117
+ ],
118
+ 'code_block': [
119
+ (token, ctx) => {
120
+ const indent = +(token.attrGet('indent') || 0);
121
+ const lang = token.attrGet('lang') || '';
122
+ if (indent === 0) {
123
+ const content = token.content.endsWith('\n')
124
+ ? token.content
125
+ : token.content + '\n';
126
+ if (lang === 'latex') {
127
+ ctx.current.log('$$' + '\n' + content + '$$\n\n', token);
128
+ }
129
+ else {
130
+ ctx.current.log('```' + lang + '\n' + content + '```\n\n', token);
131
+ }
132
+ return;
133
+ }
134
+ ctx.current.log(token.content
135
+ .split('\n')
136
+ .map((t) => t ? (' '.repeat(indent) + t) : '')
137
+ .join('\n'), token);
138
+ },
139
+ ],
140
+ 'hr': [
141
+ (token, ctx) => {
142
+ ctx.current.log((token.markup || '---') + '\n', token);
143
+ },
144
+ ],
145
+ 'html_block': [
146
+ (token, ctx) => {
147
+ ctx.current.log(token.content, token);
148
+ },
149
+ ],
150
+ };
151
+ }
@@ -0,0 +1,3 @@
1
+ import type { TokenHandler } from '../MarkdownSerializer.js';
2
+ export declare function getFootnoteTokensHandlers(): Record<string, Array<TokenHandler>>;
3
+ //# sourceMappingURL=footnote_token_handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"footnote_token_handlers.d.ts","sourceRoot":"","sources":["../../../../src/extension-markdown/src/token_handlers/footnote_token_handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,yBAAyB,IAAI,MAAM,CACjD,MAAM,EACN,KAAK,CAAC,YAAY,CAAC,CACpB,CAiCA"}
@@ -0,0 +1,34 @@
1
+ export function getFootnoteTokensHandlers() {
2
+ return {
3
+ 'footnote_block_open': [
4
+ (token, ctx) => {
5
+ },
6
+ ],
7
+ 'footnote_block_close': [
8
+ (token, ctx) => {
9
+ },
10
+ ],
11
+ 'footnote_open': [
12
+ (token, ctx) => {
13
+ if (token.meta.label) {
14
+ ctx.current.log(`[^${token.meta.label}]: `, token);
15
+ }
16
+ else {
17
+ ctx.current.log(`[^footnote_${token.meta.id}]: `, token);
18
+ }
19
+ ctx.stash('getFootnoteTokensHandlers.footnote_open');
20
+ ctx.current.footnoteCnt++;
21
+ ctx.current.itemRow = 0;
22
+ },
23
+ ],
24
+ 'footnote_close': [
25
+ (token, ctx) => {
26
+ ctx.unstash('getFootnoteTokensHandlers.footnote_close');
27
+ },
28
+ ],
29
+ 'footnote_anchor': [
30
+ (token, ctx) => {
31
+ },
32
+ ],
33
+ };
34
+ }
@@ -0,0 +1,6 @@
1
+ import type { Token } from '../types.js';
2
+ import type { TokenHandler } from '../MarkdownSerializer.js';
3
+ export declare function escapeMarkdown(token: Token): Array<[string, Token]>;
4
+ export declare function getInlineTokensHandlers(): Record<string, Array<TokenHandler>>;
5
+ export declare function getHtmlInlineTokensHandlers(): Record<string, Array<TokenHandler>>;
6
+ //# sourceMappingURL=inline_token_handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline_token_handlers.d.ts","sourceRoot":"","sources":["../../../../src/extension-markdown/src/token_handlers/inline_token_handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CA4EnE;AAwDD,wBAAgB,uBAAuB,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAqJ7E;AAMD,wBAAgB,2BAA2B,IAAI,MAAM,CACnD,MAAM,EACN,KAAK,CAAC,YAAY,CAAC,CACpB,CA4IA"}