@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.
- package/LICENSE +23 -0
- package/README.md +82 -0
- 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 +40 -0
- package/esm/editor/src/CoreEditor.d.ts.map +1 -0
- package/esm/editor/src/CoreEditor.js +252 -0
- package/esm/editor/src/DummyEditorView.d.ts +60 -0
- package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
- package/esm/editor/src/DummyEditorView.js +277 -0
- package/esm/editor/src/Extension.d.ts +31 -0
- package/esm/editor/src/Extension.d.ts.map +1 -0
- package/esm/editor/src/Extension.js +53 -0
- package/esm/editor/src/ExtensionManager.d.ts +32 -0
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
- package/esm/editor/src/ExtensionManager.js +260 -0
- package/esm/editor/src/Mark.d.ts +23 -0
- package/esm/editor/src/Mark.d.ts.map +1 -0
- package/esm/editor/src/Mark.js +51 -0
- package/esm/editor/src/Node.d.ts +32 -0
- package/esm/editor/src/Node.d.ts.map +1 -0
- package/esm/editor/src/Node.js +60 -0
- package/esm/editor/src/commands/CommandManager.d.ts +23 -0
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
- package/esm/editor/src/commands/CommandManager.js +118 -0
- 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/createChainableState.d.ts +3 -0
- package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
- package/esm/editor/src/commands/createChainableState.js +29 -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 +7 -0
- package/esm/editor/src/commands/mod.d.ts.map +1 -0
- package/esm/editor/src/commands/mod.js +76 -0
- 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 +9 -0
- package/esm/editor/src/mod.d.ts.map +1 -0
- package/esm/editor/src/mod.js +8 -0
- package/esm/editor/src/nodeToTreeString.d.ts +10 -0
- package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
- package/esm/editor/src/nodeToTreeString.js +74 -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/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/keymap.js +125 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
- package/esm/editor/src/types.d.ts +52 -0
- package/esm/editor/src/types.d.ts.map +1 -0
- package/esm/editor/src/types.js +1 -0
- 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 +41 -0
- package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
- package/esm/editor/src/utilities/SmartOutput.js +228 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
- package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
- package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
- 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 +6 -0
- package/esm/editor/src/utilities/mod.d.ts.map +1 -0
- package/esm/editor/src/utilities/mod.js +5 -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-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/LspWebSocketTransport.d.ts +20 -0
- package/esm/extension-lsp/src/LspWebSocketTransport.d.ts.map +1 -0
- package/esm/extension-lsp/src/LspWebSocketTransport.js +137 -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 +5 -0
- package/esm/extension-lsp/src/mod.d.ts.map +1 -0
- package/esm/extension-lsp/src/mod.js +4 -0
- package/esm/extension-lsp/src/types.d.ts +20 -0
- package/esm/extension-lsp/src/types.d.ts.map +1 -0
- package/esm/extension-lsp/src/types.js +1 -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/package.json +3 -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 +31 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { Mark, } from 'prosemirror-model';
|
|
2
|
+
const __dirname = globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).dirname;
|
|
3
|
+
function maybeMerge(a, b) {
|
|
4
|
+
if (a.isText && b.isText && Mark.sameSet(a.marks, b.marks)) {
|
|
5
|
+
return a.withText(a.text + b.text);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
// Object used to track the context of a running parse.
|
|
9
|
+
export class MarkdownParseState {
|
|
10
|
+
constructor(schema, tokenHandlers) {
|
|
11
|
+
Object.defineProperty(this, "schema", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: schema
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "tokenHandlers", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: tokenHandlers
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "stack", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this.stack = [{
|
|
30
|
+
type: schema.topNodeType,
|
|
31
|
+
attrs: null,
|
|
32
|
+
content: [],
|
|
33
|
+
marks: Mark.none,
|
|
34
|
+
}];
|
|
35
|
+
}
|
|
36
|
+
top() {
|
|
37
|
+
return this.stack[this.stack.length - 1];
|
|
38
|
+
}
|
|
39
|
+
push(elt) {
|
|
40
|
+
if (this.stack.length)
|
|
41
|
+
this.top().content.push(elt);
|
|
42
|
+
}
|
|
43
|
+
// Adds the given text to the current position in the document,
|
|
44
|
+
// using the current marks as styling.
|
|
45
|
+
addText(text) {
|
|
46
|
+
if (!text)
|
|
47
|
+
return;
|
|
48
|
+
let top = this.top(), nodes = top.content, last = nodes[nodes.length - 1];
|
|
49
|
+
let node = this.schema.text(text, top.marks), merged;
|
|
50
|
+
if (last && (merged = maybeMerge(last, node))) {
|
|
51
|
+
nodes[nodes.length - 1] = merged;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
nodes.push(node);
|
|
55
|
+
}
|
|
56
|
+
// Adds the given mark to the set of active marks.
|
|
57
|
+
openMark(mark) {
|
|
58
|
+
let top = this.top();
|
|
59
|
+
top.marks = mark.addToSet(top.marks);
|
|
60
|
+
}
|
|
61
|
+
// Removes the given mark from the set of active marks.
|
|
62
|
+
closeMark(mark) {
|
|
63
|
+
let top = this.top();
|
|
64
|
+
top.marks = mark.removeFromSet(top.marks);
|
|
65
|
+
}
|
|
66
|
+
parseTokens(toks) {
|
|
67
|
+
for (let i = 0; i < toks.length; i++) {
|
|
68
|
+
let tok = toks[i];
|
|
69
|
+
let handler = this.tokenHandlers[tok.type];
|
|
70
|
+
if (!handler) {
|
|
71
|
+
console.log(Object.keys(this.tokenHandlers));
|
|
72
|
+
throw new Error('Token type `' + tok.type + '` not supported by Markdown parser');
|
|
73
|
+
}
|
|
74
|
+
handler(this, tok, toks, i);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Add a node at the current position.
|
|
78
|
+
addNode(type, attrs, content) {
|
|
79
|
+
let top = this.top();
|
|
80
|
+
let node = type.createAndFill(attrs, content, top ? top.marks : []);
|
|
81
|
+
if (!node)
|
|
82
|
+
return null;
|
|
83
|
+
this.push(node);
|
|
84
|
+
return node;
|
|
85
|
+
}
|
|
86
|
+
// Wrap subsequent content in a node of the given type.
|
|
87
|
+
openNode(type, attrs) {
|
|
88
|
+
this.stack.push({
|
|
89
|
+
type: type,
|
|
90
|
+
attrs: attrs,
|
|
91
|
+
content: [],
|
|
92
|
+
marks: Mark.none,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Close and return the node that is currently on top of the stack.
|
|
96
|
+
closeNode() {
|
|
97
|
+
let info = this.stack.pop();
|
|
98
|
+
return this.addNode(info.type, info.attrs, info.content);
|
|
99
|
+
}
|
|
100
|
+
importNodes(nodes) {
|
|
101
|
+
for (const node of nodes) {
|
|
102
|
+
this.push(node);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function attrs(spec, token, tokens, i) {
|
|
107
|
+
if (spec.getAttrs)
|
|
108
|
+
return spec.getAttrs(token, tokens, i);
|
|
109
|
+
// For backwards compatibility when `attrs` is a Function
|
|
110
|
+
else if (spec.attrs instanceof Function)
|
|
111
|
+
return spec.attrs(token);
|
|
112
|
+
else
|
|
113
|
+
return spec.attrs;
|
|
114
|
+
}
|
|
115
|
+
// Code content is represented as a single token with a `content`
|
|
116
|
+
// property in Markdown-it.
|
|
117
|
+
function noCloseToken(spec, type) {
|
|
118
|
+
return spec.noCloseToken || type == 'code_block' ||
|
|
119
|
+
type == 'fence';
|
|
120
|
+
}
|
|
121
|
+
function withoutTrailingNewline(str) {
|
|
122
|
+
return str[str.length - 1] == '\n' ? str.slice(0, str.length - 1) : str;
|
|
123
|
+
}
|
|
124
|
+
function noOp() { }
|
|
125
|
+
function tokenHandlers(schema, tokens) {
|
|
126
|
+
let handlers = Object.create(null);
|
|
127
|
+
for (let type in tokens) {
|
|
128
|
+
let spec = tokens[type];
|
|
129
|
+
if (spec.block) {
|
|
130
|
+
let nodeType = schema.nodes[spec.block];
|
|
131
|
+
if (noCloseToken(spec, type)) {
|
|
132
|
+
handlers[type] = (state, tok, tokens, i) => {
|
|
133
|
+
state.openNode(nodeType, attrs(spec, tok, tokens, i));
|
|
134
|
+
state.addText(withoutTrailingNewline(tok.content));
|
|
135
|
+
state.closeNode();
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
handlers[type + '_open'] = (state, tok, tokens, i) => state.openNode(nodeType, attrs(spec, tok, tokens, i));
|
|
140
|
+
handlers[type + '_close'] = (state) => state.closeNode();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (spec.node) {
|
|
144
|
+
let nodeType = schema.nodes[spec.node];
|
|
145
|
+
handlers[type] = (state, tok, tokens, i) => state.addNode(nodeType, attrs(spec, tok, tokens, i));
|
|
146
|
+
}
|
|
147
|
+
else if (spec.mark) {
|
|
148
|
+
let markType = schema.marks[spec.mark];
|
|
149
|
+
if (noCloseToken(spec, type)) {
|
|
150
|
+
handlers[type] = (state, tok, tokens, i) => {
|
|
151
|
+
state.openMark(markType.create(attrs(spec, tok, tokens, i)));
|
|
152
|
+
state.addText(withoutTrailingNewline(tok.content));
|
|
153
|
+
state.closeMark(markType);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
handlers[type + '_open'] = (state, tok, tokens, i) => state.openMark(markType.create(attrs(spec, tok, tokens, i)));
|
|
158
|
+
handlers[type + '_close'] = (state) => state.closeMark(markType);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (spec.custom) {
|
|
162
|
+
const custom = spec.custom;
|
|
163
|
+
handlers[type] = (state, tok, tokens, i) => {
|
|
164
|
+
custom(state, tok, tokens, i);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
else if (spec.ignore) {
|
|
168
|
+
if (noCloseToken(spec, type)) {
|
|
169
|
+
handlers[type] = noOp;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
handlers[type + '_open'] = noOp;
|
|
173
|
+
handlers[type + '_close'] = noOp;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
throw new RangeError('Unrecognized parsing spec ' + JSON.stringify(spec));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
handlers.text = (state, tok) => state.addText(tok.content);
|
|
181
|
+
handlers.inline = (state, tok) => state.parseTokens(tok.children);
|
|
182
|
+
handlers.softbreak = handlers.softbreak || ((state) => state.addText(' '));
|
|
183
|
+
return handlers;
|
|
184
|
+
}
|
|
185
|
+
/// A configuration of a Markdown parser. Such a parser uses
|
|
186
|
+
/// [markdown-it](https://github.com/markdown-it/markdown-it) to
|
|
187
|
+
/// tokenize a file, and then runs the custom rules it is given over
|
|
188
|
+
/// the tokens to create a ProseMirror document tree.
|
|
189
|
+
export class MarkdownParser {
|
|
190
|
+
/// Create a parser with the given configuration. You can configure
|
|
191
|
+
/// the markdown-it parser to parse the dialect you want, and provide
|
|
192
|
+
/// a description of the ProseMirror entities those tokens map to in
|
|
193
|
+
/// the `tokens` object, which maps token names to descriptions of
|
|
194
|
+
/// what to do with them. Such a description is an object, and may
|
|
195
|
+
/// have the following properties:
|
|
196
|
+
constructor(
|
|
197
|
+
/// The parser's document schema.
|
|
198
|
+
schema,
|
|
199
|
+
/// This parser's markdown-it tokenizer.
|
|
200
|
+
tokenizer,
|
|
201
|
+
/// The value of the `tokens` object used to construct this
|
|
202
|
+
/// parser. Can be useful to copy and modify to base other parsers
|
|
203
|
+
/// on.
|
|
204
|
+
tokens) {
|
|
205
|
+
Object.defineProperty(this, "schema", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
configurable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: schema
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(this, "tokenizer", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: tokenizer
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(this, "tokens", {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
configurable: true,
|
|
220
|
+
writable: true,
|
|
221
|
+
value: tokens
|
|
222
|
+
});
|
|
223
|
+
/// @internal
|
|
224
|
+
Object.defineProperty(this, "tokenHandlers", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
configurable: true,
|
|
227
|
+
writable: true,
|
|
228
|
+
value: void 0
|
|
229
|
+
});
|
|
230
|
+
this.tokenHandlers = tokenHandlers(schema, tokens);
|
|
231
|
+
}
|
|
232
|
+
/// Parse a string as [CommonMark](http://commonmark.org/) markup,
|
|
233
|
+
/// and create a ProseMirror document as prescribed by this parser's
|
|
234
|
+
/// rules.
|
|
235
|
+
///
|
|
236
|
+
/// The second argument, when given, is passed through to the
|
|
237
|
+
/// [Markdown
|
|
238
|
+
/// parser](https://markdown-it.github.io/markdown-it/#MarkdownIt.parse).
|
|
239
|
+
parse(text, markdownEnv = {}) {
|
|
240
|
+
const state = new MarkdownParseState(this.schema, this.tokenHandlers);
|
|
241
|
+
const tokens = this.tokenizer.parse(text, markdownEnv);
|
|
242
|
+
state.parseTokens(tokens);
|
|
243
|
+
let doc;
|
|
244
|
+
do {
|
|
245
|
+
doc = state.closeNode();
|
|
246
|
+
} while (state.stack.length);
|
|
247
|
+
return doc || this.schema.topNodeType.createAndFill();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Token } from './types.js';
|
|
2
|
+
import { TokenSource } from './TokenSource.js';
|
|
3
|
+
import { SmartOutput } from '../../editor/src/utilities/mod.js';
|
|
4
|
+
export declare function writeIndented(output: SmartOutput<Token>, text: string, currentCtx: SerializerContext, token?: Token): void;
|
|
5
|
+
type ListType = 'ul' | 'ol' | 'dl' | 'tl';
|
|
6
|
+
export interface SerializerContext {
|
|
7
|
+
meta: Record<string, any>;
|
|
8
|
+
metaObj: Record<string, any>;
|
|
9
|
+
blockquoteCnt: number;
|
|
10
|
+
footnoteCnt: number;
|
|
11
|
+
listPath: Array<ListType>;
|
|
12
|
+
listType?: ListType;
|
|
13
|
+
itemRow: number;
|
|
14
|
+
itemNumber: number;
|
|
15
|
+
itemSymbol: string;
|
|
16
|
+
handlers: Record<string, Array<TokenHandler>>;
|
|
17
|
+
log: (txt: string, token?: Token) => void;
|
|
18
|
+
debug: (...args: any[]) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare class ContextStash {
|
|
21
|
+
private ctxStash;
|
|
22
|
+
private currentCtx;
|
|
23
|
+
readonly output: SmartOutput<Token>;
|
|
24
|
+
constructor(handlers: Record<string, Array<TokenHandler>>);
|
|
25
|
+
stash(reason: string): number;
|
|
26
|
+
unstash(reason: string): void;
|
|
27
|
+
rollback(rollbackPos: number, reason: string): void;
|
|
28
|
+
get current(): SerializerContext;
|
|
29
|
+
}
|
|
30
|
+
export declare function serializeInlineTokens(ctx: ContextStash, tokenSource: TokenSource<Token>, tokens: Token[]): void;
|
|
31
|
+
export type TokenHandler = (token: Token, ctx: ContextStash, tokenSource: TokenSource<Token>) => boolean | void;
|
|
32
|
+
export interface MarkdownSerializerConfig {
|
|
33
|
+
debug?: (...args: any[]) => void;
|
|
34
|
+
}
|
|
35
|
+
export declare class MarkdownSerializer {
|
|
36
|
+
private ctx;
|
|
37
|
+
constructor(config?: MarkdownSerializerConfig);
|
|
38
|
+
private get endsWithEmptyLine();
|
|
39
|
+
serialize(tokens: Token[]): SmartOutput<Token>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=MarkdownSerializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownSerializer.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/MarkdownSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAOzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAEhE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,EAC1B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,iBAAiB,EAC7B,KAAK,CAAC,EAAE,KAAK,QAmGd;AAED,KAAK,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IAEnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;IAC9C,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAC1C,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjC;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,UAAU,CAAoB;IACtC,SAAgB,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;gBAE/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAmBlD,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IA2B7B,OAAO,CAAC,MAAM,EAAE,MAAM;IAWtB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAWnD,IAAI,OAAO,sBAEV;CACF;AAED,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,YAAY,EACjB,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,EAC/B,MAAM,EAAE,KAAK,EAAE,QAgChB;AAED,MAAM,MAAM,YAAY,GAAG,CACzB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,YAAY,EACjB,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,KAC5B,OAAO,GAAG,IAAI,CAAC;AAEpB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAClC;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAe;gBAEd,MAAM,GAAE,wBAA6B;IAcjD,OAAO,KAAK,iBAAiB,GAE5B;IAED,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,KAAK,CAAC;CAiH/C"}
|
|
@@ -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"}
|