@pyreon/code 0.6.0 → 0.7.0

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.
@@ -1,635 +0,0 @@
1
- import { d as NodeType, h as parseMixed, l as NodeProp, m as Tree, n as styleTags, p as Parser, r as tags, t as Tag, u as NodeSet } from "./dist.js";
2
- import { html, htmlCompletionSource } from "./dist6.js";
3
- import { Language, LanguageDescription, LanguageSupport, ParseContext, defineLanguageFacet, foldNodeProp, foldService, indentNodeProp, indentUnit, languageDataProp, syntaxTree } from "@codemirror/language";
4
- import { EditorSelection, EditorState, Prec, countColumn } from "@codemirror/state";
5
- import { EditorView, keymap } from "@codemirror/view";
6
- import { CompletionContext } from "@codemirror/autocomplete";
7
-
8
- //#region ../../node_modules/.bun/@lezer+markdown@1.6.3/node_modules/@lezer/markdown/dist/index.js
9
-
10
- function skipForList(bl, cx, line) {
11
- if (line.pos == line.text.length || bl != cx.block && line.indent >= cx.stack[line.depth + 1].value + line.baseIndent) return true;
12
- if (line.indent >= line.baseIndent + 4) return false;
13
- let size = (bl.type == Type.OrderedList ? isOrderedList : isBulletList)(line, cx, false);
14
- return size > 0 && (bl.type != Type.BulletList || isHorizontalRule(line, cx, false) < 0) && line.text.charCodeAt(line.pos + size - 1) == bl.value;
15
- }
16
- function space(ch) {
17
- return ch == 32 || ch == 9 || ch == 10 || ch == 13;
18
- }
19
- function skipSpace(line, i = 0) {
20
- while (i < line.length && space(line.charCodeAt(i))) i++;
21
- return i;
22
- }
23
- function skipSpaceBack(line, i, to) {
24
- while (i > to && space(line.charCodeAt(i - 1))) i--;
25
- return i;
26
- }
27
- function isFencedCode(line) {
28
- if (line.next != 96 && line.next != 126) return -1;
29
- let pos = line.pos + 1;
30
- while (pos < line.text.length && line.text.charCodeAt(pos) == line.next) pos++;
31
- if (pos < line.pos + 3) return -1;
32
- if (line.next == 96) {
33
- for (let i = pos; i < line.text.length; i++) if (line.text.charCodeAt(i) == 96) return -1;
34
- }
35
- return pos;
36
- }
37
- function isBlockquote(line) {
38
- return line.next != 62 ? -1 : line.text.charCodeAt(line.pos + 1) == 32 ? 2 : 1;
39
- }
40
- function isHorizontalRule(line, cx, breaking) {
41
- if (line.next != 42 && line.next != 45 && line.next != 95) return -1;
42
- let count = 1;
43
- for (let pos = line.pos + 1; pos < line.text.length; pos++) {
44
- let ch = line.text.charCodeAt(pos);
45
- if (ch == line.next) count++;else if (!space(ch)) return -1;
46
- }
47
- if (breaking && line.next == 45 && isSetextUnderline(line) > -1 && line.depth == cx.stack.length && cx.parser.leafBlockParsers.indexOf(DefaultLeafBlocks.SetextHeading) > -1) return -1;
48
- return count < 3 ? -1 : 1;
49
- }
50
- function inList(cx, type) {
51
- for (let i = cx.stack.length - 1; i >= 0; i--) if (cx.stack[i].type == type) return true;
52
- return false;
53
- }
54
- function isBulletList(line, cx, breaking) {
55
- return (line.next == 45 || line.next == 43 || line.next == 42) && (line.pos == line.text.length - 1 || space(line.text.charCodeAt(line.pos + 1))) && (!breaking || inList(cx, Type.BulletList) || line.skipSpace(line.pos + 2) < line.text.length) ? 1 : -1;
56
- }
57
- function isOrderedList(line, cx, breaking) {
58
- let pos = line.pos,
59
- next = line.next;
60
- for (;;) {
61
- if (next >= 48 && next <= 57) pos++;else break;
62
- if (pos == line.text.length) return -1;
63
- next = line.text.charCodeAt(pos);
64
- }
65
- if (pos == line.pos || pos > line.pos + 9 || next != 46 && next != 41 || pos < line.text.length - 1 && !space(line.text.charCodeAt(pos + 1)) || breaking && !inList(cx, Type.OrderedList) && (line.skipSpace(pos + 1) == line.text.length || pos > line.pos + 1 || line.next != 49)) return -1;
66
- return pos + 1 - line.pos;
67
- }
68
- function isAtxHeading(line) {
69
- if (line.next != 35) return -1;
70
- let pos = line.pos + 1;
71
- while (pos < line.text.length && line.text.charCodeAt(pos) == 35) pos++;
72
- if (pos < line.text.length && line.text.charCodeAt(pos) != 32) return -1;
73
- let size = pos - line.pos;
74
- return size > 6 ? -1 : size;
75
- }
76
- function isSetextUnderline(line) {
77
- if (line.next != 45 && line.next != 61 || line.indent >= line.baseIndent + 4) return -1;
78
- let pos = line.pos + 1;
79
- while (pos < line.text.length && line.text.charCodeAt(pos) == line.next) pos++;
80
- let end = pos;
81
- while (pos < line.text.length && space(line.text.charCodeAt(pos))) pos++;
82
- return pos == line.text.length ? end : -1;
83
- }
84
- function isHTMLBlock(line, _cx, breaking) {
85
- if (line.next != 60) return -1;
86
- let rest = line.text.slice(line.pos);
87
- for (let i = 0, e = HTMLBlockStyle.length - (breaking ? 1 : 0); i < e; i++) if (HTMLBlockStyle[i][0].test(rest)) return i;
88
- return -1;
89
- }
90
- function getListIndent(line, pos) {
91
- let indentAfter = line.countIndent(pos, line.pos, line.indent);
92
- let indented = line.countIndent(line.skipSpace(pos), pos, indentAfter);
93
- return indented >= indentAfter + 5 ? indentAfter + 1 : indented;
94
- }
95
- function addCodeText(marks, from, to) {
96
- let last = marks.length - 1;
97
- if (last >= 0 && marks[last].to == from && marks[last].type == Type.CodeText) marks[last].to = to;else marks.push(elt(Type.CodeText, from, to));
98
- }
99
- function lineEnd(text, pos) {
100
- for (; pos < text.length; pos++) {
101
- let next = text.charCodeAt(pos);
102
- if (next == 10) break;
103
- if (!space(next)) return -1;
104
- }
105
- return pos;
106
- }
107
- function injectGaps(ranges, rangeI, tree, offset, dummies) {
108
- let rangeEnd = ranges[rangeI].to;
109
- let children = [],
110
- positions = [],
111
- start = tree.from + offset;
112
- function movePastNext(upto, inclusive) {
113
- while (inclusive ? upto >= rangeEnd : upto > rangeEnd) {
114
- let size = ranges[rangeI + 1].from - rangeEnd;
115
- offset += size;
116
- upto += size;
117
- rangeI++;
118
- rangeEnd = ranges[rangeI].to;
119
- }
120
- }
121
- for (let ch = tree.firstChild; ch; ch = ch.nextSibling) {
122
- movePastNext(ch.from + offset, true);
123
- let from = ch.from + offset,
124
- node,
125
- reuse = dummies.get(ch.tree);
126
- if (reuse) node = reuse;else if (ch.to + offset > rangeEnd) {
127
- node = injectGaps(ranges, rangeI, ch, offset, dummies);
128
- movePastNext(ch.to + offset, false);
129
- } else node = ch.toTree();
130
- children.push(node);
131
- positions.push(from - start);
132
- }
133
- movePastNext(tree.to + offset, false);
134
- return new Tree(tree.type, children, positions, tree.to + offset - start, tree.tree ? tree.tree.propValues : void 0);
135
- }
136
- /**
137
- A Markdown parser configuration.
138
- */
139
-
140
- function nonEmpty(a) {
141
- return a != null && a.length > 0;
142
- }
143
- function resolveConfig(spec) {
144
- if (!Array.isArray(spec)) return spec;
145
- if (spec.length == 0) return null;
146
- let conf = resolveConfig(spec[0]);
147
- if (spec.length == 1) return conf;
148
- let rest = resolveConfig(spec.slice(1));
149
- if (!rest || !conf) return conf || rest;
150
- let conc = (a, b) => (a || none).concat(b || none);
151
- let wrapA = conf.wrap,
152
- wrapB = rest.wrap;
153
- return {
154
- props: conc(conf.props, rest.props),
155
- defineNodes: conc(conf.defineNodes, rest.defineNodes),
156
- parseBlock: conc(conf.parseBlock, rest.parseBlock),
157
- parseInline: conc(conf.parseInline, rest.parseInline),
158
- remove: conc(conf.remove, rest.remove),
159
- wrap: !wrapA ? wrapB : !wrapB ? wrapA : (inner, input, fragments, ranges) => wrapA(wrapB(inner, input, fragments, ranges), input, fragments, ranges)
160
- };
161
- }
162
- function findName(names, name) {
163
- let found = names.indexOf(name);
164
- if (found < 0) throw new RangeError(`Position specified relative to unknown parser ${name}`);
165
- return found;
166
- }
167
- for (let i = 1, name; name = Type[i]; i++) nodeTypes[i] = NodeType.define({
168
- id: i,
169
- name,
170
- props: i >= Type.Escape ? [] : [[NodeProp.group, i in DefaultSkipMarkup ? ["Block", "BlockContext"] : ["Block", "LeafBlock"]]],
171
- top: name == "Document"
172
- });
173
- function elt(type, from, to, children) {
174
- return new Element(type, from, to, children);
175
- }
176
- try {
177
- Punctuation = /* @__PURE__ */new RegExp("[\\p{S}|\\p{P}]", "u");
178
- } catch (_) {}
179
- function finishLink(cx, content, type, start, startPos) {
180
- let {
181
- text
182
- } = cx,
183
- next = cx.char(startPos),
184
- endPos = startPos;
185
- content.unshift(elt(Type.LinkMark, start, start + (type == Type.Image ? 2 : 1)));
186
- content.push(elt(Type.LinkMark, startPos - 1, startPos));
187
- if (next == 40) {
188
- let pos = cx.skipSpace(startPos + 1);
189
- let dest = parseURL(text, pos - cx.offset, cx.offset),
190
- title;
191
- if (dest) {
192
- pos = cx.skipSpace(dest.to);
193
- if (pos != dest.to) {
194
- title = parseLinkTitle(text, pos - cx.offset, cx.offset);
195
- if (title) pos = cx.skipSpace(title.to);
196
- }
197
- }
198
- if (cx.char(pos) == 41) {
199
- content.push(elt(Type.LinkMark, startPos, startPos + 1));
200
- endPos = pos + 1;
201
- if (dest) content.push(dest);
202
- if (title) content.push(title);
203
- content.push(elt(Type.LinkMark, pos, endPos));
204
- }
205
- } else if (next == 91) {
206
- let label = parseLinkLabel(text, startPos - cx.offset, cx.offset, false);
207
- if (label) {
208
- content.push(label);
209
- endPos = label.to;
210
- }
211
- }
212
- return elt(type, start, endPos, content);
213
- }
214
- function parseURL(text, start, offset) {
215
- if (text.charCodeAt(start) == 60) {
216
- for (let pos = start + 1; pos < text.length; pos++) {
217
- let ch = text.charCodeAt(pos);
218
- if (ch == 62) return elt(Type.URL, start + offset, pos + 1 + offset);
219
- if (ch == 60 || ch == 10) return false;
220
- }
221
- return null;
222
- } else {
223
- let depth = 0,
224
- pos = start;
225
- for (let escaped = false; pos < text.length; pos++) {
226
- let ch = text.charCodeAt(pos);
227
- if (space(ch)) break;else if (escaped) escaped = false;else if (ch == 40) depth++;else if (ch == 41) {
228
- if (!depth) break;
229
- depth--;
230
- } else if (ch == 92) escaped = true;
231
- }
232
- return pos > start ? elt(Type.URL, start + offset, pos + offset) : pos == text.length ? null : false;
233
- }
234
- }
235
- function parseLinkTitle(text, start, offset) {
236
- let next = text.charCodeAt(start);
237
- if (next != 39 && next != 34 && next != 40) return false;
238
- let end = next == 40 ? 41 : next;
239
- for (let pos = start + 1, escaped = false; pos < text.length; pos++) {
240
- let ch = text.charCodeAt(pos);
241
- if (escaped) escaped = false;else if (ch == end) return elt(Type.LinkTitle, start + offset, pos + 1 + offset);else if (ch == 92) escaped = true;
242
- }
243
- return null;
244
- }
245
- function parseLinkLabel(text, start, offset, requireNonWS) {
246
- for (let escaped = false, pos = start + 1, end = Math.min(text.length, pos + 999); pos < end; pos++) {
247
- let ch = text.charCodeAt(pos);
248
- if (escaped) escaped = false;else if (ch == 93) return requireNonWS ? false : elt(Type.LinkLabel, start + offset, pos + 1 + offset);else {
249
- if (requireNonWS && !space(ch)) requireNonWS = false;
250
- if (ch == 91) return false;else if (ch == 92) escaped = true;
251
- }
252
- }
253
- return null;
254
- }
255
- /**
256
- Inline parsing functions get access to this context, and use it to
257
- read the content and emit syntax nodes.
258
- */
259
-
260
- function injectMarks(elements, marks) {
261
- if (!marks.length) return elements;
262
- if (!elements.length) return marks;
263
- let elts = elements.slice(),
264
- eI = 0;
265
- for (let mark of marks) {
266
- while (eI < elts.length && elts[eI].to < mark.to) eI++;
267
- if (eI < elts.length && elts[eI].from < mark.from) {
268
- let e = elts[eI];
269
- if (e instanceof Element) elts[eI] = new Element(e.type, e.from, e.to, injectMarks(e.children, [mark]));
270
- } else elts.splice(eI++, 0, mark);
271
- }
272
- return elts;
273
- }
274
- function toRelative(abs, ranges) {
275
- let pos = abs;
276
- for (let i = 1; i < ranges.length; i++) {
277
- let gapFrom = ranges[i - 1].to,
278
- gapTo = ranges[i].from;
279
- if (gapFrom < abs) pos -= gapTo - gapFrom;
280
- }
281
- return pos;
282
- }
283
- function leftOverSpace(node, from, to) {
284
- let ranges = [];
285
- for (let n = node.firstChild, pos = from;; n = n.nextSibling) {
286
- let nextPos = n ? n.from : to;
287
- if (nextPos > pos) ranges.push({
288
- from: pos,
289
- to: nextPos
290
- });
291
- if (!n) break;
292
- pos = n.to;
293
- }
294
- return ranges;
295
- }
296
- /**
297
- Create a Markdown extension to enable nested parsing on code
298
- blocks and/or embedded HTML.
299
- */
300
- function parseCode(config) {
301
- let {
302
- codeParser,
303
- htmlParser
304
- } = config;
305
- return {
306
- wrap: parseMixed((node, input) => {
307
- let id = node.type.id;
308
- if (codeParser && (id == Type.CodeBlock || id == Type.FencedCode)) {
309
- let info = "";
310
- if (id == Type.FencedCode) {
311
- let infoNode = node.node.getChild(Type.CodeInfo);
312
- if (infoNode) info = input.read(infoNode.from, infoNode.to);
313
- }
314
- let parser = codeParser(info);
315
- if (parser) return {
316
- parser,
317
- overlay: node => node.type.id == Type.CodeText,
318
- bracketed: id == Type.FencedCode
319
- };
320
- } else if (htmlParser && (id == Type.HTMLBlock || id == Type.HTMLTag || id == Type.CommentBlock)) return {
321
- parser: htmlParser,
322
- overlay: leftOverSpace(node.node, node.from, node.to)
323
- };
324
- return null;
325
- })
326
- };
327
- }
328
- function parseRow(cx, line, startI = 0, elts, offset = 0) {
329
- let count = 0,
330
- first = true,
331
- cellStart = -1,
332
- cellEnd = -1,
333
- esc = false;
334
- let parseCell = () => {
335
- elts.push(cx.elt("TableCell", offset + cellStart, offset + cellEnd, cx.parser.parseInline(line.slice(cellStart, cellEnd), offset + cellStart)));
336
- };
337
- for (let i = startI; i < line.length; i++) {
338
- let next = line.charCodeAt(i);
339
- if (next == 124 && !esc) {
340
- if (!first || cellStart > -1) count++;
341
- first = false;
342
- if (elts) {
343
- if (cellStart > -1) parseCell();
344
- elts.push(cx.elt("TableDelimiter", i + offset, i + offset + 1));
345
- }
346
- cellStart = cellEnd = -1;
347
- } else if (esc || next != 32 && next != 9) {
348
- if (cellStart < 0) cellStart = i;
349
- cellEnd = i + 1;
350
- }
351
- esc = !esc && next == 92;
352
- }
353
- if (cellStart > -1) {
354
- count++;
355
- if (elts) parseCell();
356
- }
357
- return count;
358
- }
359
- function hasPipe(str, start) {
360
- for (let i = start; i < str.length; i++) {
361
- let next = str.charCodeAt(i);
362
- if (next == 124) return true;
363
- if (next == 92) i++;
364
- }
365
- return false;
366
- }
367
- function count(str, from, to, ch) {
368
- let result = 0;
369
- for (let i = from; i < to; i++) if (str[i] == ch) result++;
370
- return result;
371
- }
372
- function autolinkURLEnd(text, from) {
373
- urlRE.lastIndex = from;
374
- let m = urlRE.exec(text);
375
- if (!m || lastTwoDomainWords.exec(m[0])[0].indexOf("_") > -1) return -1;
376
- let end = from + m[0].length;
377
- for (;;) {
378
- let last = text[end - 1],
379
- m;
380
- if (/[?!.,:*_~]/.test(last) || last == ")" && count(text, from, end, ")") > count(text, from, end, "(")) end--;else if (last == ";" && (m = /&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(text.slice(from, end)))) end = from + m.index;else break;
381
- }
382
- return end;
383
- }
384
- function autolinkEmailEnd(text, from) {
385
- emailRE.lastIndex = from;
386
- let m = emailRE.exec(text);
387
- if (!m) return -1;
388
- let last = m[0][m[0].length - 1];
389
- return last == "_" || last == "-" ? -1 : from + m[0].length - (last == "." ? 1 : 0);
390
- }
391
- /**
392
- Extension that implements autolinking for
393
- `www.`/`http://`/`https://`/`mailto:`/`xmpp:` URLs and email
394
- addresses.
395
- */
396
-
397
- function parseSubSuper(ch, node, mark) {
398
- return (cx, next, pos) => {
399
- if (next != ch || cx.char(pos + 1) == ch) return -1;
400
- let elts = [cx.elt(mark, pos, pos + 1)];
401
- for (let i = pos + 1; i < cx.end; i++) {
402
- let next = cx.char(i);
403
- if (next == ch) return cx.addElement(cx.elt(node, pos, i + 1, elts.concat(cx.elt(mark, i, i + 1))));
404
- if (next == 92) elts.push(cx.elt("Escape", i, i++ + 2));
405
- if (space(next)) break;
406
- }
407
- return -1;
408
- };
409
- }
410
- /**
411
- Extension providing
412
- [Pandoc-style](https://pandoc.org/MANUAL.html#superscripts-and-subscripts)
413
- superscript using `^` markers.
414
- */
415
-
416
- function isHeading(type) {
417
- let match = /^(?:ATX|Setext)Heading(\d)$/.exec(type.name);
418
- return match ? +match[1] : void 0;
419
- }
420
- function isList(type) {
421
- return type.name == "OrderedList" || type.name == "BulletList";
422
- }
423
- function findSectionEnd(headerNode, level) {
424
- let last = headerNode;
425
- for (;;) {
426
- let next = last.nextSibling,
427
- heading;
428
- if (!next || (heading = isHeading(next.type)) != null && heading <= level) break;
429
- last = next;
430
- }
431
- return last.to;
432
- }
433
- function mkLang(parser) {
434
- return new Language(data, parser, [], "markdown");
435
- }
436
- /**
437
- Language support for strict CommonMark.
438
- */
439
-
440
- function getCodeParser(languages, defaultLanguage) {
441
- return info => {
442
- if (info && languages) {
443
- let found = null;
444
- info = /\S*/.exec(info)[0];
445
- if (typeof languages == "function") found = languages(info);else found = LanguageDescription.matchLanguageName(languages, info, true);
446
- if (found instanceof LanguageDescription) return found.support ? found.support.language.parser : ParseContext.getSkippingParser(found.load());else if (found) return found.parser;
447
- }
448
- return defaultLanguage ? defaultLanguage.parser : null;
449
- };
450
- }
451
- function getContext(node, doc) {
452
- let nodes = [],
453
- context = [];
454
- for (let cur = node; cur; cur = cur.parent) {
455
- if (cur.name == "FencedCode") return context;
456
- if (cur.name == "ListItem" || cur.name == "Blockquote") nodes.push(cur);
457
- }
458
- for (let i = nodes.length - 1; i >= 0; i--) {
459
- let node = nodes[i],
460
- match;
461
- let line = doc.lineAt(node.from),
462
- startPos = node.from - line.from;
463
- if (node.name == "Blockquote" && (match = /^ *>( ?)/.exec(line.text.slice(startPos)))) context.push(new Context(node, startPos, startPos + match[0].length, "", match[1], ">", null));else if (node.name == "ListItem" && node.parent.name == "OrderedList" && (match = /^( *)\d+([.)])( *)/.exec(line.text.slice(startPos)))) {
464
- let after = match[3],
465
- len = match[0].length;
466
- if (after.length >= 4) {
467
- after = after.slice(0, after.length - 4);
468
- len -= 4;
469
- }
470
- context.push(new Context(node.parent, startPos, startPos + len, match[1], after, match[2], node));
471
- } else if (node.name == "ListItem" && node.parent.name == "BulletList" && (match = /^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(line.text.slice(startPos)))) {
472
- let after = match[4],
473
- len = match[0].length;
474
- if (after.length > 4) {
475
- after = after.slice(0, after.length - 4);
476
- len -= 4;
477
- }
478
- let type = match[2];
479
- if (match[3]) type += match[3].replace(/[xX]/, " ");
480
- context.push(new Context(node.parent, startPos, startPos + len, match[1], after, type, node));
481
- }
482
- }
483
- return context;
484
- }
485
- function itemNumber(item, doc) {
486
- return /^(\s*)(\d+)(?=[.)])/.exec(doc.sliceString(item.from, item.from + 10));
487
- }
488
- function renumberList(after, doc, changes, offset = 0) {
489
- for (let prev = -1, node = after;;) {
490
- if (node.name == "ListItem") {
491
- let m = itemNumber(node, doc);
492
- let number = +m[2];
493
- if (prev >= 0) {
494
- if (number != prev + 1) return;
495
- changes.push({
496
- from: node.from + m[1].length,
497
- to: node.from + m[0].length,
498
- insert: String(prev + 2 + offset)
499
- });
500
- }
501
- prev = number;
502
- }
503
- let next = node.nextSibling;
504
- if (!next) break;
505
- node = next;
506
- }
507
- }
508
- function normalizeIndent(content, state) {
509
- let blank = /^[ \t]*/.exec(content)[0].length;
510
- if (!blank || state.facet(indentUnit) != " ") return content;
511
- let col = countColumn(content, 4, blank);
512
- let space = "";
513
- for (let i = col; i > 0;) if (i >= 4) {
514
- space += " ";
515
- i -= 4;
516
- } else {
517
- space += " ";
518
- i--;
519
- }
520
- return space + content.slice(blank);
521
- }
522
- /**
523
- Returns a command like
524
- [`insertNewlineContinueMarkup`](https://codemirror.net/6/docs/ref/#lang-markdown.insertNewlineContinueMarkup),
525
- allowing further configuration.
526
- */
527
-
528
- function isMark(node) {
529
- return node.name == "QuoteMark" || node.name == "ListMark";
530
- }
531
- function nonTightList(node, doc) {
532
- if (node.name != "OrderedList" && node.name != "BulletList") return false;
533
- let first = node.firstChild,
534
- second = node.getChild("ListItem", "ListItem");
535
- if (!second) return false;
536
- let line1 = doc.lineAt(first.to),
537
- line2 = doc.lineAt(second.from);
538
- let empty = /^[\s>]*$/.test(line1.text);
539
- return line1.number + (empty ? 0 : 1) < line2.number;
540
- }
541
- function blankLine(context, state, line) {
542
- let insert = "";
543
- for (let i = 0, e = context.length - 2; i <= e; i++) insert += context[i].blank(i < e ? countColumn(line.text, 4, context[i + 1].from) - insert.length : null, i < e);
544
- return normalizeIndent(insert, state);
545
- }
546
- function contextNodeForDelete(tree, pos) {
547
- let node = tree.resolveInner(pos, -1),
548
- scan = pos;
549
- if (isMark(node)) {
550
- scan = node.from;
551
- node = node.parent;
552
- }
553
- for (let prev; prev = node.childBefore(scan);) if (isMark(prev)) scan = prev.from;else if (prev.name == "OrderedList" || prev.name == "BulletList") {
554
- node = prev.lastChild;
555
- scan = node.to;
556
- } else break;
557
- return node;
558
- }
559
- /**
560
- This command will, when invoked in a Markdown context with the
561
- cursor directly after list or blockquote markup, delete one level
562
- of markup. When the markup is for a list, it will be replaced by
563
- spaces on the first invocation (a further invocation will delete
564
- the spaces), to make it easy to continue a list.
565
-
566
- When not after Markdown block markup, this command will return
567
- false, so it is intended to be bound alongside other deletion
568
- commands, with a higher precedence than the more generic commands.
569
- */
570
-
571
- /**
572
- Markdown language support.
573
- */
574
- function markdown(config = {}) {
575
- let {
576
- codeLanguages,
577
- defaultCodeLanguage,
578
- addKeymap = true,
579
- base: {
580
- parser
581
- } = commonmarkLanguage,
582
- completeHTMLTags = true,
583
- pasteURLAsLink: pasteURL = true,
584
- htmlTagLanguage = htmlNoMatch
585
- } = config;
586
- if (!(parser instanceof MarkdownParser)) throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");
587
- let extensions = config.extensions ? [config.extensions] : [];
588
- let support = [htmlTagLanguage.support, headerIndent],
589
- defaultCode;
590
- if (pasteURL) support.push(pasteURLAsLink);
591
- if (defaultCodeLanguage instanceof LanguageSupport) {
592
- support.push(defaultCodeLanguage.support);
593
- defaultCode = defaultCodeLanguage.language;
594
- } else if (defaultCodeLanguage) defaultCode = defaultCodeLanguage;
595
- let codeParser = codeLanguages || defaultCode ? getCodeParser(codeLanguages, defaultCode) : void 0;
596
- extensions.push(parseCode({
597
- codeParser,
598
- htmlParser: htmlTagLanguage.language.parser
599
- }));
600
- if (addKeymap) support.push(Prec.high(keymap.of(markdownKeymap)));
601
- let lang = mkLang(parser.configure(extensions));
602
- if (completeHTMLTags) support.push(lang.data.of({
603
- autocomplete: htmlTagCompletion
604
- }));
605
- return new LanguageSupport(lang, support);
606
- }
607
- function htmlTagCompletion(context) {
608
- let {
609
- state,
610
- pos
611
- } = context,
612
- m = /<[:\-\.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos));
613
- if (!m) return null;
614
- let tree = syntaxTree(state).resolveInner(pos, -1);
615
- while (tree && !tree.type.isTop) {
616
- if (tree.name == "CodeBlock" || tree.name == "FencedCode" || tree.name == "ProcessingInstructionBlock" || tree.name == "CommentBlock" || tree.name == "Link" || tree.name == "Image") return null;
617
- tree = tree.parent;
618
- }
619
- return {
620
- from: pos - m[0].length,
621
- to: pos,
622
- options: htmlTagCompletions(),
623
- validFor: /^<[:\-\.\w\u00b7-\uffff]*$/
624
- };
625
- }
626
- function htmlTagCompletions() {
627
- if (_tagCompletions) return _tagCompletions;
628
- let result = htmlCompletionSource(new CompletionContext(EditorState.create({
629
- extensions: htmlNoMatch
630
- }), 0, true));
631
- return _tagCompletions = result ? result.options : [];
632
- }
633
- //#endregion
634
- export { markdown };
635
- //# sourceMappingURL=dist9.d.ts.map