@kerebron/extension-codemirror 0.3.1 → 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.
- package/README.md +3 -3
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/editor/src/CoreEditor.d.ts +13 -4
- package/esm/editor/src/CoreEditor.d.ts.map +1 -1
- package/esm/editor/src/CoreEditor.js +64 -12
- package/esm/editor/src/Extension.d.ts +6 -1
- package/esm/editor/src/Extension.d.ts.map +1 -1
- package/esm/editor/src/Extension.js +21 -1
- package/esm/editor/src/ExtensionManager.d.ts +5 -6
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
- package/esm/editor/src/ExtensionManager.js +43 -55
- package/esm/editor/src/Mark.d.ts +3 -0
- package/esm/editor/src/Mark.d.ts.map +1 -1
- package/esm/editor/src/Mark.js +11 -0
- package/esm/editor/src/Node.d.ts +5 -2
- package/esm/editor/src/Node.d.ts.map +1 -1
- package/esm/editor/src/Node.js +13 -2
- package/esm/editor/src/commands/CommandManager.d.ts +13 -6
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
- package/esm/editor/src/commands/CommandManager.js +59 -2
- package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/baseCommandFactories.js +836 -0
- package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/keyCommandFactories.js +10 -0
- package/esm/editor/src/commands/mod.d.ts +5 -53
- package/esm/editor/src/commands/mod.d.ts.map +1 -1
- package/esm/editor/src/commands/mod.js +14 -821
- package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
- package/esm/editor/src/commands/types.d.ts +18 -0
- package/esm/editor/src/commands/types.d.ts.map +1 -0
- package/esm/editor/src/commands/types.js +1 -0
- package/esm/editor/src/mod.d.ts +2 -0
- package/esm/editor/src/mod.d.ts.map +1 -1
- package/esm/editor/src/mod.js +2 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
- package/esm/editor/src/types.d.ts +20 -2
- package/esm/editor/src/types.d.ts.map +1 -1
- package/esm/editor/src/ui.d.ts +15 -0
- package/esm/editor/src/ui.d.ts.map +1 -0
- package/esm/editor/src/ui.js +16 -0
- package/esm/editor/src/utilities/SmartOutput.d.ts +9 -7
- package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -1
- package/esm/editor/src/utilities/SmartOutput.js +35 -20
- package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
- package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
- package/esm/editor/src/utilities/getShadowRoot.js +16 -0
- package/esm/editor/src/utilities/mod.d.ts +2 -0
- package/esm/editor/src/utilities/mod.d.ts.map +1 -1
- package/esm/editor/src/utilities/mod.js +2 -0
- package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
- package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
- package/esm/editor/src/utilities/toRawTextResult.js +21 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
- package/esm/extension-autocomplete/src/mod.d.ts +3 -0
- package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/mod.js +2 -0
- package/esm/extension-autocomplete/src/types.d.ts +60 -0
- package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/types.js +1 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts +9 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.js +58 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts +24 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.js +35 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts +25 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.js +96 -0
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +15 -2
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +1 -1
- package/esm/extension-codemirror/src/ExtensionCodeMirror.js +74 -2
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +13 -9
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +1 -1
- package/esm/extension-codemirror/src/NodeCodeMirror.js +34 -121
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +3 -2
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +1 -1
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +164 -103
- package/esm/extension-codemirror/src/defaults.d.ts +1 -1
- package/esm/extension-codemirror/src/defaults.d.ts.map +1 -1
- package/esm/extension-codemirror/src/defaults.js +4 -3
- package/esm/extension-codemirror/src/languageLoaders.d.ts.map +1 -1
- package/esm/extension-codemirror/src/languageLoaders.js +1 -2
- package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts +14 -0
- package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/LSPExtension.js +38 -0
- package/esm/extension-codemirror/src/lsp/completion.d.ts +8 -0
- package/esm/extension-codemirror/src/lsp/completion.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/completion.js +179 -0
- package/esm/extension-codemirror/src/lsp/hover.d.ts +5 -0
- package/esm/extension-codemirror/src/lsp/hover.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/hover.js +81 -0
- package/esm/extension-codemirror/src/lsp/index.d.ts +7 -0
- package/esm/extension-codemirror/src/lsp/index.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/index.js +49 -0
- package/esm/extension-codemirror/src/lsp/plugin.d.ts +37 -0
- package/esm/extension-codemirror/src/lsp/plugin.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/plugin.js +125 -0
- package/esm/extension-codemirror/src/lsp/pos.d.ts +5 -0
- package/esm/extension-codemirror/src/lsp/pos.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/pos.js +8 -0
- package/esm/extension-codemirror/src/lsp/text.d.ts +2 -0
- package/esm/extension-codemirror/src/lsp/text.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/text.js +47 -0
- package/esm/extension-codemirror/src/lsp/theme.d.ts +2 -0
- package/esm/extension-codemirror/src/lsp/theme.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/theme.js +76 -0
- package/esm/extension-codemirror/src/{y-remote-selections.d.ts → remote-selections.d.ts} +5 -5
- package/esm/extension-codemirror/src/remote-selections.d.ts.map +1 -0
- package/esm/extension-codemirror/src/{y-remote-selections.js → remote-selections.js} +49 -69
- package/esm/extension-codemirror/src/remote-sync.d.ts +11 -0
- package/esm/extension-codemirror/src/remote-sync.d.ts.map +1 -0
- package/esm/extension-codemirror/src/{y-sync.js → remote-sync.js} +6 -6
- package/esm/extension-codemirror/src/types.d.ts +10 -10
- package/esm/extension-codemirror/src/types.d.ts.map +1 -1
- package/esm/extension-codemirror/src/utils.d.ts +7 -6
- package/esm/extension-codemirror/src/utils.d.ts.map +1 -1
- package/esm/extension-codemirror/src/utils.js +21 -10
- package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
- package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
- package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
- package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
- package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
- package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
- package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
- package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
- package/esm/extension-lsp/src/LSPClient.js +449 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
- package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
- package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
- package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
- package/esm/extension-lsp/src/mod.d.ts +4 -0
- package/esm/extension-lsp/src/mod.d.ts.map +1 -0
- package/esm/extension-lsp/src/mod.js +3 -0
- package/esm/extension-lsp/src/workspace.d.ts +62 -0
- package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
- package/esm/extension-lsp/src/workspace.js +168 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
- package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
- package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
- package/esm/extension-markdown/src/MarkdownParser.js +249 -0
- package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
- package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
- package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
- package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
- package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
- package/esm/extension-markdown/src/PositionMapper.js +100 -0
- package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
- package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
- package/esm/extension-markdown/src/TokenSource.js +39 -0
- package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
- package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
- package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
- package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
- package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
- package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
- package/esm/extension-markdown/src/types.d.ts +28 -0
- package/esm/extension-markdown/src/types.d.ts.map +1 -0
- package/esm/extension-markdown/src/types.js +131 -0
- package/esm/extension-markdown/src/utils.d.ts +8 -0
- package/esm/extension-markdown/src/utils.d.ts.map +1 -0
- package/esm/extension-markdown/src/utils.js +86 -0
- package/esm/tree-sitter-shim/src/main.d.ts +15 -0
- package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/main.js +25 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
- package/esm/wasm/src/mod.d.ts +12 -0
- package/esm/wasm/src/mod.d.ts.map +1 -0
- package/esm/wasm/src/mod.js +48 -0
- package/esm/wasm/wasm.d.ts +138 -0
- package/esm/wasm/wasm.d.ts.map +1 -0
- package/esm/wasm/wasm.js +120 -0
- package/package.json +6 -26
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
- package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
- package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { NESTING_CLOSING } from './types.js';
|
|
2
|
+
import { getTableTokensHandlers } from './token_handlers/table_token_handlers.js';
|
|
3
|
+
import { getBasicTokensHandlers } from './token_handlers/basic_token_handlers.js';
|
|
4
|
+
import { getInlineTokensHandlers } from './token_handlers/inline_token_handlers.js';
|
|
5
|
+
import { getFootnoteTokensHandlers } from './token_handlers/footnote_token_handlers.js';
|
|
6
|
+
import { getListsTokensHandlers } from './token_handlers/lists_token_handlers.js';
|
|
7
|
+
import { TokenSource } from './TokenSource.js';
|
|
8
|
+
import { SmartOutput } from '../../editor/src/utilities/mod.js';
|
|
9
|
+
export function writeIndented(output, text, currentCtx, token) {
|
|
10
|
+
const lines = text.split('\n');
|
|
11
|
+
const typeIndent = {
|
|
12
|
+
ul: 2,
|
|
13
|
+
ol: 4,
|
|
14
|
+
dl: 2,
|
|
15
|
+
tl: 4,
|
|
16
|
+
};
|
|
17
|
+
let offset = 0;
|
|
18
|
+
const startPos = token
|
|
19
|
+
? (token.map && token.map.length > 0 ? token.map[0] : 0)
|
|
20
|
+
: 0;
|
|
21
|
+
for (let lineNo = 0; lineNo < lines.length; lineNo++) {
|
|
22
|
+
const line = lines[lineNo];
|
|
23
|
+
if (lineNo === lines.length - 1 && line.length === 0) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (output.colPos === 0) {
|
|
27
|
+
output.log('> '.repeat(currentCtx.blockquoteCnt).trim());
|
|
28
|
+
}
|
|
29
|
+
if (output.colPos === 0 && line.length > 0) {
|
|
30
|
+
output.log(' '.repeat(currentCtx.footnoteCnt));
|
|
31
|
+
const indent = currentCtx.listPath
|
|
32
|
+
.slice(0, currentCtx.listPath.length - 1)
|
|
33
|
+
.map((type) => typeIndent[type])
|
|
34
|
+
.reduce((p, c) => p + c, 0);
|
|
35
|
+
if (currentCtx.listType === 'tl') {
|
|
36
|
+
output.log(' '.repeat(indent));
|
|
37
|
+
if (currentCtx.itemRow === 0) {
|
|
38
|
+
output.log('- ');
|
|
39
|
+
if (currentCtx.itemSymbol) {
|
|
40
|
+
output.log('[x] ');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
output.log('[ ] ');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
output.log(' ');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (currentCtx.listType === 'ul') {
|
|
51
|
+
output.log(' '.repeat(indent));
|
|
52
|
+
if (currentCtx.itemRow === 0) {
|
|
53
|
+
output.log(currentCtx.itemSymbol + ' ');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
output.log(' ');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (currentCtx.listType === 'ol') {
|
|
60
|
+
const no = currentCtx.itemSymbol;
|
|
61
|
+
output.log(' '.repeat(indent));
|
|
62
|
+
if (currentCtx.itemRow === 0) {
|
|
63
|
+
output.log(no);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
output.log(' '.repeat(4));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (currentCtx.listType === 'dl') {
|
|
70
|
+
if (currentCtx.itemSymbol) {
|
|
71
|
+
if (currentCtx.itemRow === 0) {
|
|
72
|
+
output.log(`${currentCtx.itemSymbol}`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
output.log(' '.repeat(currentCtx.itemSymbol.length));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const tok = structuredClone(token);
|
|
81
|
+
if (startPos && tok) {
|
|
82
|
+
tok.map = [startPos + offset];
|
|
83
|
+
}
|
|
84
|
+
if (line.length > 0) {
|
|
85
|
+
if (currentCtx.blockquoteCnt > 0 &&
|
|
86
|
+
output.colPos === currentCtx.blockquoteCnt * 2 - 1) {
|
|
87
|
+
output.log(' ');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
output.log(line, tok);
|
|
91
|
+
offset += line.length;
|
|
92
|
+
if (lineNo < lines.length - 1) {
|
|
93
|
+
currentCtx.itemRow++;
|
|
94
|
+
const tok = structuredClone(token);
|
|
95
|
+
if (startPos && tok) {
|
|
96
|
+
tok.map = [startPos + offset];
|
|
97
|
+
}
|
|
98
|
+
output.log('\n', tok);
|
|
99
|
+
offset++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export class ContextStash {
|
|
104
|
+
constructor(handlers) {
|
|
105
|
+
Object.defineProperty(this, "ctxStash", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
value: []
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(this, "currentCtx", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true,
|
|
114
|
+
writable: true,
|
|
115
|
+
value: void 0
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(this, "output", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
writable: true,
|
|
121
|
+
value: void 0
|
|
122
|
+
});
|
|
123
|
+
this.output = new SmartOutput();
|
|
124
|
+
this.currentCtx = {
|
|
125
|
+
meta: {},
|
|
126
|
+
metaObj: {},
|
|
127
|
+
blockquoteCnt: 0,
|
|
128
|
+
footnoteCnt: 0,
|
|
129
|
+
itemRow: 0,
|
|
130
|
+
listPath: [],
|
|
131
|
+
itemNumber: 0,
|
|
132
|
+
itemSymbol: '',
|
|
133
|
+
handlers,
|
|
134
|
+
log: (txt, token) => this.output.log(txt, token),
|
|
135
|
+
debug: () => { },
|
|
136
|
+
};
|
|
137
|
+
this.stash('ContextStash.constructor()');
|
|
138
|
+
}
|
|
139
|
+
stash(reason) {
|
|
140
|
+
this.currentCtx.debug(' '.repeat(this.ctxStash.length) + 'stash: ' + reason);
|
|
141
|
+
this.ctxStash.push(this.currentCtx);
|
|
142
|
+
const funcs = {
|
|
143
|
+
log: this.currentCtx.log,
|
|
144
|
+
debug: this.currentCtx.debug,
|
|
145
|
+
};
|
|
146
|
+
const handlers = { ...this.currentCtx.handlers };
|
|
147
|
+
const metaObj = { ...this.currentCtx.metaObj };
|
|
148
|
+
this.currentCtx = {
|
|
149
|
+
...structuredClone({
|
|
150
|
+
...this.currentCtx,
|
|
151
|
+
log: undefined,
|
|
152
|
+
debug: undefined,
|
|
153
|
+
handlers: undefined,
|
|
154
|
+
}),
|
|
155
|
+
metaObj,
|
|
156
|
+
...funcs,
|
|
157
|
+
handlers: handlers,
|
|
158
|
+
};
|
|
159
|
+
const rollbackPos = this.ctxStash.length - 1;
|
|
160
|
+
return rollbackPos;
|
|
161
|
+
}
|
|
162
|
+
unstash(reason) {
|
|
163
|
+
const ctx = this.ctxStash.pop();
|
|
164
|
+
this.currentCtx.debug(' '.repeat(this.ctxStash.length) + 'unstash: ' + reason);
|
|
165
|
+
if (!ctx) {
|
|
166
|
+
throw new Error('Unstash failed');
|
|
167
|
+
}
|
|
168
|
+
this.currentCtx = ctx;
|
|
169
|
+
}
|
|
170
|
+
rollback(rollbackPos, reason) {
|
|
171
|
+
const rollbackCtx = this.ctxStash[rollbackPos];
|
|
172
|
+
if (!rollbackCtx) {
|
|
173
|
+
throw new RangeError('Invalid rollbackPos: ' + rollbackPos);
|
|
174
|
+
}
|
|
175
|
+
this.currentCtx.debug('rollback ' + reason, rollbackPos);
|
|
176
|
+
this.ctxStash.splice(rollbackPos);
|
|
177
|
+
this.currentCtx = this.ctxStash[this.ctxStash.length - 1];
|
|
178
|
+
}
|
|
179
|
+
get current() {
|
|
180
|
+
return this.currentCtx;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export function serializeInlineTokens(ctx, tokenSource, tokens) {
|
|
184
|
+
const appendPos = tokenSource.append(tokens);
|
|
185
|
+
const oldPos = tokenSource.pos;
|
|
186
|
+
tokenSource.rewind(appendPos);
|
|
187
|
+
try {
|
|
188
|
+
tokenSource.iterate(appendPos, (token, i) => {
|
|
189
|
+
const tokenHandlers = ctx.current.handlers[token.type] || ctx.current.handlers['default'];
|
|
190
|
+
if (!tokenHandlers) {
|
|
191
|
+
throw new Error(`Unknown inline token: ${token.type} ` + JSON.stringify(token) +
|
|
192
|
+
`, available hadlers: ${Object.keys(ctx.current.handlers)}`);
|
|
193
|
+
}
|
|
194
|
+
for (const handler of tokenHandlers) {
|
|
195
|
+
if (handler(token, ctx, tokenSource)) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (tokenSource.pos + 1 < appendPos) {
|
|
200
|
+
throw new RangeError('Rewinded before inline tokens');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
tokenSource.rewind(oldPos);
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
tokenSource.trim(appendPos);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export class MarkdownSerializer {
|
|
210
|
+
constructor(config = {}) {
|
|
211
|
+
Object.defineProperty(this, "ctx", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: void 0
|
|
216
|
+
});
|
|
217
|
+
this.ctx = new ContextStash({
|
|
218
|
+
...getInlineTokensHandlers(),
|
|
219
|
+
...getTableTokensHandlers(),
|
|
220
|
+
...getBasicTokensHandlers(),
|
|
221
|
+
...getFootnoteTokensHandlers(),
|
|
222
|
+
...getListsTokensHandlers(),
|
|
223
|
+
});
|
|
224
|
+
if (config.debug) {
|
|
225
|
+
this.ctx.current.debug = config.debug;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
get endsWithEmptyLine() {
|
|
229
|
+
return this.ctx.output.endsWith('\n\n');
|
|
230
|
+
}
|
|
231
|
+
serialize(tokens) {
|
|
232
|
+
const prevLevelTokenType = {};
|
|
233
|
+
const tokenSource = new TokenSource(tokens);
|
|
234
|
+
tokenSource.iterate(0, (token, i) => {
|
|
235
|
+
if (!this.ctx.current.meta['html_mode']) {
|
|
236
|
+
if (token.level === 0 && token.nesting !== NESTING_CLOSING) {
|
|
237
|
+
if (this.ctx.output.colPos !== 0) {
|
|
238
|
+
this.ctx.current.log('\n');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!this.endsWithEmptyLine) {
|
|
242
|
+
if (token.nesting !== NESTING_CLOSING && token.level === 0) {
|
|
243
|
+
const prevTopTokenType = prevLevelTokenType[token.level] || '';
|
|
244
|
+
if ([
|
|
245
|
+
'hr',
|
|
246
|
+
'paragraph_close',
|
|
247
|
+
'ordered_list_close',
|
|
248
|
+
'bullet_list_close',
|
|
249
|
+
'task_list_close',
|
|
250
|
+
'dl_close',
|
|
251
|
+
'table_close',
|
|
252
|
+
'blockquote_close',
|
|
253
|
+
'footnote_close',
|
|
254
|
+
'code_block',
|
|
255
|
+
'html_block',
|
|
256
|
+
].includes(prevTopTokenType)) {
|
|
257
|
+
this.ctx.current.log('\n');
|
|
258
|
+
}
|
|
259
|
+
if ('heading_close' === prevTopTokenType &&
|
|
260
|
+
token.tag !== 'heading_open') {
|
|
261
|
+
this.ctx.current.log('\n');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else if (token.nesting !== NESTING_CLOSING && token.level === 1 &&
|
|
265
|
+
'dt_open' === token.type) {
|
|
266
|
+
const prevTokenType = prevLevelTokenType[token.level] || '';
|
|
267
|
+
if ([
|
|
268
|
+
'dt_close',
|
|
269
|
+
'dd_close',
|
|
270
|
+
].includes(prevTokenType)) {
|
|
271
|
+
this.ctx.current.log('\n');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (token.nesting !== NESTING_CLOSING && token.level > 0) {
|
|
277
|
+
const prevTopTokenType = prevLevelTokenType[token.level] || '';
|
|
278
|
+
if ([
|
|
279
|
+
'paragraph_close',
|
|
280
|
+
].includes(prevTopTokenType)) {
|
|
281
|
+
if (this.ctx.current.blockquoteCnt === token.level) {
|
|
282
|
+
writeIndented(this.ctx.output, '\n', this.ctx.current, token);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const tokenHandlers = this.ctx.current.handlers[token.type] ||
|
|
287
|
+
this.ctx.current.handlers['default'];
|
|
288
|
+
if (token.type === 'inline') {
|
|
289
|
+
if (token.children) {
|
|
290
|
+
this.ctx.stash('serializeInlineTokens()');
|
|
291
|
+
this.ctx.current.log = (txt, token) => {
|
|
292
|
+
writeIndented(this.ctx.output, txt, this.ctx.current, token);
|
|
293
|
+
};
|
|
294
|
+
try {
|
|
295
|
+
serializeInlineTokens(this.ctx, tokenSource, token.children);
|
|
296
|
+
this.ctx.unstash('serializeInlineTokens()');
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
this.ctx.current.debug(err.message);
|
|
300
|
+
if (err.message === 'Rewinded before inline tokens') {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
throw err;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else if (!tokenHandlers) {
|
|
308
|
+
this.ctx.current.debug('current.handlers', Object.keys(this.ctx.current.handlers).sort());
|
|
309
|
+
throw new Error(`Unknown token: ${token.type} ` + JSON.stringify(token));
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
for (const handler of tokenHandlers) {
|
|
313
|
+
if (handler(token, this.ctx, tokenSource)) {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
prevLevelTokenType[token.level] = token.type;
|
|
319
|
+
if (token.nesting === NESTING_CLOSING) {
|
|
320
|
+
prevLevelTokenType[token.level + 1] = '';
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
return this.ctx.output;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Node } from 'prosemirror-model';
|
|
2
|
+
import type { CoreEditor, RawTextMapEntry } from '../../editor/src/mod.js';
|
|
3
|
+
export declare class PositionMapper {
|
|
4
|
+
readonly rawTextMap: Array<RawTextMapEntry>;
|
|
5
|
+
private readonly rawTextArr;
|
|
6
|
+
readonly doc: Node;
|
|
7
|
+
constructor(editor: CoreEditor, rawTextMap: Array<RawTextMapEntry>);
|
|
8
|
+
toRawTextPos(pos: number): number;
|
|
9
|
+
toRawTextLspPos(pos: number): {
|
|
10
|
+
line: number;
|
|
11
|
+
character: number;
|
|
12
|
+
};
|
|
13
|
+
fromLineChar(line: number, character: number): number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=PositionMapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PositionMapper.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/PositionMapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAiC3E,qBAAa,cAAc;aAMP,UAAU,EAAE,KAAK,CAAC,eAAe,CAAC;IALpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,SAAgB,GAAG,EAAE,IAAI,CAAC;gBAGxB,MAAM,EAAE,UAAU,EACF,UAAU,EAAE,KAAK,CAAC,eAAe,CAAC;IA0BpD,YAAY,CAAC,GAAG,EAAE,MAAM;IAUxB,eAAe,CAAC,GAAG,EAAE,MAAM;;;;IAa3B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAoB7C"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
function findFirstLetterPosition(node, startPos) {
|
|
2
|
+
let firstLetterPos = -1;
|
|
3
|
+
let textLen = 0;
|
|
4
|
+
node.descendants((child, posInParent) => {
|
|
5
|
+
if (child.isText && child.text && child.text.length > 0) {
|
|
6
|
+
firstLetterPos = startPos + posInParent + 1; // First char of first text node
|
|
7
|
+
textLen = child.text.length;
|
|
8
|
+
return false; // Stop
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
});
|
|
12
|
+
if (firstLetterPos === -1) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return [firstLetterPos, textLen];
|
|
16
|
+
}
|
|
17
|
+
export class PositionMapper {
|
|
18
|
+
constructor(editor, rawTextMap) {
|
|
19
|
+
Object.defineProperty(this, "rawTextMap", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: rawTextMap
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "rawTextArr", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "doc", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
this.doc = editor.state.doc;
|
|
38
|
+
this.rawTextArr = [];
|
|
39
|
+
for (const item of rawTextMap) {
|
|
40
|
+
if (item.nodeIdx > 0) {
|
|
41
|
+
this.rawTextArr.push({
|
|
42
|
+
nodeIdx: item.nodeIdx,
|
|
43
|
+
maxNodeIdx: item.nodeIdx,
|
|
44
|
+
targetPos: item.targetPos,
|
|
45
|
+
targetRow: item.targetRow,
|
|
46
|
+
targetCol: item.targetCol,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.rawTextArr.sort((b, a) => b.nodeIdx - a.nodeIdx);
|
|
51
|
+
for (let i = 0; i < this.rawTextArr.length; i++) {
|
|
52
|
+
const next = i + 1;
|
|
53
|
+
if (next < this.rawTextArr.length) {
|
|
54
|
+
this.rawTextArr[i].maxNodeIdx = this.rawTextArr[next].nodeIdx - 1;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.rawTextArr[i].maxNodeIdx = this.doc.nodeSize;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
toRawTextPos(pos) {
|
|
62
|
+
for (let i = 0; i < this.rawTextArr.length; i++) {
|
|
63
|
+
const item = this.rawTextArr[i];
|
|
64
|
+
if (pos >= item.nodeIdx && pos <= item.maxNodeIdx) {
|
|
65
|
+
return item.targetPos + pos - item.nodeIdx;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return -1;
|
|
69
|
+
}
|
|
70
|
+
toRawTextLspPos(pos) {
|
|
71
|
+
for (let i = 0; i < this.rawTextArr.length; i++) {
|
|
72
|
+
const item = this.rawTextArr[i];
|
|
73
|
+
if (pos >= item.nodeIdx && pos <= item.maxNodeIdx) {
|
|
74
|
+
return {
|
|
75
|
+
line: item.targetRow,
|
|
76
|
+
character: item.targetCol + pos - item.nodeIdx,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { line: 0, character: 0 };
|
|
81
|
+
}
|
|
82
|
+
fromLineChar(line, character) {
|
|
83
|
+
for (let i = 0; i < this.rawTextArr.length; i++) {
|
|
84
|
+
const item = this.rawTextArr[i];
|
|
85
|
+
const len = item.maxNodeIdx - item.nodeIdx + 1;
|
|
86
|
+
if (item.targetRow === line) {
|
|
87
|
+
if (character >= item.targetCol && character < item.targetCol + len) {
|
|
88
|
+
const offset = character - item.targetCol;
|
|
89
|
+
return item.nodeIdx + offset;
|
|
90
|
+
}
|
|
91
|
+
const nextItem = this.rawTextArr[i + 1];
|
|
92
|
+
const isLastInRow = !nextItem || nextItem.targetRow > item.targetRow;
|
|
93
|
+
if (isLastInRow && character >= item.targetCol + len) {
|
|
94
|
+
return item.maxNodeIdx;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class TokenSource<K> {
|
|
2
|
+
private tokens;
|
|
3
|
+
private currentPos;
|
|
4
|
+
constructor(tokens: Array<K>);
|
|
5
|
+
get pos(): number;
|
|
6
|
+
iterate(start: number, callback: (token: K, tokenNo: number) => void): void;
|
|
7
|
+
append(tokens: Array<K>): number;
|
|
8
|
+
trim(pos: number): void;
|
|
9
|
+
rewind(tokenNo?: number): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=TokenSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenSource.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/TokenSource.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW,CAAC,CAAC;IAGZ,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,UAAU,CAAS;gBAEP,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAIpC,IAAI,GAAG,WAEN;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI;IAWpE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAKvB,IAAI,CAAC,GAAG,EAAE,MAAM;IAIhB,MAAM,CAAC,OAAO,GAAE,MAAW;CAM5B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class TokenSource {
|
|
2
|
+
constructor(tokens) {
|
|
3
|
+
Object.defineProperty(this, "tokens", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: tokens
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "currentPos", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: void 0
|
|
14
|
+
});
|
|
15
|
+
this.currentPos = 0;
|
|
16
|
+
}
|
|
17
|
+
get pos() {
|
|
18
|
+
return this.currentPos;
|
|
19
|
+
}
|
|
20
|
+
iterate(start, callback) {
|
|
21
|
+
for (this.currentPos = start; this.currentPos < this.tokens.length; this.currentPos++) {
|
|
22
|
+
const token = this.tokens[this.currentPos];
|
|
23
|
+
callback(token, this.currentPos);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
append(tokens) {
|
|
27
|
+
this.tokens.push(...tokens);
|
|
28
|
+
return this.tokens.length - tokens.length;
|
|
29
|
+
}
|
|
30
|
+
trim(pos) {
|
|
31
|
+
this.tokens.splice(pos);
|
|
32
|
+
}
|
|
33
|
+
rewind(tokenNo = -1) {
|
|
34
|
+
if (tokenNo < 0) {
|
|
35
|
+
throw new RangeError('Invalid rewind pos: ' + tokenNo);
|
|
36
|
+
}
|
|
37
|
+
this.currentPos = tokenNo;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Node, Schema } from 'prosemirror-model';
|
|
2
|
+
import { MdConfig } from './ExtensionMarkdown.js';
|
|
3
|
+
export declare function mdToPmConverter(buffer: Uint8Array, config: MdConfig, schema: Schema): Promise<Node>;
|
|
4
|
+
export declare function mdToPmConverterText(content: string, config: MdConfig, schema: Schema): Promise<Node>;
|
|
5
|
+
//# sourceMappingURL=mdToPmConverter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdToPmConverter.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/mdToPmConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAelD,wBAAsB,eAAe,CACnC,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA2Gf"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { DOMParser } from 'prosemirror-model';
|
|
2
|
+
import { elementFromString } from '../../extension-basic-editor/src/ExtensionHtml.js';
|
|
3
|
+
import { MarkdownParser } from './MarkdownParser.js';
|
|
4
|
+
import { sitterTokenizer } from './treeSitterTokenizer.js';
|
|
5
|
+
function listIsTight(tokens, i) {
|
|
6
|
+
while (++i < tokens.length) {
|
|
7
|
+
if (tokens[i].type != 'list_item_open')
|
|
8
|
+
return tokens[i].hidden;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export async function mdToPmConverter(buffer, config, schema) {
|
|
13
|
+
const content = new TextDecoder().decode(buffer);
|
|
14
|
+
return mdToPmConverterText(content, config, schema);
|
|
15
|
+
}
|
|
16
|
+
export async function mdToPmConverterText(content, config, schema) {
|
|
17
|
+
const tokenizer = await sitterTokenizer(config.cdnUrl);
|
|
18
|
+
const defaultMarkdownParser = new MarkdownParser(schema, tokenizer, {
|
|
19
|
+
frontmatter: {
|
|
20
|
+
node: 'frontmatter',
|
|
21
|
+
},
|
|
22
|
+
blockquote: { block: 'blockquote' },
|
|
23
|
+
paragraph: { block: 'paragraph' },
|
|
24
|
+
task_item: { block: 'task_item' },
|
|
25
|
+
task_list: {
|
|
26
|
+
block: 'task_list',
|
|
27
|
+
},
|
|
28
|
+
list_item: { block: 'list_item' },
|
|
29
|
+
bullet_list: {
|
|
30
|
+
block: 'bullet_list',
|
|
31
|
+
getAttrs: (_, tokens, i) => ({ tight: listIsTight(tokens, i) }),
|
|
32
|
+
},
|
|
33
|
+
ordered_list: {
|
|
34
|
+
block: 'ordered_list',
|
|
35
|
+
getAttrs: (tok, tokens, i) => ({
|
|
36
|
+
start: +tok.attrGet('start') || 1,
|
|
37
|
+
tight: listIsTight(tokens, i),
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
dl: {
|
|
41
|
+
block: 'dl',
|
|
42
|
+
},
|
|
43
|
+
dt: {
|
|
44
|
+
block: 'dt',
|
|
45
|
+
},
|
|
46
|
+
dd: {
|
|
47
|
+
block: 'dd',
|
|
48
|
+
},
|
|
49
|
+
heading: {
|
|
50
|
+
block: 'heading',
|
|
51
|
+
getAttrs: (tok) => ({ level: +tok.tag.slice(1) }),
|
|
52
|
+
},
|
|
53
|
+
code_block: { block: 'code_block', noCloseToken: true },
|
|
54
|
+
fence: {
|
|
55
|
+
block: 'code_block',
|
|
56
|
+
getAttrs: (tok) => ({ lang: tok.attrGet('lang') || undefined }),
|
|
57
|
+
noCloseToken: true,
|
|
58
|
+
},
|
|
59
|
+
hr: { node: 'hr' },
|
|
60
|
+
image: {
|
|
61
|
+
node: 'image',
|
|
62
|
+
getAttrs: (tok) => {
|
|
63
|
+
const firstChild = tok.children ? tok.children[0] : undefined;
|
|
64
|
+
return {
|
|
65
|
+
src: tok.attrGet('src'),
|
|
66
|
+
title: tok.attrGet('title') || null,
|
|
67
|
+
alt: firstChild?.content || null,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
hardbreak: { node: 'br' },
|
|
72
|
+
em: { mark: 'em' },
|
|
73
|
+
underline: { mark: 'underline' },
|
|
74
|
+
strong: { mark: 'strong' },
|
|
75
|
+
strike: { mark: 'strike' },
|
|
76
|
+
link: {
|
|
77
|
+
mark: 'link',
|
|
78
|
+
getAttrs: (tok) => ({
|
|
79
|
+
href: tok.attrGet('href'),
|
|
80
|
+
title: tok.attrGet('title') || null,
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
code: { mark: 'code' },
|
|
84
|
+
html_block: {
|
|
85
|
+
custom: (state, token, tokens, i) => {
|
|
86
|
+
const parser = DOMParser.fromSchema(schema);
|
|
87
|
+
const parsed = parser.parse(elementFromString(token.content));
|
|
88
|
+
// state.importNodes(parsed.children); // breaks lsptoy example
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
footnote_ref: {
|
|
92
|
+
block: 'code_block',
|
|
93
|
+
},
|
|
94
|
+
table: {
|
|
95
|
+
block: 'table',
|
|
96
|
+
},
|
|
97
|
+
tr: {
|
|
98
|
+
block: 'table_row',
|
|
99
|
+
},
|
|
100
|
+
td: {
|
|
101
|
+
block: 'table_cell',
|
|
102
|
+
},
|
|
103
|
+
th: {
|
|
104
|
+
block: 'table_header',
|
|
105
|
+
},
|
|
106
|
+
thead: {
|
|
107
|
+
ignore: true,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return defaultMarkdownParser.parse(content);
|
|
111
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node, Schema } from 'prosemirror-model';
|
|
2
|
+
import { type CoreEditor, RawTextResult, SourceMap } from '../../editor/src/mod.js';
|
|
3
|
+
import { MdConfig } from './ExtensionMarkdown.js';
|
|
4
|
+
export interface MdContext {
|
|
5
|
+
meta: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export declare function pmToMdConverter(document: Node, config: MdConfig, schema: Schema, editor: CoreEditor): Promise<Uint8Array>;
|
|
8
|
+
export interface MarkdownResult extends RawTextResult {
|
|
9
|
+
debugMap: Record<number, {
|
|
10
|
+
targetRow: number;
|
|
11
|
+
targetCol: number;
|
|
12
|
+
}>;
|
|
13
|
+
sourceMap?: SourceMap;
|
|
14
|
+
}
|
|
15
|
+
export declare function syncPmToMdConverter(document: Node, config: MdConfig, schema: Schema, editor: CoreEditor): MarkdownResult;
|
|
16
|
+
//# sourceMappingURL=pmToMdConverter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pmToMdConverter.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/pmToMdConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIjE,OAAO,EACL,KAAK,UAAU,EAIf,aAAa,EACb,SAAS,EACV,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AA+ClD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B;AAkCD,wBAAsB,eAAe,CACnC,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnE,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,GACjB,cAAc,CA+ahB"}
|