@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,323 @@
1
+ import { writeIndented, } from '../MarkdownSerializer.js';
2
+ import { getHtmlInlineTokensHandlers, getInlineTokensHandlers, } from './inline_token_handlers.js';
3
+ import { numberString } from '../utils.js';
4
+ function getLongDefinitionTokensHandlers() {
5
+ return {
6
+ ...getInlineTokensHandlers(),
7
+ 'hardbreak': [
8
+ (token, ctx) => {
9
+ ctx.current.log('\n');
10
+ if (ctx.current.meta['para_hidden']) {
11
+ ctx.current.itemSymbol = '';
12
+ }
13
+ ctx.current.itemRow++;
14
+ },
15
+ ],
16
+ 'code_block': [
17
+ (token, ctx) => {
18
+ if (ctx.current.itemRow === 0) {
19
+ ctx.current.itemRow++;
20
+ }
21
+ if (ctx.output.colPos > 0) {
22
+ ctx.current.log('\n');
23
+ }
24
+ if (!ctx.output.endsWith('\n\n')) {
25
+ ctx.current.log('\n');
26
+ }
27
+ ctx.stash('getLongDefinitionTokensHandlers.code_block');
28
+ ctx.current.log = (txt) => {
29
+ writeIndented(ctx.output, txt, ctx.current, token);
30
+ };
31
+ ctx.current.log(token.content
32
+ .split('\n')
33
+ .map((t) => t.trim() ? (' ' + t) : '')
34
+ .join('\n') + '\n');
35
+ ctx.unstash('getLongDefinitionTokensHandlers.code_block');
36
+ ctx.current.itemRow++;
37
+ },
38
+ ],
39
+ 'paragraph_open': [
40
+ (token, ctx) => {
41
+ ctx.stash('getLongDefinitionTokensHandlers.paragraph_open');
42
+ ctx.current.meta['para_hidden'] = token.hidden;
43
+ },
44
+ ],
45
+ 'paragraph_close': [
46
+ (token, ctx) => {
47
+ ctx.unstash('getLongDefinitionTokensHandlers.paragraph_close');
48
+ if (ctx.output.colPos !== 0) {
49
+ // ctx.current.log('\n');
50
+ }
51
+ ctx.current.itemRow++;
52
+ },
53
+ ],
54
+ 'dt_open': [
55
+ (token, ctx) => {
56
+ ctx.current.itemSymbol = '';
57
+ ctx.current.itemRow = 0;
58
+ },
59
+ ],
60
+ 'dt_close': [
61
+ (token, ctx) => {
62
+ if (ctx.output.colPos !== 0) {
63
+ ctx.current.log('\n');
64
+ }
65
+ },
66
+ ],
67
+ 'dd_open': [
68
+ (token, ctx) => {
69
+ if (!ctx.output.endsWith('\n\n')) {
70
+ ctx.current.log('\n');
71
+ }
72
+ ctx.current.itemSymbol = ': ';
73
+ ctx.current.itemRow = 0;
74
+ },
75
+ ],
76
+ 'dd_close': [
77
+ (token, ctx) => {
78
+ if (ctx.output.colPos !== 0) {
79
+ ctx.current.log('\n');
80
+ }
81
+ },
82
+ ],
83
+ 'dl_open': [
84
+ (token, ctx) => {
85
+ ctx.stash('getLongDefinitionTokensHandlers.dl_open');
86
+ ctx.current.listPath.push('dl');
87
+ ctx.current.listType = 'dl';
88
+ },
89
+ ],
90
+ 'dl_close': [
91
+ (token, ctx) => {
92
+ ctx.unstash('getLongDefinitionTokensHandlers.dl_close');
93
+ },
94
+ ],
95
+ };
96
+ }
97
+ function getShortDefinitionTokensHandlers() {
98
+ const rollbackList = (token, ctx, tokenSource) => {
99
+ const rollbackPos = ctx.current.meta['def_rollback'];
100
+ if (!ctx.current.meta['def_token_start']) {
101
+ throw new Error('No def_token_start');
102
+ }
103
+ const outputPos = ctx.current.meta['def_output_pos'];
104
+ if (!ctx.current.meta['def_output_pos']) {
105
+ throw new Error('No def_output_pos');
106
+ }
107
+ tokenSource.rewind(ctx.current.meta['def_token_start']);
108
+ ctx.rollback(rollbackPos, 'rollbackList, ' + token.type);
109
+ ctx.output.rollback(outputPos);
110
+ ctx.stash('getShortDefinitionTokensHandlers.rollbackList');
111
+ ctx.current.listPath.push('dl');
112
+ ctx.current.listType = 'dl';
113
+ ctx.current.handlers = getLongDefinitionTokensHandlers();
114
+ };
115
+ return {
116
+ 'dl_open': [
117
+ (token, ctx, tokenSource) => {
118
+ const rollbackPos = ctx.stash('getShortDefinitionTokensHandlers.dl_open');
119
+ ctx.current.meta['def_rollback'] = rollbackPos;
120
+ ctx.current.meta['def_token_start'] = tokenSource.pos;
121
+ ctx.current.meta['def_output_pos'] = ctx.output.chunkPos;
122
+ ctx.current.listPath.push('dl');
123
+ ctx.current.listType = 'dl';
124
+ ctx.current.handlers = getShortDefinitionTokensHandlers();
125
+ },
126
+ ],
127
+ 'dl_close': [
128
+ (token, ctx) => {
129
+ ctx.unstash('getShortDefinitionTokensHandlers.dl_close');
130
+ },
131
+ ],
132
+ ...getInlineTokensHandlers(),
133
+ 'hardbreak': [
134
+ rollbackList,
135
+ ],
136
+ 'code_block': [
137
+ rollbackList,
138
+ ],
139
+ 'paragraph_open': [
140
+ (token, ctx) => {
141
+ // Skip, as paragraphs are implied by newlines
142
+ },
143
+ ],
144
+ 'paragraph_close': [
145
+ (token, ctx) => {
146
+ if (ctx.output.colPos !== 0) {
147
+ // ctx.current.log('\n');
148
+ }
149
+ },
150
+ ],
151
+ 'dt_open': [
152
+ (token, ctx) => {
153
+ ctx.current.itemSymbol = '';
154
+ ctx.current.itemRow = 0;
155
+ },
156
+ ],
157
+ 'dt_close': [
158
+ (token, ctx) => {
159
+ if (ctx.output.colPos !== 0) {
160
+ ctx.current.log('\n');
161
+ }
162
+ },
163
+ ],
164
+ 'dd_open': [
165
+ (token, ctx) => {
166
+ ctx.current.itemSymbol = ' ~ ';
167
+ ctx.current.itemRow = 0;
168
+ },
169
+ ],
170
+ 'dd_close': [
171
+ (token, ctx) => {
172
+ if (ctx.output.colPos !== 0) {
173
+ ctx.current.log('\n');
174
+ }
175
+ },
176
+ ],
177
+ };
178
+ }
179
+ export function getListsTokensHandlers() {
180
+ return {
181
+ 'dl_open': getShortDefinitionTokensHandlers()['dl_open'],
182
+ 'paragraph_close': [
183
+ (token, ctx) => {
184
+ if (ctx.output.colPos !== 0) {
185
+ ctx.current.log('\n', token);
186
+ }
187
+ ctx.current.itemRow++;
188
+ },
189
+ ],
190
+ 'task_list_open': [
191
+ (token, ctx) => {
192
+ ctx.stash('getListsTokensHandlers.task_list_open');
193
+ ctx.current.listPath.push('tl');
194
+ ctx.current.listType = 'tl';
195
+ ctx.current.itemSymbol = '';
196
+ ctx.current.itemNumber = 0;
197
+ },
198
+ ],
199
+ 'task_list_close': [
200
+ (token, ctx) => {
201
+ ctx.unstash('getListsTokensHandlers.task_list_close');
202
+ if (ctx.output.colPos !== 0) {
203
+ ctx.current.log('\n');
204
+ }
205
+ },
206
+ ],
207
+ 'task_item_open': [
208
+ (token, ctx) => {
209
+ ctx.current.itemRow = 0;
210
+ ctx.current.itemNumber++;
211
+ ctx.current.itemSymbol = token.attrGet('checked') ? 'x' : '';
212
+ if (ctx.output.colPos !== 0) {
213
+ ctx.current.log('\n');
214
+ }
215
+ },
216
+ ],
217
+ 'task_item_close': [
218
+ (token, ctx) => {
219
+ if (ctx.output.colPos !== 0) {
220
+ ctx.current.log('\n');
221
+ }
222
+ },
223
+ ],
224
+ 'bullet_list_open': [
225
+ (token, ctx) => {
226
+ ctx.stash('getListsTokensHandlers.bullet_list_open');
227
+ ctx.current.listPath.push('ul');
228
+ ctx.current.listType = 'ul';
229
+ ctx.current.itemSymbol = '';
230
+ ctx.current.itemNumber = 0;
231
+ },
232
+ ],
233
+ 'bullet_list_close': [
234
+ (token, ctx) => {
235
+ ctx.unstash('getListsTokensHandlers.bullet_list_close');
236
+ if (ctx.output.colPos !== 0) {
237
+ ctx.current.log('\n');
238
+ }
239
+ },
240
+ ],
241
+ 'ordered_list_open': [
242
+ (token, ctx) => {
243
+ {
244
+ ctx.stash('getListsTokensHandlers.ordered_list_open');
245
+ ctx.current.listPath.push('ol');
246
+ ctx.current.listType = 'ol';
247
+ const htmlInlineHandlers = Object.entries(getHtmlInlineTokensHandlers())
248
+ .filter((a) => [
249
+ 'strong_open',
250
+ 'strong_close',
251
+ 'em_open',
252
+ 'em_close',
253
+ 'underline_open',
254
+ 'underline_close',
255
+ 'strike_open',
256
+ 'strike_close',
257
+ ].includes(a[0]));
258
+ ctx.current.handlers = {
259
+ ...ctx.current.handlers,
260
+ ...Object.fromEntries(htmlInlineHandlers),
261
+ };
262
+ ctx.current.itemSymbol = '';
263
+ const symbol = token.attrGet('symbol');
264
+ if (symbol) {
265
+ ctx.current.meta['list_symbol'] = symbol;
266
+ }
267
+ else {
268
+ ctx.current.meta['list_symbol'] = '1';
269
+ }
270
+ const start = token.attrGet('start');
271
+ if (start) {
272
+ ctx.current.itemNumber = (+start || 1) - 1;
273
+ }
274
+ else {
275
+ ctx.current.itemNumber = 0;
276
+ }
277
+ }
278
+ },
279
+ ],
280
+ 'ordered_list_close': [
281
+ (token, ctx) => {
282
+ ctx.unstash('getListsTokensHandlers.ordered_list_close');
283
+ if (ctx.output.colPos !== 0) {
284
+ ctx.current.log('\n');
285
+ }
286
+ },
287
+ ],
288
+ 'list_item_open': [
289
+ (token, ctx) => {
290
+ ctx.current.itemRow = 0;
291
+ ctx.current.itemNumber++;
292
+ ctx.current.itemSymbol = token.info || token.markup;
293
+ if (!ctx.current.itemSymbol) {
294
+ ctx.current.itemSymbol = numberString(ctx.current.itemNumber, ctx.current.meta['list_symbol'] || '1');
295
+ }
296
+ if (ctx.output.colPos !== 0) {
297
+ ctx.current.log('\n');
298
+ }
299
+ },
300
+ ],
301
+ 'list_item_close': [
302
+ (token, ctx) => {
303
+ if (ctx.output.colPos !== 0) {
304
+ ctx.current.log('\n');
305
+ }
306
+ },
307
+ ],
308
+ 'blockquote_open': [
309
+ (token, ctx) => {
310
+ ctx.stash('getListsTokensHandlers.blockquote_open');
311
+ ctx.current.blockquoteCnt++;
312
+ if (ctx.output.colPos !== 0) {
313
+ ctx.current.log('\n');
314
+ }
315
+ },
316
+ ],
317
+ 'blockquote_close': [
318
+ (token, ctx) => {
319
+ ctx.unstash('getListsTokensHandlers.blockquote_close');
320
+ },
321
+ ],
322
+ };
323
+ }
@@ -0,0 +1,9 @@
1
+ import type { TokenHandler } from '../MarkdownSerializer.js';
2
+ export type TextAlign = 'left' | 'right';
3
+ export interface RollbackData {
4
+ sourcePos: number;
5
+ outputPos: number;
6
+ ctxDepth: number;
7
+ }
8
+ export declare function getTableTokensHandlers(): Record<string, Array<TokenHandler>>;
9
+ //# sourceMappingURL=table_token_handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table_token_handlers.d.ts","sourceRoot":"","sources":["../../../../src/extension-markdown/src/token_handlers/table_token_handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,0BAA0B,CAAC;AAIlC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAuNzC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAsID,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAI5E"}
@@ -0,0 +1,308 @@
1
+ import { getHtmlInlineTokensHandlers } from './inline_token_handlers.js';
2
+ function getHtmlTableTokensHandlers() {
3
+ return {
4
+ // ...getHtmlBasicTokensHandlers(), // TODO html
5
+ ...getHtmlInlineTokensHandlers(),
6
+ 'paragraph_open': [],
7
+ 'paragraph_close': [],
8
+ 'table_open': [
9
+ (token, ctx) => {
10
+ ctx.stash('getHtmlTableTokensHandlers.table_open');
11
+ ctx.current.meta['html_mode'] = true;
12
+ ctx.current.log('<table>\n', token);
13
+ },
14
+ ],
15
+ 'table_close': [
16
+ (token, ctx) => {
17
+ ctx.current.log('</table>\n', token);
18
+ ctx.unstash('getHtmlTableTokensHandlers.table_close');
19
+ },
20
+ ],
21
+ 'thead_open': [
22
+ (token, ctx) => {
23
+ ctx.current.log('<thead>\n', token);
24
+ },
25
+ ],
26
+ 'thead_close': [
27
+ (token, ctx) => {
28
+ ctx.current.log('</thead>\n', token);
29
+ },
30
+ ],
31
+ 'tr_open': [
32
+ (token, ctx) => {
33
+ ctx.current.log('<tr>\n', token);
34
+ },
35
+ ],
36
+ 'tr_close': [
37
+ (token, ctx) => {
38
+ ctx.current.log('</tr>\n', token);
39
+ },
40
+ ],
41
+ 'th_open': [
42
+ (token, ctx) => {
43
+ ctx.current.log('<th>', token);
44
+ },
45
+ ],
46
+ 'th_close': [
47
+ (token, ctx) => {
48
+ ctx.current.log('</th>\n', token);
49
+ },
50
+ ],
51
+ 'tbody_open': [
52
+ (token, ctx) => {
53
+ ctx.current.log('<tbody>\n', token);
54
+ },
55
+ ],
56
+ 'tbody_close': [
57
+ (token, ctx) => {
58
+ ctx.current.log('</tbody>\n', token);
59
+ },
60
+ ],
61
+ 'td_open': [
62
+ (token, ctx) => {
63
+ ctx.current.log('<td>', token);
64
+ },
65
+ ],
66
+ 'td_close': [
67
+ (token, ctx) => {
68
+ ctx.current.log('</td>\n', token);
69
+ },
70
+ ],
71
+ };
72
+ }
73
+ class TableBuilder {
74
+ constructor() {
75
+ Object.defineProperty(this, "rows", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: void 0
80
+ });
81
+ Object.defineProperty(this, "currentType", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: void 0
86
+ });
87
+ this.currentType = 'body';
88
+ this.rows = [];
89
+ }
90
+ appendRow() {
91
+ this.rows.push({
92
+ type: this.currentType,
93
+ cells: [],
94
+ });
95
+ }
96
+ appendCell(align, token) {
97
+ const lastRow = this.rows[this.rows.length - 1];
98
+ const startPos = token.map && token.map.length > 0 ? token.map[0] : 0;
99
+ lastRow.cells.push({
100
+ value: [],
101
+ startPos,
102
+ align,
103
+ });
104
+ }
105
+ appendText(content, token) {
106
+ const lastRow = this.rows[this.rows.length - 1];
107
+ if (lastRow.cells.length > 0) {
108
+ lastRow.cells[lastRow.cells.length - 1].value.push([content, token]);
109
+ }
110
+ }
111
+ render(log) {
112
+ let prevType = '';
113
+ let lastHeader = [];
114
+ const columnsWidth = [];
115
+ for (let rowNo = 0; rowNo < this.rows.length; rowNo++) {
116
+ const row = this.rows[rowNo];
117
+ for (let cellNo = 0; cellNo < row.cells.length; cellNo++) {
118
+ while (columnsWidth.length <= cellNo) {
119
+ columnsWidth.push(1);
120
+ }
121
+ const headCell = lastHeader[cellNo];
122
+ const cell = row.cells[cellNo];
123
+ const textLen = cell.value.reduce((prev, current) => prev + current[0].length, 0);
124
+ if (columnsWidth[cellNo] < textLen + 1) {
125
+ columnsWidth[cellNo] = textLen + 1;
126
+ }
127
+ }
128
+ }
129
+ for (let rowNo = 0; rowNo < this.rows.length; rowNo++) {
130
+ const row = this.rows[rowNo];
131
+ if (prevType === 'header' && prevType !== row.type) {
132
+ log('|');
133
+ for (let cellNo = 0; cellNo < lastHeader.length; cellNo++) {
134
+ const cell = lastHeader[cellNo];
135
+ log(' ');
136
+ if (cell.align === 'right') {
137
+ log('-'.repeat(columnsWidth[cellNo] - 2));
138
+ log(': |');
139
+ }
140
+ else {
141
+ log('-'.repeat(columnsWidth[cellNo] - 1));
142
+ log(' |');
143
+ }
144
+ }
145
+ log('\n');
146
+ }
147
+ log('|');
148
+ for (let cellNo = 0; cellNo < row.cells.length; cellNo++) {
149
+ const cell = row.cells[cellNo];
150
+ const textLen = cell.value.reduce((prev, current) => prev + current[0].length, 0);
151
+ if (cell.align === 'right') {
152
+ if (textLen === 0 && cell.startPos) {
153
+ log(' '.repeat(columnsWidth[cellNo] - textLen), { map: [cell.startPos + 2] });
154
+ }
155
+ else {
156
+ log(' '.repeat(columnsWidth[cellNo] - textLen));
157
+ }
158
+ }
159
+ else {
160
+ log(' '.repeat(1));
161
+ }
162
+ for (const pair of cell.value) {
163
+ log(pair[0], pair[1]);
164
+ }
165
+ if (textLen < columnsWidth[cellNo]) {
166
+ if (cell.align === 'right') {
167
+ log(' '.repeat(1));
168
+ }
169
+ else {
170
+ if (textLen === 0 && cell.startPos) {
171
+ log(' '.repeat(columnsWidth[cellNo] - textLen), { map: [cell.startPos + 2] });
172
+ }
173
+ else {
174
+ log(' '.repeat(columnsWidth[cellNo] - textLen));
175
+ }
176
+ }
177
+ }
178
+ log('|');
179
+ }
180
+ log('\n');
181
+ if (row.type === 'header') {
182
+ lastHeader = row.cells;
183
+ }
184
+ prevType = row.type;
185
+ }
186
+ }
187
+ }
188
+ function getMdTableTokensHandler() {
189
+ const rollbackMdTable = (token, ctx, tokenSource) => {
190
+ if (!ctx.current.meta['html_rollback']) {
191
+ throw new Error('No html_rollback');
192
+ }
193
+ const rollback = ctx.current.meta['html_rollback'];
194
+ tokenSource.rewind(rollback.sourcePos);
195
+ ctx.rollback(rollback.ctxDepth, 'rollbackMdTable, ' + token.type);
196
+ ctx.output.rollback(rollback.outputPos);
197
+ ctx.stash('getMdTableTokensHandler.rollbackTable');
198
+ ctx.current.meta['html_mode'] = true;
199
+ ctx.current.log('<table>\n', token);
200
+ ctx.current.handlers = getHtmlTableTokensHandlers();
201
+ };
202
+ return {
203
+ 'text': [
204
+ (token, ctx) => {
205
+ const tableBuilder = ctx.current.metaObj['table_builder'];
206
+ tableBuilder.appendText(token.content, token);
207
+ },
208
+ ],
209
+ 'paragraph_open': [],
210
+ 'paragraph_close': [
211
+ (token, ctx, tokenSource) => {
212
+ ctx.current.meta['table_cell_para_count'] =
213
+ +ctx.current.meta['table_cell_para_count'] + 1;
214
+ if (ctx.current.meta['table_cell_para_count'] > 1) { // Only 1 line in markdown pipe table
215
+ rollbackMdTable(token, ctx, tokenSource);
216
+ }
217
+ },
218
+ ],
219
+ 'default': [
220
+ rollbackMdTable,
221
+ ],
222
+ 'table_open': [
223
+ (token, ctx, tokenSource) => {
224
+ const rollbackDepth = ctx.stash('getMdTableTokensHandler.table_open');
225
+ if (!ctx.current.meta['html_rollback']) {
226
+ const rollback = {
227
+ sourcePos: tokenSource.pos,
228
+ outputPos: ctx.output.chunkPos,
229
+ ctxDepth: rollbackDepth,
230
+ };
231
+ ctx.current.meta['html_rollback'] = rollback;
232
+ }
233
+ ctx.current.metaObj['table_builder'] = new TableBuilder();
234
+ ctx.current.handlers = getMdTableTokensHandler();
235
+ },
236
+ ],
237
+ 'table_close': [
238
+ (token, ctx) => {
239
+ const tableBuilder = ctx.current.metaObj['table_builder'];
240
+ tableBuilder.render(ctx.current.log);
241
+ ctx.unstash('getMdTableTokensHandler.table_close');
242
+ },
243
+ ],
244
+ 'thead_open': [
245
+ (token, ctx) => {
246
+ const tableBuilder = ctx.current.metaObj['table_builder'];
247
+ tableBuilder.currentType = 'header';
248
+ },
249
+ ],
250
+ 'thead_close': [
251
+ (token, ctx) => {
252
+ const tableBuilder = ctx.current.metaObj['table_builder'];
253
+ tableBuilder.currentType = 'body';
254
+ },
255
+ ],
256
+ 'tr_open': [
257
+ (token, ctx) => {
258
+ const tableBuilder = ctx.current.metaObj['table_builder'];
259
+ tableBuilder.appendRow();
260
+ },
261
+ ],
262
+ 'tr_close': [
263
+ (token, ctx) => {
264
+ },
265
+ ],
266
+ 'th_open': [
267
+ (token, ctx) => {
268
+ // const style = token.attrGet('style');
269
+ // const align = style === 'text-align:right' ? 'right' : 'left';
270
+ const align = token.attrGet('align') || 'left';
271
+ const tableBuilder = ctx.current.metaObj['table_builder'];
272
+ tableBuilder.appendCell(align, token);
273
+ ctx.current.meta['table_cell_para_count'] = 0;
274
+ },
275
+ ],
276
+ 'th_close': [
277
+ (token, ctx) => {
278
+ },
279
+ ],
280
+ 'tbody_open': [
281
+ (token, ctx) => {
282
+ const tableBuilder = ctx.current.metaObj['table_builder'];
283
+ tableBuilder.currentType = 'body';
284
+ },
285
+ ],
286
+ 'tbody_close': [
287
+ (token, ctx) => {
288
+ },
289
+ ],
290
+ 'td_open': [
291
+ (token, ctx) => {
292
+ const align = token.attrGet('align') || 'left';
293
+ const tableBuilder = ctx.current.metaObj['table_builder'];
294
+ tableBuilder.appendCell(align, token);
295
+ ctx.current.meta['table_cell_para_count'] = 0;
296
+ },
297
+ ],
298
+ 'td_close': [
299
+ (token, ctx) => {
300
+ },
301
+ ],
302
+ };
303
+ }
304
+ export function getTableTokensHandlers() {
305
+ return {
306
+ 'table_open': getMdTableTokensHandler()['table_open'],
307
+ };
308
+ }
@@ -0,0 +1,5 @@
1
+ import { Token } from './types.js';
2
+ export declare function sitterTokenizer(cdnUrl?: string): Promise<{
3
+ parse: (source: string) => Array<Token>;
4
+ }>;
5
+ //# sourceMappingURL=treeSitterTokenizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeSitterTokenizer.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/treeSitterTokenizer.ts"],"names":[],"mappings":"AAKA,OAAO,EAIL,KAAK,EACN,MAAM,YAAY,CAAC;AA4kCpB,wBAAsB,eAAe,CAAC,MAAM,SAAK;oBAkB7B,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC;GASxC"}