@hpcc-js/observablehq-compiler 3.4.0 → 3.5.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.
- package/dist/dot-DK4iDc2-.js +40 -0
- package/dist/dot-DK4iDc2-.js.map +1 -0
- package/dist/duckdb-DkM9_nXT.js +298 -0
- package/dist/duckdb-DkM9_nXT.js.map +1 -0
- package/dist/highlight-Bv8PkwN-.js +2402 -0
- package/dist/highlight-Bv8PkwN-.js.map +1 -0
- package/dist/index-B7vRtYlU.js +1807 -0
- package/dist/index-B7vRtYlU.js.map +1 -0
- package/dist/index-COHaJzee.js +260 -0
- package/dist/index-COHaJzee.js.map +1 -0
- package/dist/index-CP3HrqN0.js +1815 -0
- package/dist/index-CP3HrqN0.js.map +1 -0
- package/dist/index-D3TL70UM.js +163 -0
- package/dist/index-D3TL70UM.js.map +1 -0
- package/dist/index-DNwLE6Kk.js +198 -0
- package/dist/index-DNwLE6Kk.js.map +1 -0
- package/dist/index.js +4381 -4944
- package/dist/index.js.map +1 -1
- package/dist/inputs-CsCXZHQ8.js +3 -0
- package/dist/inputs-CsCXZHQ8.js.map +1 -0
- package/dist/leaflet-CkvVhxBL.js +9 -0
- package/dist/leaflet-CkvVhxBL.js.map +1 -0
- package/dist/mapboxgl-C0i2HzjJ.js +9 -0
- package/dist/mapboxgl-C0i2HzjJ.js.map +1 -0
- package/dist/md-Bxvu6Hld.js +7603 -0
- package/dist/md-Bxvu6Hld.js.map +1 -0
- package/dist/mermaid-CFg6sgdO.js +17 -0
- package/dist/mermaid-CFg6sgdO.js.map +1 -0
- package/dist/node/index.cjs +10 -6
- package/dist/node/index.cjs.map +4 -4
- package/dist/node/index.js +8 -4
- package/dist/node/index.js.map +4 -4
- package/dist/runtime.js +2501 -0
- package/dist/runtime.js.map +1 -0
- package/dist/tex-ayRXOMLZ.js +24 -0
- package/dist/tex-ayRXOMLZ.js.map +1 -0
- package/dist/vega-lite-CESXoehe.js +8 -0
- package/dist/vega-lite-CESXoehe.js.map +1 -0
- package/package.json +12 -10
- package/src/__package__.ts +2 -2
- package/src/compiler.ts +2 -16
- package/src/cst.ts +1 -2
- package/src/index.ts +2 -3
- package/src/kit/compiler.ts +41 -0
- package/src/kit/index.ts +3 -0
- package/src/kit/runtime.ts +57 -0
- package/src/kit/util.ts +157 -0
- package/src/util.ts +1 -134
- package/types/compiler.d.ts +1 -3
- package/types/index.d.ts +2 -2
- package/types/kit/compiler.d.ts +6 -0
- package/types/kit/index.d.ts +3 -0
- package/types/kit/runtime.d.ts +13 -0
- package/types/kit/util.d.ts +52 -0
- package/types/util.d.ts +1 -49
- package/dist/index.umd.cjs +0 -5
- package/dist/index.umd.cjs.map +0 -1
- package/dist/node/index.css +0 -2
- package/dist/node/index.css.map +0 -7
- package/src/index.css +0 -460
|
@@ -0,0 +1,1815 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { N as NodeSet, a as NodeType, s as styleTags, P as Parser, b as NodeProp, c as Tag, T as Tree, t as tags } from "./highlight-Bv8PkwN-.js";
|
|
4
|
+
const _CompositeBlock = class _CompositeBlock {
|
|
5
|
+
static create(type, value, from, parentHash, end) {
|
|
6
|
+
let hash = parentHash + (parentHash << 8) + type + (value << 4) | 0;
|
|
7
|
+
return new _CompositeBlock(type, value, from, hash, end, [], []);
|
|
8
|
+
}
|
|
9
|
+
constructor(type, value, from, hash, end, children, positions) {
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.value = value;
|
|
12
|
+
this.from = from;
|
|
13
|
+
this.hash = hash;
|
|
14
|
+
this.end = end;
|
|
15
|
+
this.children = children;
|
|
16
|
+
this.positions = positions;
|
|
17
|
+
this.hashProp = [[NodeProp.contextHash, hash]];
|
|
18
|
+
}
|
|
19
|
+
addChild(child, pos) {
|
|
20
|
+
if (child.prop(NodeProp.contextHash) != this.hash)
|
|
21
|
+
child = new Tree(child.type, child.children, child.positions, child.length, this.hashProp);
|
|
22
|
+
this.children.push(child);
|
|
23
|
+
this.positions.push(pos);
|
|
24
|
+
}
|
|
25
|
+
toTree(nodeSet, end = this.end) {
|
|
26
|
+
let last = this.children.length - 1;
|
|
27
|
+
if (last >= 0)
|
|
28
|
+
end = Math.max(end, this.positions[last] + this.children[last].length + this.from);
|
|
29
|
+
return new Tree(nodeSet.types[this.type], this.children, this.positions, end - this.from).balance({
|
|
30
|
+
makeTree: /* @__PURE__ */ __name((children, positions, length) => new Tree(NodeType.none, children, positions, length, this.hashProp), "makeTree")
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
__name(_CompositeBlock, "CompositeBlock");
|
|
35
|
+
let CompositeBlock = _CompositeBlock;
|
|
36
|
+
var Type;
|
|
37
|
+
(function(Type2) {
|
|
38
|
+
Type2[Type2["Document"] = 1] = "Document";
|
|
39
|
+
Type2[Type2["CodeBlock"] = 2] = "CodeBlock";
|
|
40
|
+
Type2[Type2["FencedCode"] = 3] = "FencedCode";
|
|
41
|
+
Type2[Type2["Blockquote"] = 4] = "Blockquote";
|
|
42
|
+
Type2[Type2["HorizontalRule"] = 5] = "HorizontalRule";
|
|
43
|
+
Type2[Type2["BulletList"] = 6] = "BulletList";
|
|
44
|
+
Type2[Type2["OrderedList"] = 7] = "OrderedList";
|
|
45
|
+
Type2[Type2["ListItem"] = 8] = "ListItem";
|
|
46
|
+
Type2[Type2["ATXHeading1"] = 9] = "ATXHeading1";
|
|
47
|
+
Type2[Type2["ATXHeading2"] = 10] = "ATXHeading2";
|
|
48
|
+
Type2[Type2["ATXHeading3"] = 11] = "ATXHeading3";
|
|
49
|
+
Type2[Type2["ATXHeading4"] = 12] = "ATXHeading4";
|
|
50
|
+
Type2[Type2["ATXHeading5"] = 13] = "ATXHeading5";
|
|
51
|
+
Type2[Type2["ATXHeading6"] = 14] = "ATXHeading6";
|
|
52
|
+
Type2[Type2["SetextHeading1"] = 15] = "SetextHeading1";
|
|
53
|
+
Type2[Type2["SetextHeading2"] = 16] = "SetextHeading2";
|
|
54
|
+
Type2[Type2["HTMLBlock"] = 17] = "HTMLBlock";
|
|
55
|
+
Type2[Type2["LinkReference"] = 18] = "LinkReference";
|
|
56
|
+
Type2[Type2["Paragraph"] = 19] = "Paragraph";
|
|
57
|
+
Type2[Type2["CommentBlock"] = 20] = "CommentBlock";
|
|
58
|
+
Type2[Type2["ProcessingInstructionBlock"] = 21] = "ProcessingInstructionBlock";
|
|
59
|
+
Type2[Type2["Escape"] = 22] = "Escape";
|
|
60
|
+
Type2[Type2["Entity"] = 23] = "Entity";
|
|
61
|
+
Type2[Type2["HardBreak"] = 24] = "HardBreak";
|
|
62
|
+
Type2[Type2["Emphasis"] = 25] = "Emphasis";
|
|
63
|
+
Type2[Type2["StrongEmphasis"] = 26] = "StrongEmphasis";
|
|
64
|
+
Type2[Type2["Link"] = 27] = "Link";
|
|
65
|
+
Type2[Type2["Image"] = 28] = "Image";
|
|
66
|
+
Type2[Type2["InlineCode"] = 29] = "InlineCode";
|
|
67
|
+
Type2[Type2["HTMLTag"] = 30] = "HTMLTag";
|
|
68
|
+
Type2[Type2["Comment"] = 31] = "Comment";
|
|
69
|
+
Type2[Type2["ProcessingInstruction"] = 32] = "ProcessingInstruction";
|
|
70
|
+
Type2[Type2["Autolink"] = 33] = "Autolink";
|
|
71
|
+
Type2[Type2["HeaderMark"] = 34] = "HeaderMark";
|
|
72
|
+
Type2[Type2["QuoteMark"] = 35] = "QuoteMark";
|
|
73
|
+
Type2[Type2["ListMark"] = 36] = "ListMark";
|
|
74
|
+
Type2[Type2["LinkMark"] = 37] = "LinkMark";
|
|
75
|
+
Type2[Type2["EmphasisMark"] = 38] = "EmphasisMark";
|
|
76
|
+
Type2[Type2["CodeMark"] = 39] = "CodeMark";
|
|
77
|
+
Type2[Type2["CodeText"] = 40] = "CodeText";
|
|
78
|
+
Type2[Type2["CodeInfo"] = 41] = "CodeInfo";
|
|
79
|
+
Type2[Type2["LinkTitle"] = 42] = "LinkTitle";
|
|
80
|
+
Type2[Type2["LinkLabel"] = 43] = "LinkLabel";
|
|
81
|
+
Type2[Type2["URL"] = 44] = "URL";
|
|
82
|
+
})(Type || (Type = {}));
|
|
83
|
+
const _LeafBlock = class _LeafBlock {
|
|
84
|
+
/**
|
|
85
|
+
@internal
|
|
86
|
+
*/
|
|
87
|
+
constructor(start, content) {
|
|
88
|
+
this.start = start;
|
|
89
|
+
this.content = content;
|
|
90
|
+
this.marks = [];
|
|
91
|
+
this.parsers = [];
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
__name(_LeafBlock, "LeafBlock");
|
|
95
|
+
let LeafBlock = _LeafBlock;
|
|
96
|
+
const _Line = class _Line {
|
|
97
|
+
constructor() {
|
|
98
|
+
this.text = "";
|
|
99
|
+
this.baseIndent = 0;
|
|
100
|
+
this.basePos = 0;
|
|
101
|
+
this.depth = 0;
|
|
102
|
+
this.markers = [];
|
|
103
|
+
this.pos = 0;
|
|
104
|
+
this.indent = 0;
|
|
105
|
+
this.next = -1;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
@internal
|
|
109
|
+
*/
|
|
110
|
+
forward() {
|
|
111
|
+
if (this.basePos > this.pos)
|
|
112
|
+
this.forwardInner();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
@internal
|
|
116
|
+
*/
|
|
117
|
+
forwardInner() {
|
|
118
|
+
let newPos = this.skipSpace(this.basePos);
|
|
119
|
+
this.indent = this.countIndent(newPos, this.pos, this.indent);
|
|
120
|
+
this.pos = newPos;
|
|
121
|
+
this.next = newPos == this.text.length ? -1 : this.text.charCodeAt(newPos);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
Skip whitespace after the given position, return the position of
|
|
125
|
+
the next non-space character or the end of the line if there's
|
|
126
|
+
only space after `from`.
|
|
127
|
+
*/
|
|
128
|
+
skipSpace(from) {
|
|
129
|
+
return skipSpace(this.text, from);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
@internal
|
|
133
|
+
*/
|
|
134
|
+
reset(text) {
|
|
135
|
+
this.text = text;
|
|
136
|
+
this.baseIndent = this.basePos = this.pos = this.indent = 0;
|
|
137
|
+
this.forwardInner();
|
|
138
|
+
this.depth = 1;
|
|
139
|
+
while (this.markers.length)
|
|
140
|
+
this.markers.pop();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
Move the line's base position forward to the given position.
|
|
144
|
+
This should only be called by composite [block
|
|
145
|
+
parsers](#BlockParser.parse) or [markup skipping
|
|
146
|
+
functions](#NodeSpec.composite).
|
|
147
|
+
*/
|
|
148
|
+
moveBase(to) {
|
|
149
|
+
this.basePos = to;
|
|
150
|
+
this.baseIndent = this.countIndent(to, this.pos, this.indent);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
Move the line's base position forward to the given _column_.
|
|
154
|
+
*/
|
|
155
|
+
moveBaseColumn(indent) {
|
|
156
|
+
this.baseIndent = indent;
|
|
157
|
+
this.basePos = this.findColumn(indent);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
Store a composite-block-level marker. Should be called from
|
|
161
|
+
[markup skipping functions](#NodeSpec.composite) when they
|
|
162
|
+
consume any non-whitespace characters.
|
|
163
|
+
*/
|
|
164
|
+
addMarker(elt2) {
|
|
165
|
+
this.markers.push(elt2);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
Find the column position at `to`, optionally starting at a given
|
|
169
|
+
position and column.
|
|
170
|
+
*/
|
|
171
|
+
countIndent(to, from = 0, indent = 0) {
|
|
172
|
+
for (let i = from; i < to; i++)
|
|
173
|
+
indent += this.text.charCodeAt(i) == 9 ? 4 - indent % 4 : 1;
|
|
174
|
+
return indent;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
Find the position corresponding to the given column.
|
|
178
|
+
*/
|
|
179
|
+
findColumn(goal) {
|
|
180
|
+
let i = 0;
|
|
181
|
+
for (let indent = 0; i < this.text.length && indent < goal; i++)
|
|
182
|
+
indent += this.text.charCodeAt(i) == 9 ? 4 - indent % 4 : 1;
|
|
183
|
+
return i;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
@internal
|
|
187
|
+
*/
|
|
188
|
+
scrub() {
|
|
189
|
+
if (!this.baseIndent)
|
|
190
|
+
return this.text;
|
|
191
|
+
let result = "";
|
|
192
|
+
for (let i = 0; i < this.basePos; i++)
|
|
193
|
+
result += " ";
|
|
194
|
+
return result + this.text.slice(this.basePos);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
__name(_Line, "Line");
|
|
198
|
+
let Line = _Line;
|
|
199
|
+
function skipForList(bl, cx, line) {
|
|
200
|
+
if (line.pos == line.text.length || bl != cx.block && line.indent >= cx.stack[line.depth + 1].value + line.baseIndent)
|
|
201
|
+
return true;
|
|
202
|
+
if (line.indent >= line.baseIndent + 4)
|
|
203
|
+
return false;
|
|
204
|
+
let size = (bl.type == Type.OrderedList ? isOrderedList : isBulletList)(line, cx, false);
|
|
205
|
+
return size > 0 && (bl.type != Type.BulletList || isHorizontalRule(line, cx, false) < 0) && line.text.charCodeAt(line.pos + size - 1) == bl.value;
|
|
206
|
+
}
|
|
207
|
+
__name(skipForList, "skipForList");
|
|
208
|
+
const DefaultSkipMarkup = {
|
|
209
|
+
[Type.Blockquote](bl, cx, line) {
|
|
210
|
+
if (line.next != 62)
|
|
211
|
+
return false;
|
|
212
|
+
line.markers.push(elt(Type.QuoteMark, cx.lineStart + line.pos, cx.lineStart + line.pos + 1));
|
|
213
|
+
line.moveBase(line.pos + (space(line.text.charCodeAt(line.pos + 1)) ? 2 : 1));
|
|
214
|
+
bl.end = cx.lineStart + line.text.length;
|
|
215
|
+
return true;
|
|
216
|
+
},
|
|
217
|
+
[Type.ListItem](bl, _cx, line) {
|
|
218
|
+
if (line.indent < line.baseIndent + bl.value && line.next > -1)
|
|
219
|
+
return false;
|
|
220
|
+
line.moveBaseColumn(line.baseIndent + bl.value);
|
|
221
|
+
return true;
|
|
222
|
+
},
|
|
223
|
+
[Type.OrderedList]: skipForList,
|
|
224
|
+
[Type.BulletList]: skipForList,
|
|
225
|
+
[Type.Document]() {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function space(ch) {
|
|
230
|
+
return ch == 32 || ch == 9 || ch == 10 || ch == 13;
|
|
231
|
+
}
|
|
232
|
+
__name(space, "space");
|
|
233
|
+
function skipSpace(line, i = 0) {
|
|
234
|
+
while (i < line.length && space(line.charCodeAt(i)))
|
|
235
|
+
i++;
|
|
236
|
+
return i;
|
|
237
|
+
}
|
|
238
|
+
__name(skipSpace, "skipSpace");
|
|
239
|
+
function skipSpaceBack(line, i, to) {
|
|
240
|
+
while (i > to && space(line.charCodeAt(i - 1)))
|
|
241
|
+
i--;
|
|
242
|
+
return i;
|
|
243
|
+
}
|
|
244
|
+
__name(skipSpaceBack, "skipSpaceBack");
|
|
245
|
+
function isFencedCode(line) {
|
|
246
|
+
if (line.next != 96 && line.next != 126)
|
|
247
|
+
return -1;
|
|
248
|
+
let pos = line.pos + 1;
|
|
249
|
+
while (pos < line.text.length && line.text.charCodeAt(pos) == line.next)
|
|
250
|
+
pos++;
|
|
251
|
+
if (pos < line.pos + 3)
|
|
252
|
+
return -1;
|
|
253
|
+
if (line.next == 96) {
|
|
254
|
+
for (let i = pos; i < line.text.length; i++)
|
|
255
|
+
if (line.text.charCodeAt(i) == 96)
|
|
256
|
+
return -1;
|
|
257
|
+
}
|
|
258
|
+
return pos;
|
|
259
|
+
}
|
|
260
|
+
__name(isFencedCode, "isFencedCode");
|
|
261
|
+
function isBlockquote(line) {
|
|
262
|
+
return line.next != 62 ? -1 : line.text.charCodeAt(line.pos + 1) == 32 ? 2 : 1;
|
|
263
|
+
}
|
|
264
|
+
__name(isBlockquote, "isBlockquote");
|
|
265
|
+
function isHorizontalRule(line, cx, breaking) {
|
|
266
|
+
if (line.next != 42 && line.next != 45 && line.next != 95)
|
|
267
|
+
return -1;
|
|
268
|
+
let count = 1;
|
|
269
|
+
for (let pos = line.pos + 1; pos < line.text.length; pos++) {
|
|
270
|
+
let ch = line.text.charCodeAt(pos);
|
|
271
|
+
if (ch == line.next)
|
|
272
|
+
count++;
|
|
273
|
+
else if (!space(ch))
|
|
274
|
+
return -1;
|
|
275
|
+
}
|
|
276
|
+
if (breaking && line.next == 45 && isSetextUnderline(line) > -1 && line.depth == cx.stack.length && cx.parser.leafBlockParsers.indexOf(DefaultLeafBlocks.SetextHeading) > -1)
|
|
277
|
+
return -1;
|
|
278
|
+
return count < 3 ? -1 : 1;
|
|
279
|
+
}
|
|
280
|
+
__name(isHorizontalRule, "isHorizontalRule");
|
|
281
|
+
function inList(cx, type) {
|
|
282
|
+
for (let i = cx.stack.length - 1; i >= 0; i--)
|
|
283
|
+
if (cx.stack[i].type == type)
|
|
284
|
+
return true;
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
__name(inList, "inList");
|
|
288
|
+
function isBulletList(line, cx, breaking) {
|
|
289
|
+
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;
|
|
290
|
+
}
|
|
291
|
+
__name(isBulletList, "isBulletList");
|
|
292
|
+
function isOrderedList(line, cx, breaking) {
|
|
293
|
+
let pos = line.pos, next = line.next;
|
|
294
|
+
for (; ; ) {
|
|
295
|
+
if (next >= 48 && next <= 57)
|
|
296
|
+
pos++;
|
|
297
|
+
else
|
|
298
|
+
break;
|
|
299
|
+
if (pos == line.text.length)
|
|
300
|
+
return -1;
|
|
301
|
+
next = line.text.charCodeAt(pos);
|
|
302
|
+
}
|
|
303
|
+
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))
|
|
304
|
+
return -1;
|
|
305
|
+
return pos + 1 - line.pos;
|
|
306
|
+
}
|
|
307
|
+
__name(isOrderedList, "isOrderedList");
|
|
308
|
+
function isAtxHeading(line) {
|
|
309
|
+
if (line.next != 35)
|
|
310
|
+
return -1;
|
|
311
|
+
let pos = line.pos + 1;
|
|
312
|
+
while (pos < line.text.length && line.text.charCodeAt(pos) == 35)
|
|
313
|
+
pos++;
|
|
314
|
+
if (pos < line.text.length && line.text.charCodeAt(pos) != 32)
|
|
315
|
+
return -1;
|
|
316
|
+
let size = pos - line.pos;
|
|
317
|
+
return size > 6 ? -1 : size;
|
|
318
|
+
}
|
|
319
|
+
__name(isAtxHeading, "isAtxHeading");
|
|
320
|
+
function isSetextUnderline(line) {
|
|
321
|
+
if (line.next != 45 && line.next != 61 || line.indent >= line.baseIndent + 4)
|
|
322
|
+
return -1;
|
|
323
|
+
let pos = line.pos + 1;
|
|
324
|
+
while (pos < line.text.length && line.text.charCodeAt(pos) == line.next)
|
|
325
|
+
pos++;
|
|
326
|
+
let end = pos;
|
|
327
|
+
while (pos < line.text.length && space(line.text.charCodeAt(pos)))
|
|
328
|
+
pos++;
|
|
329
|
+
return pos == line.text.length ? end : -1;
|
|
330
|
+
}
|
|
331
|
+
__name(isSetextUnderline, "isSetextUnderline");
|
|
332
|
+
const EmptyLine = /^[ \t]*$/, CommentEnd = /-->/, ProcessingEnd = /\?>/;
|
|
333
|
+
const HTMLBlockStyle = [
|
|
334
|
+
[/^<(?:script|pre|style)(?:\s|>|$)/i, /<\/(?:script|pre|style)>/i],
|
|
335
|
+
[/^\s*<!--/, CommentEnd],
|
|
336
|
+
[/^\s*<\?/, ProcessingEnd],
|
|
337
|
+
[/^\s*<![A-Z]/, />/],
|
|
338
|
+
[/^\s*<!\[CDATA\[/, /\]\]>/],
|
|
339
|
+
[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i, EmptyLine],
|
|
340
|
+
[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i, EmptyLine]
|
|
341
|
+
];
|
|
342
|
+
function isHTMLBlock(line, _cx, breaking) {
|
|
343
|
+
if (line.next != 60)
|
|
344
|
+
return -1;
|
|
345
|
+
let rest = line.text.slice(line.pos);
|
|
346
|
+
for (let i = 0, e = HTMLBlockStyle.length - (breaking ? 1 : 0); i < e; i++)
|
|
347
|
+
if (HTMLBlockStyle[i][0].test(rest))
|
|
348
|
+
return i;
|
|
349
|
+
return -1;
|
|
350
|
+
}
|
|
351
|
+
__name(isHTMLBlock, "isHTMLBlock");
|
|
352
|
+
function getListIndent(line, pos) {
|
|
353
|
+
let indentAfter = line.countIndent(pos, line.pos, line.indent);
|
|
354
|
+
let indented = line.countIndent(line.skipSpace(pos), pos, indentAfter);
|
|
355
|
+
return indented >= indentAfter + 5 ? indentAfter + 1 : indented;
|
|
356
|
+
}
|
|
357
|
+
__name(getListIndent, "getListIndent");
|
|
358
|
+
function addCodeText(marks, from, to) {
|
|
359
|
+
let last = marks.length - 1;
|
|
360
|
+
if (last >= 0 && marks[last].to == from && marks[last].type == Type.CodeText)
|
|
361
|
+
marks[last].to = to;
|
|
362
|
+
else
|
|
363
|
+
marks.push(elt(Type.CodeText, from, to));
|
|
364
|
+
}
|
|
365
|
+
__name(addCodeText, "addCodeText");
|
|
366
|
+
const DefaultBlockParsers = {
|
|
367
|
+
LinkReference: void 0,
|
|
368
|
+
IndentedCode(cx, line) {
|
|
369
|
+
let base = line.baseIndent + 4;
|
|
370
|
+
if (line.indent < base)
|
|
371
|
+
return false;
|
|
372
|
+
let start = line.findColumn(base);
|
|
373
|
+
let from = cx.lineStart + start, to = cx.lineStart + line.text.length;
|
|
374
|
+
let marks = [], pendingMarks = [];
|
|
375
|
+
addCodeText(marks, from, to);
|
|
376
|
+
while (cx.nextLine() && line.depth >= cx.stack.length) {
|
|
377
|
+
if (line.pos == line.text.length) {
|
|
378
|
+
addCodeText(pendingMarks, cx.lineStart - 1, cx.lineStart);
|
|
379
|
+
for (let m of line.markers)
|
|
380
|
+
pendingMarks.push(m);
|
|
381
|
+
} else if (line.indent < base) {
|
|
382
|
+
break;
|
|
383
|
+
} else {
|
|
384
|
+
if (pendingMarks.length) {
|
|
385
|
+
for (let m of pendingMarks) {
|
|
386
|
+
if (m.type == Type.CodeText)
|
|
387
|
+
addCodeText(marks, m.from, m.to);
|
|
388
|
+
else
|
|
389
|
+
marks.push(m);
|
|
390
|
+
}
|
|
391
|
+
pendingMarks = [];
|
|
392
|
+
}
|
|
393
|
+
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
394
|
+
for (let m of line.markers)
|
|
395
|
+
marks.push(m);
|
|
396
|
+
to = cx.lineStart + line.text.length;
|
|
397
|
+
let codeStart = cx.lineStart + line.findColumn(line.baseIndent + 4);
|
|
398
|
+
if (codeStart < to)
|
|
399
|
+
addCodeText(marks, codeStart, to);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (pendingMarks.length) {
|
|
403
|
+
pendingMarks = pendingMarks.filter((m) => m.type != Type.CodeText);
|
|
404
|
+
if (pendingMarks.length)
|
|
405
|
+
line.markers = pendingMarks.concat(line.markers);
|
|
406
|
+
}
|
|
407
|
+
cx.addNode(cx.buffer.writeElements(marks, -from).finish(Type.CodeBlock, to - from), from);
|
|
408
|
+
return true;
|
|
409
|
+
},
|
|
410
|
+
FencedCode(cx, line) {
|
|
411
|
+
let fenceEnd = isFencedCode(line);
|
|
412
|
+
if (fenceEnd < 0)
|
|
413
|
+
return false;
|
|
414
|
+
let from = cx.lineStart + line.pos, ch = line.next, len = fenceEnd - line.pos;
|
|
415
|
+
let infoFrom = line.skipSpace(fenceEnd), infoTo = skipSpaceBack(line.text, line.text.length, infoFrom);
|
|
416
|
+
let marks = [elt(Type.CodeMark, from, from + len)];
|
|
417
|
+
if (infoFrom < infoTo)
|
|
418
|
+
marks.push(elt(Type.CodeInfo, cx.lineStart + infoFrom, cx.lineStart + infoTo));
|
|
419
|
+
for (let first = true; cx.nextLine() && line.depth >= cx.stack.length; first = false) {
|
|
420
|
+
let i = line.pos;
|
|
421
|
+
if (line.indent - line.baseIndent < 4)
|
|
422
|
+
while (i < line.text.length && line.text.charCodeAt(i) == ch)
|
|
423
|
+
i++;
|
|
424
|
+
if (i - line.pos >= len && line.skipSpace(i) == line.text.length) {
|
|
425
|
+
for (let m of line.markers)
|
|
426
|
+
marks.push(m);
|
|
427
|
+
marks.push(elt(Type.CodeMark, cx.lineStart + line.pos, cx.lineStart + i));
|
|
428
|
+
cx.nextLine();
|
|
429
|
+
break;
|
|
430
|
+
} else {
|
|
431
|
+
if (!first)
|
|
432
|
+
addCodeText(marks, cx.lineStart - 1, cx.lineStart);
|
|
433
|
+
for (let m of line.markers)
|
|
434
|
+
marks.push(m);
|
|
435
|
+
let textStart = cx.lineStart + line.basePos, textEnd = cx.lineStart + line.text.length;
|
|
436
|
+
if (textStart < textEnd)
|
|
437
|
+
addCodeText(marks, textStart, textEnd);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
cx.addNode(cx.buffer.writeElements(marks, -from).finish(Type.FencedCode, cx.prevLineEnd() - from), from);
|
|
441
|
+
return true;
|
|
442
|
+
},
|
|
443
|
+
Blockquote(cx, line) {
|
|
444
|
+
let size = isBlockquote(line);
|
|
445
|
+
if (size < 0)
|
|
446
|
+
return false;
|
|
447
|
+
cx.startContext(Type.Blockquote, line.pos);
|
|
448
|
+
cx.addNode(Type.QuoteMark, cx.lineStart + line.pos, cx.lineStart + line.pos + 1);
|
|
449
|
+
line.moveBase(line.pos + size);
|
|
450
|
+
return null;
|
|
451
|
+
},
|
|
452
|
+
HorizontalRule(cx, line) {
|
|
453
|
+
if (isHorizontalRule(line, cx, false) < 0)
|
|
454
|
+
return false;
|
|
455
|
+
let from = cx.lineStart + line.pos;
|
|
456
|
+
cx.nextLine();
|
|
457
|
+
cx.addNode(Type.HorizontalRule, from);
|
|
458
|
+
return true;
|
|
459
|
+
},
|
|
460
|
+
BulletList(cx, line) {
|
|
461
|
+
let size = isBulletList(line, cx, false);
|
|
462
|
+
if (size < 0)
|
|
463
|
+
return false;
|
|
464
|
+
if (cx.block.type != Type.BulletList)
|
|
465
|
+
cx.startContext(Type.BulletList, line.basePos, line.next);
|
|
466
|
+
let newBase = getListIndent(line, line.pos + 1);
|
|
467
|
+
cx.startContext(Type.ListItem, line.basePos, newBase - line.baseIndent);
|
|
468
|
+
cx.addNode(Type.ListMark, cx.lineStart + line.pos, cx.lineStart + line.pos + size);
|
|
469
|
+
line.moveBaseColumn(newBase);
|
|
470
|
+
return null;
|
|
471
|
+
},
|
|
472
|
+
OrderedList(cx, line) {
|
|
473
|
+
let size = isOrderedList(line, cx, false);
|
|
474
|
+
if (size < 0)
|
|
475
|
+
return false;
|
|
476
|
+
if (cx.block.type != Type.OrderedList)
|
|
477
|
+
cx.startContext(Type.OrderedList, line.basePos, line.text.charCodeAt(line.pos + size - 1));
|
|
478
|
+
let newBase = getListIndent(line, line.pos + size);
|
|
479
|
+
cx.startContext(Type.ListItem, line.basePos, newBase - line.baseIndent);
|
|
480
|
+
cx.addNode(Type.ListMark, cx.lineStart + line.pos, cx.lineStart + line.pos + size);
|
|
481
|
+
line.moveBaseColumn(newBase);
|
|
482
|
+
return null;
|
|
483
|
+
},
|
|
484
|
+
ATXHeading(cx, line) {
|
|
485
|
+
let size = isAtxHeading(line);
|
|
486
|
+
if (size < 0)
|
|
487
|
+
return false;
|
|
488
|
+
let off = line.pos, from = cx.lineStart + off;
|
|
489
|
+
let endOfSpace = skipSpaceBack(line.text, line.text.length, off), after = endOfSpace;
|
|
490
|
+
while (after > off && line.text.charCodeAt(after - 1) == line.next)
|
|
491
|
+
after--;
|
|
492
|
+
if (after == endOfSpace || after == off || !space(line.text.charCodeAt(after - 1)))
|
|
493
|
+
after = line.text.length;
|
|
494
|
+
let buf = cx.buffer.write(Type.HeaderMark, 0, size).writeElements(cx.parser.parseInline(line.text.slice(off + size + 1, after), from + size + 1), -from);
|
|
495
|
+
if (after < line.text.length)
|
|
496
|
+
buf.write(Type.HeaderMark, after - off, endOfSpace - off);
|
|
497
|
+
let node = buf.finish(Type.ATXHeading1 - 1 + size, line.text.length - off);
|
|
498
|
+
cx.nextLine();
|
|
499
|
+
cx.addNode(node, from);
|
|
500
|
+
return true;
|
|
501
|
+
},
|
|
502
|
+
HTMLBlock(cx, line) {
|
|
503
|
+
let type = isHTMLBlock(line, cx, false);
|
|
504
|
+
if (type < 0)
|
|
505
|
+
return false;
|
|
506
|
+
let from = cx.lineStart + line.pos, end = HTMLBlockStyle[type][1];
|
|
507
|
+
let marks = [], trailing = end != EmptyLine;
|
|
508
|
+
while (!end.test(line.text) && cx.nextLine()) {
|
|
509
|
+
if (line.depth < cx.stack.length) {
|
|
510
|
+
trailing = false;
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
for (let m of line.markers)
|
|
514
|
+
marks.push(m);
|
|
515
|
+
}
|
|
516
|
+
if (trailing)
|
|
517
|
+
cx.nextLine();
|
|
518
|
+
let nodeType = end == CommentEnd ? Type.CommentBlock : end == ProcessingEnd ? Type.ProcessingInstructionBlock : Type.HTMLBlock;
|
|
519
|
+
let to = cx.prevLineEnd();
|
|
520
|
+
cx.addNode(cx.buffer.writeElements(marks, -from).finish(nodeType, to - from), from);
|
|
521
|
+
return true;
|
|
522
|
+
},
|
|
523
|
+
SetextHeading: void 0
|
|
524
|
+
// Specifies relative precedence for block-continue function
|
|
525
|
+
};
|
|
526
|
+
const _LinkReferenceParser = class _LinkReferenceParser {
|
|
527
|
+
constructor(leaf) {
|
|
528
|
+
this.stage = 0;
|
|
529
|
+
this.elts = [];
|
|
530
|
+
this.pos = 0;
|
|
531
|
+
this.start = leaf.start;
|
|
532
|
+
this.advance(leaf.content);
|
|
533
|
+
}
|
|
534
|
+
nextLine(cx, line, leaf) {
|
|
535
|
+
if (this.stage == -1)
|
|
536
|
+
return false;
|
|
537
|
+
let content = leaf.content + "\n" + line.scrub();
|
|
538
|
+
let finish = this.advance(content);
|
|
539
|
+
if (finish > -1 && finish < content.length)
|
|
540
|
+
return this.complete(cx, leaf, finish);
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
finish(cx, leaf) {
|
|
544
|
+
if ((this.stage == 2 || this.stage == 3) && skipSpace(leaf.content, this.pos) == leaf.content.length)
|
|
545
|
+
return this.complete(cx, leaf, leaf.content.length);
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
complete(cx, leaf, len) {
|
|
549
|
+
cx.addLeafElement(leaf, elt(Type.LinkReference, this.start, this.start + len, this.elts));
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
nextStage(elt2) {
|
|
553
|
+
if (elt2) {
|
|
554
|
+
this.pos = elt2.to - this.start;
|
|
555
|
+
this.elts.push(elt2);
|
|
556
|
+
this.stage++;
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
if (elt2 === false)
|
|
560
|
+
this.stage = -1;
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
advance(content) {
|
|
564
|
+
for (; ; ) {
|
|
565
|
+
if (this.stage == -1) {
|
|
566
|
+
return -1;
|
|
567
|
+
} else if (this.stage == 0) {
|
|
568
|
+
if (!this.nextStage(parseLinkLabel(content, this.pos, this.start, true)))
|
|
569
|
+
return -1;
|
|
570
|
+
if (content.charCodeAt(this.pos) != 58)
|
|
571
|
+
return this.stage = -1;
|
|
572
|
+
this.elts.push(elt(Type.LinkMark, this.pos + this.start, this.pos + this.start + 1));
|
|
573
|
+
this.pos++;
|
|
574
|
+
} else if (this.stage == 1) {
|
|
575
|
+
if (!this.nextStage(parseURL(content, skipSpace(content, this.pos), this.start)))
|
|
576
|
+
return -1;
|
|
577
|
+
} else if (this.stage == 2) {
|
|
578
|
+
let skip = skipSpace(content, this.pos), end = 0;
|
|
579
|
+
if (skip > this.pos) {
|
|
580
|
+
let title = parseLinkTitle(content, skip, this.start);
|
|
581
|
+
if (title) {
|
|
582
|
+
let titleEnd = lineEnd(content, title.to - this.start);
|
|
583
|
+
if (titleEnd > 0) {
|
|
584
|
+
this.nextStage(title);
|
|
585
|
+
end = titleEnd;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (!end)
|
|
590
|
+
end = lineEnd(content, this.pos);
|
|
591
|
+
return end > 0 && end < content.length ? end : -1;
|
|
592
|
+
} else {
|
|
593
|
+
return lineEnd(content, this.pos);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
__name(_LinkReferenceParser, "LinkReferenceParser");
|
|
599
|
+
let LinkReferenceParser = _LinkReferenceParser;
|
|
600
|
+
function lineEnd(text, pos) {
|
|
601
|
+
for (; pos < text.length; pos++) {
|
|
602
|
+
let next = text.charCodeAt(pos);
|
|
603
|
+
if (next == 10)
|
|
604
|
+
break;
|
|
605
|
+
if (!space(next))
|
|
606
|
+
return -1;
|
|
607
|
+
}
|
|
608
|
+
return pos;
|
|
609
|
+
}
|
|
610
|
+
__name(lineEnd, "lineEnd");
|
|
611
|
+
const _SetextHeadingParser = class _SetextHeadingParser {
|
|
612
|
+
nextLine(cx, line, leaf) {
|
|
613
|
+
let underline = line.depth < cx.stack.length ? -1 : isSetextUnderline(line);
|
|
614
|
+
let next = line.next;
|
|
615
|
+
if (underline < 0)
|
|
616
|
+
return false;
|
|
617
|
+
let underlineMark = elt(Type.HeaderMark, cx.lineStart + line.pos, cx.lineStart + underline);
|
|
618
|
+
cx.nextLine();
|
|
619
|
+
cx.addLeafElement(leaf, elt(next == 61 ? Type.SetextHeading1 : Type.SetextHeading2, leaf.start, cx.prevLineEnd(), [
|
|
620
|
+
...cx.parser.parseInline(leaf.content, leaf.start),
|
|
621
|
+
underlineMark
|
|
622
|
+
]));
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
finish() {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
__name(_SetextHeadingParser, "SetextHeadingParser");
|
|
630
|
+
let SetextHeadingParser = _SetextHeadingParser;
|
|
631
|
+
const DefaultLeafBlocks = {
|
|
632
|
+
LinkReference(_, leaf) {
|
|
633
|
+
return leaf.content.charCodeAt(0) == 91 ? new LinkReferenceParser(leaf) : null;
|
|
634
|
+
},
|
|
635
|
+
SetextHeading() {
|
|
636
|
+
return new SetextHeadingParser();
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
const DefaultEndLeaf = [
|
|
640
|
+
(_, line) => isAtxHeading(line) >= 0,
|
|
641
|
+
(_, line) => isFencedCode(line) >= 0,
|
|
642
|
+
(_, line) => isBlockquote(line) >= 0,
|
|
643
|
+
(p, line) => isBulletList(line, p, true) >= 0,
|
|
644
|
+
(p, line) => isOrderedList(line, p, true) >= 0,
|
|
645
|
+
(p, line) => isHorizontalRule(line, p, true) >= 0,
|
|
646
|
+
(p, line) => isHTMLBlock(line, p, true) >= 0
|
|
647
|
+
];
|
|
648
|
+
const scanLineResult = { text: "", end: 0 };
|
|
649
|
+
const _BlockContext = class _BlockContext {
|
|
650
|
+
/**
|
|
651
|
+
@internal
|
|
652
|
+
*/
|
|
653
|
+
constructor(parser2, input, fragments, ranges) {
|
|
654
|
+
this.parser = parser2;
|
|
655
|
+
this.input = input;
|
|
656
|
+
this.ranges = ranges;
|
|
657
|
+
this.line = new Line();
|
|
658
|
+
this.atEnd = false;
|
|
659
|
+
this.reusePlaceholders = /* @__PURE__ */ new Map();
|
|
660
|
+
this.stoppedAt = null;
|
|
661
|
+
this.rangeI = 0;
|
|
662
|
+
this.to = ranges[ranges.length - 1].to;
|
|
663
|
+
this.lineStart = this.absoluteLineStart = this.absoluteLineEnd = ranges[0].from;
|
|
664
|
+
this.block = CompositeBlock.create(Type.Document, 0, this.lineStart, 0, 0);
|
|
665
|
+
this.stack = [this.block];
|
|
666
|
+
this.fragments = fragments.length ? new FragmentCursor(fragments, input) : null;
|
|
667
|
+
this.readLine();
|
|
668
|
+
}
|
|
669
|
+
get parsedPos() {
|
|
670
|
+
return this.absoluteLineStart;
|
|
671
|
+
}
|
|
672
|
+
advance() {
|
|
673
|
+
if (this.stoppedAt != null && this.absoluteLineStart > this.stoppedAt)
|
|
674
|
+
return this.finish();
|
|
675
|
+
let { line } = this;
|
|
676
|
+
for (; ; ) {
|
|
677
|
+
for (let markI = 0; ; ) {
|
|
678
|
+
let next = line.depth < this.stack.length ? this.stack[this.stack.length - 1] : null;
|
|
679
|
+
while (markI < line.markers.length && (!next || line.markers[markI].from < next.end)) {
|
|
680
|
+
let mark = line.markers[markI++];
|
|
681
|
+
this.addNode(mark.type, mark.from, mark.to);
|
|
682
|
+
}
|
|
683
|
+
if (!next)
|
|
684
|
+
break;
|
|
685
|
+
this.finishContext();
|
|
686
|
+
}
|
|
687
|
+
if (line.pos < line.text.length)
|
|
688
|
+
break;
|
|
689
|
+
if (!this.nextLine())
|
|
690
|
+
return this.finish();
|
|
691
|
+
}
|
|
692
|
+
if (this.fragments && this.reuseFragment(line.basePos))
|
|
693
|
+
return null;
|
|
694
|
+
start: for (; ; ) {
|
|
695
|
+
for (let type of this.parser.blockParsers)
|
|
696
|
+
if (type) {
|
|
697
|
+
let result = type(this, line);
|
|
698
|
+
if (result != false) {
|
|
699
|
+
if (result == true)
|
|
700
|
+
return null;
|
|
701
|
+
line.forward();
|
|
702
|
+
continue start;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
let leaf = new LeafBlock(this.lineStart + line.pos, line.text.slice(line.pos));
|
|
708
|
+
for (let parse of this.parser.leafBlockParsers)
|
|
709
|
+
if (parse) {
|
|
710
|
+
let parser2 = parse(this, leaf);
|
|
711
|
+
if (parser2)
|
|
712
|
+
leaf.parsers.push(parser2);
|
|
713
|
+
}
|
|
714
|
+
lines: while (this.nextLine()) {
|
|
715
|
+
if (line.pos == line.text.length)
|
|
716
|
+
break;
|
|
717
|
+
if (line.indent < line.baseIndent + 4) {
|
|
718
|
+
for (let stop of this.parser.endLeafBlock)
|
|
719
|
+
if (stop(this, line, leaf))
|
|
720
|
+
break lines;
|
|
721
|
+
}
|
|
722
|
+
for (let parser2 of leaf.parsers)
|
|
723
|
+
if (parser2.nextLine(this, line, leaf))
|
|
724
|
+
return null;
|
|
725
|
+
leaf.content += "\n" + line.scrub();
|
|
726
|
+
for (let m of line.markers)
|
|
727
|
+
leaf.marks.push(m);
|
|
728
|
+
}
|
|
729
|
+
this.finishLeaf(leaf);
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
stopAt(pos) {
|
|
733
|
+
if (this.stoppedAt != null && this.stoppedAt < pos)
|
|
734
|
+
throw new RangeError("Can't move stoppedAt forward");
|
|
735
|
+
this.stoppedAt = pos;
|
|
736
|
+
}
|
|
737
|
+
reuseFragment(start) {
|
|
738
|
+
if (!this.fragments.moveTo(this.absoluteLineStart + start, this.absoluteLineStart) || !this.fragments.matches(this.block.hash))
|
|
739
|
+
return false;
|
|
740
|
+
let taken = this.fragments.takeNodes(this);
|
|
741
|
+
if (!taken)
|
|
742
|
+
return false;
|
|
743
|
+
this.absoluteLineStart += taken;
|
|
744
|
+
this.lineStart = toRelative(this.absoluteLineStart, this.ranges);
|
|
745
|
+
this.moveRangeI();
|
|
746
|
+
if (this.absoluteLineStart < this.to) {
|
|
747
|
+
this.lineStart++;
|
|
748
|
+
this.absoluteLineStart++;
|
|
749
|
+
this.readLine();
|
|
750
|
+
} else {
|
|
751
|
+
this.atEnd = true;
|
|
752
|
+
this.readLine();
|
|
753
|
+
}
|
|
754
|
+
return true;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
The number of parent blocks surrounding the current block.
|
|
758
|
+
*/
|
|
759
|
+
get depth() {
|
|
760
|
+
return this.stack.length;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
Get the type of the parent block at the given depth. When no
|
|
764
|
+
depth is passed, return the type of the innermost parent.
|
|
765
|
+
*/
|
|
766
|
+
parentType(depth = this.depth - 1) {
|
|
767
|
+
return this.parser.nodeSet.types[this.stack[depth].type];
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
Move to the next input line. This should only be called by
|
|
771
|
+
(non-composite) [block parsers](#BlockParser.parse) that consume
|
|
772
|
+
the line directly, or leaf block parser
|
|
773
|
+
[`nextLine`](#LeafBlockParser.nextLine) methods when they
|
|
774
|
+
consume the current line (and return true).
|
|
775
|
+
*/
|
|
776
|
+
nextLine() {
|
|
777
|
+
this.lineStart += this.line.text.length;
|
|
778
|
+
if (this.absoluteLineEnd >= this.to) {
|
|
779
|
+
this.absoluteLineStart = this.absoluteLineEnd;
|
|
780
|
+
this.atEnd = true;
|
|
781
|
+
this.readLine();
|
|
782
|
+
return false;
|
|
783
|
+
} else {
|
|
784
|
+
this.lineStart++;
|
|
785
|
+
this.absoluteLineStart = this.absoluteLineEnd + 1;
|
|
786
|
+
this.moveRangeI();
|
|
787
|
+
this.readLine();
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
Retrieve the text of the line after the current one, without
|
|
793
|
+
actually moving the context's current line forward.
|
|
794
|
+
*/
|
|
795
|
+
peekLine() {
|
|
796
|
+
return this.scanLine(this.absoluteLineEnd + 1).text;
|
|
797
|
+
}
|
|
798
|
+
moveRangeI() {
|
|
799
|
+
while (this.rangeI < this.ranges.length - 1 && this.absoluteLineStart >= this.ranges[this.rangeI].to) {
|
|
800
|
+
this.rangeI++;
|
|
801
|
+
this.absoluteLineStart = Math.max(this.absoluteLineStart, this.ranges[this.rangeI].from);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
@internal
|
|
806
|
+
Collect the text for the next line.
|
|
807
|
+
*/
|
|
808
|
+
scanLine(start) {
|
|
809
|
+
let r = scanLineResult;
|
|
810
|
+
r.end = start;
|
|
811
|
+
if (start >= this.to) {
|
|
812
|
+
r.text = "";
|
|
813
|
+
} else {
|
|
814
|
+
r.text = this.lineChunkAt(start);
|
|
815
|
+
r.end += r.text.length;
|
|
816
|
+
if (this.ranges.length > 1) {
|
|
817
|
+
let textOffset = this.absoluteLineStart, rangeI = this.rangeI;
|
|
818
|
+
while (this.ranges[rangeI].to < r.end) {
|
|
819
|
+
rangeI++;
|
|
820
|
+
let nextFrom = this.ranges[rangeI].from;
|
|
821
|
+
let after = this.lineChunkAt(nextFrom);
|
|
822
|
+
r.end = nextFrom + after.length;
|
|
823
|
+
r.text = r.text.slice(0, this.ranges[rangeI - 1].to - textOffset) + after;
|
|
824
|
+
textOffset = r.end - r.text.length;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return r;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
@internal
|
|
832
|
+
Populate this.line with the content of the next line. Skip
|
|
833
|
+
leading characters covered by composite blocks.
|
|
834
|
+
*/
|
|
835
|
+
readLine() {
|
|
836
|
+
let { line } = this, { text, end } = this.scanLine(this.absoluteLineStart);
|
|
837
|
+
this.absoluteLineEnd = end;
|
|
838
|
+
line.reset(text);
|
|
839
|
+
for (; line.depth < this.stack.length; line.depth++) {
|
|
840
|
+
let cx = this.stack[line.depth], handler = this.parser.skipContextMarkup[cx.type];
|
|
841
|
+
if (!handler)
|
|
842
|
+
throw new Error("Unhandled block context " + Type[cx.type]);
|
|
843
|
+
if (!handler(cx, this, line))
|
|
844
|
+
break;
|
|
845
|
+
line.forward();
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
lineChunkAt(pos) {
|
|
849
|
+
let next = this.input.chunk(pos), text;
|
|
850
|
+
if (!this.input.lineChunks) {
|
|
851
|
+
let eol = next.indexOf("\n");
|
|
852
|
+
text = eol < 0 ? next : next.slice(0, eol);
|
|
853
|
+
} else {
|
|
854
|
+
text = next == "\n" ? "" : next;
|
|
855
|
+
}
|
|
856
|
+
return pos + text.length > this.to ? text.slice(0, this.to - pos) : text;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
The end position of the previous line.
|
|
860
|
+
*/
|
|
861
|
+
prevLineEnd() {
|
|
862
|
+
return this.atEnd ? this.lineStart : this.lineStart - 1;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
@internal
|
|
866
|
+
*/
|
|
867
|
+
startContext(type, start, value = 0) {
|
|
868
|
+
this.block = CompositeBlock.create(type, value, this.lineStart + start, this.block.hash, this.lineStart + this.line.text.length);
|
|
869
|
+
this.stack.push(this.block);
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
Start a composite block. Should only be called from [block
|
|
873
|
+
parser functions](#BlockParser.parse) that return null.
|
|
874
|
+
*/
|
|
875
|
+
startComposite(type, start, value = 0) {
|
|
876
|
+
this.startContext(this.parser.getNodeType(type), start, value);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
@internal
|
|
880
|
+
*/
|
|
881
|
+
addNode(block, from, to) {
|
|
882
|
+
if (typeof block == "number")
|
|
883
|
+
block = new Tree(this.parser.nodeSet.types[block], none, none, (to !== null && to !== void 0 ? to : this.prevLineEnd()) - from);
|
|
884
|
+
this.block.addChild(block, from - this.block.from);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
Add a block element. Can be called by [block
|
|
888
|
+
parsers](#BlockParser.parse).
|
|
889
|
+
*/
|
|
890
|
+
addElement(elt2) {
|
|
891
|
+
this.block.addChild(elt2.toTree(this.parser.nodeSet), elt2.from - this.block.from);
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
Add a block element from a [leaf parser](#LeafBlockParser). This
|
|
895
|
+
makes sure any extra composite block markup (such as blockquote
|
|
896
|
+
markers) inside the block are also added to the syntax tree.
|
|
897
|
+
*/
|
|
898
|
+
addLeafElement(leaf, elt2) {
|
|
899
|
+
this.addNode(this.buffer.writeElements(injectMarks(elt2.children, leaf.marks), -elt2.from).finish(elt2.type, elt2.to - elt2.from), elt2.from);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
@internal
|
|
903
|
+
*/
|
|
904
|
+
finishContext() {
|
|
905
|
+
let cx = this.stack.pop();
|
|
906
|
+
let top = this.stack[this.stack.length - 1];
|
|
907
|
+
top.addChild(cx.toTree(this.parser.nodeSet), cx.from - top.from);
|
|
908
|
+
this.block = top;
|
|
909
|
+
}
|
|
910
|
+
finish() {
|
|
911
|
+
while (this.stack.length > 1)
|
|
912
|
+
this.finishContext();
|
|
913
|
+
return this.addGaps(this.block.toTree(this.parser.nodeSet, this.lineStart));
|
|
914
|
+
}
|
|
915
|
+
addGaps(tree) {
|
|
916
|
+
return this.ranges.length > 1 ? injectGaps(this.ranges, 0, tree.topNode, this.ranges[0].from, this.reusePlaceholders) : tree;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
@internal
|
|
920
|
+
*/
|
|
921
|
+
finishLeaf(leaf) {
|
|
922
|
+
for (let parser2 of leaf.parsers)
|
|
923
|
+
if (parser2.finish(this, leaf))
|
|
924
|
+
return;
|
|
925
|
+
let inline = injectMarks(this.parser.parseInline(leaf.content, leaf.start), leaf.marks);
|
|
926
|
+
this.addNode(this.buffer.writeElements(inline, -leaf.start).finish(Type.Paragraph, leaf.content.length), leaf.start);
|
|
927
|
+
}
|
|
928
|
+
elt(type, from, to, children) {
|
|
929
|
+
if (typeof type == "string")
|
|
930
|
+
return elt(this.parser.getNodeType(type), from, to, children);
|
|
931
|
+
return new TreeElement(type, from);
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
@internal
|
|
935
|
+
*/
|
|
936
|
+
get buffer() {
|
|
937
|
+
return new Buffer2(this.parser.nodeSet);
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
__name(_BlockContext, "BlockContext");
|
|
941
|
+
let BlockContext = _BlockContext;
|
|
942
|
+
function injectGaps(ranges, rangeI, tree, offset, dummies) {
|
|
943
|
+
let rangeEnd = ranges[rangeI].to;
|
|
944
|
+
let children = [], positions = [], start = tree.from + offset;
|
|
945
|
+
function movePastNext(upto, inclusive) {
|
|
946
|
+
while (inclusive ? upto >= rangeEnd : upto > rangeEnd) {
|
|
947
|
+
let size = ranges[rangeI + 1].from - rangeEnd;
|
|
948
|
+
offset += size;
|
|
949
|
+
upto += size;
|
|
950
|
+
rangeI++;
|
|
951
|
+
rangeEnd = ranges[rangeI].to;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
__name(movePastNext, "movePastNext");
|
|
955
|
+
for (let ch = tree.firstChild; ch; ch = ch.nextSibling) {
|
|
956
|
+
movePastNext(ch.from + offset, true);
|
|
957
|
+
let from = ch.from + offset, node, reuse = dummies.get(ch.tree);
|
|
958
|
+
if (reuse) {
|
|
959
|
+
node = reuse;
|
|
960
|
+
} else if (ch.to + offset > rangeEnd) {
|
|
961
|
+
node = injectGaps(ranges, rangeI, ch, offset, dummies);
|
|
962
|
+
movePastNext(ch.to + offset, false);
|
|
963
|
+
} else {
|
|
964
|
+
node = ch.toTree();
|
|
965
|
+
}
|
|
966
|
+
children.push(node);
|
|
967
|
+
positions.push(from - start);
|
|
968
|
+
}
|
|
969
|
+
movePastNext(tree.to + offset, false);
|
|
970
|
+
return new Tree(tree.type, children, positions, tree.to + offset - start, tree.tree ? tree.tree.propValues : void 0);
|
|
971
|
+
}
|
|
972
|
+
__name(injectGaps, "injectGaps");
|
|
973
|
+
const _MarkdownParser = class _MarkdownParser extends Parser {
|
|
974
|
+
/**
|
|
975
|
+
@internal
|
|
976
|
+
*/
|
|
977
|
+
constructor(nodeSet, blockParsers, leafBlockParsers, blockNames, endLeafBlock, skipContextMarkup, inlineParsers, inlineNames, wrappers) {
|
|
978
|
+
super();
|
|
979
|
+
this.nodeSet = nodeSet;
|
|
980
|
+
this.blockParsers = blockParsers;
|
|
981
|
+
this.leafBlockParsers = leafBlockParsers;
|
|
982
|
+
this.blockNames = blockNames;
|
|
983
|
+
this.endLeafBlock = endLeafBlock;
|
|
984
|
+
this.skipContextMarkup = skipContextMarkup;
|
|
985
|
+
this.inlineParsers = inlineParsers;
|
|
986
|
+
this.inlineNames = inlineNames;
|
|
987
|
+
this.wrappers = wrappers;
|
|
988
|
+
this.nodeTypes = /* @__PURE__ */ Object.create(null);
|
|
989
|
+
for (let t of nodeSet.types)
|
|
990
|
+
this.nodeTypes[t.name] = t.id;
|
|
991
|
+
}
|
|
992
|
+
createParse(input, fragments, ranges) {
|
|
993
|
+
let parse = new BlockContext(this, input, fragments, ranges);
|
|
994
|
+
for (let w of this.wrappers)
|
|
995
|
+
parse = w(parse, input, fragments, ranges);
|
|
996
|
+
return parse;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
Reconfigure the parser.
|
|
1000
|
+
*/
|
|
1001
|
+
configure(spec) {
|
|
1002
|
+
let config = resolveConfig(spec);
|
|
1003
|
+
if (!config)
|
|
1004
|
+
return this;
|
|
1005
|
+
let { nodeSet, skipContextMarkup } = this;
|
|
1006
|
+
let blockParsers = this.blockParsers.slice(), leafBlockParsers = this.leafBlockParsers.slice(), blockNames = this.blockNames.slice(), inlineParsers = this.inlineParsers.slice(), inlineNames = this.inlineNames.slice(), endLeafBlock = this.endLeafBlock.slice(), wrappers = this.wrappers;
|
|
1007
|
+
if (nonEmpty(config.defineNodes)) {
|
|
1008
|
+
skipContextMarkup = Object.assign({}, skipContextMarkup);
|
|
1009
|
+
let nodeTypes2 = nodeSet.types.slice(), styles;
|
|
1010
|
+
for (let s of config.defineNodes) {
|
|
1011
|
+
let { name, block, composite, style } = typeof s == "string" ? { name: s } : s;
|
|
1012
|
+
if (nodeTypes2.some((t) => t.name == name))
|
|
1013
|
+
continue;
|
|
1014
|
+
if (composite)
|
|
1015
|
+
skipContextMarkup[nodeTypes2.length] = (bl, cx, line) => composite(cx, line, bl.value);
|
|
1016
|
+
let id = nodeTypes2.length;
|
|
1017
|
+
let group = composite ? ["Block", "BlockContext"] : !block ? void 0 : id >= Type.ATXHeading1 && id <= Type.SetextHeading2 ? ["Block", "LeafBlock", "Heading"] : ["Block", "LeafBlock"];
|
|
1018
|
+
nodeTypes2.push(NodeType.define({
|
|
1019
|
+
id,
|
|
1020
|
+
name,
|
|
1021
|
+
props: group && [[NodeProp.group, group]]
|
|
1022
|
+
}));
|
|
1023
|
+
if (style) {
|
|
1024
|
+
if (!styles)
|
|
1025
|
+
styles = {};
|
|
1026
|
+
if (Array.isArray(style) || style instanceof Tag)
|
|
1027
|
+
styles[name] = style;
|
|
1028
|
+
else
|
|
1029
|
+
Object.assign(styles, style);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
nodeSet = new NodeSet(nodeTypes2);
|
|
1033
|
+
if (styles)
|
|
1034
|
+
nodeSet = nodeSet.extend(styleTags(styles));
|
|
1035
|
+
}
|
|
1036
|
+
if (nonEmpty(config.props))
|
|
1037
|
+
nodeSet = nodeSet.extend(...config.props);
|
|
1038
|
+
if (nonEmpty(config.remove)) {
|
|
1039
|
+
for (let rm of config.remove) {
|
|
1040
|
+
let block = this.blockNames.indexOf(rm), inline = this.inlineNames.indexOf(rm);
|
|
1041
|
+
if (block > -1)
|
|
1042
|
+
blockParsers[block] = leafBlockParsers[block] = void 0;
|
|
1043
|
+
if (inline > -1)
|
|
1044
|
+
inlineParsers[inline] = void 0;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (nonEmpty(config.parseBlock)) {
|
|
1048
|
+
for (let spec2 of config.parseBlock) {
|
|
1049
|
+
let found = blockNames.indexOf(spec2.name);
|
|
1050
|
+
if (found > -1) {
|
|
1051
|
+
blockParsers[found] = spec2.parse;
|
|
1052
|
+
leafBlockParsers[found] = spec2.leaf;
|
|
1053
|
+
} else {
|
|
1054
|
+
let pos = spec2.before ? findName(blockNames, spec2.before) : spec2.after ? findName(blockNames, spec2.after) + 1 : blockNames.length - 1;
|
|
1055
|
+
blockParsers.splice(pos, 0, spec2.parse);
|
|
1056
|
+
leafBlockParsers.splice(pos, 0, spec2.leaf);
|
|
1057
|
+
blockNames.splice(pos, 0, spec2.name);
|
|
1058
|
+
}
|
|
1059
|
+
if (spec2.endLeaf)
|
|
1060
|
+
endLeafBlock.push(spec2.endLeaf);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
if (nonEmpty(config.parseInline)) {
|
|
1064
|
+
for (let spec2 of config.parseInline) {
|
|
1065
|
+
let found = inlineNames.indexOf(spec2.name);
|
|
1066
|
+
if (found > -1) {
|
|
1067
|
+
inlineParsers[found] = spec2.parse;
|
|
1068
|
+
} else {
|
|
1069
|
+
let pos = spec2.before ? findName(inlineNames, spec2.before) : spec2.after ? findName(inlineNames, spec2.after) + 1 : inlineNames.length - 1;
|
|
1070
|
+
inlineParsers.splice(pos, 0, spec2.parse);
|
|
1071
|
+
inlineNames.splice(pos, 0, spec2.name);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
if (config.wrap)
|
|
1076
|
+
wrappers = wrappers.concat(config.wrap);
|
|
1077
|
+
return new _MarkdownParser(nodeSet, blockParsers, leafBlockParsers, blockNames, endLeafBlock, skipContextMarkup, inlineParsers, inlineNames, wrappers);
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
@internal
|
|
1081
|
+
*/
|
|
1082
|
+
getNodeType(name) {
|
|
1083
|
+
let found = this.nodeTypes[name];
|
|
1084
|
+
if (found == null)
|
|
1085
|
+
throw new RangeError(`Unknown node type '${name}'`);
|
|
1086
|
+
return found;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
Parse the given piece of inline text at the given offset,
|
|
1090
|
+
returning an array of [`Element`](#Element) objects representing
|
|
1091
|
+
the inline content.
|
|
1092
|
+
*/
|
|
1093
|
+
parseInline(text, offset) {
|
|
1094
|
+
let cx = new InlineContext(this, text, offset);
|
|
1095
|
+
outer: for (let pos = offset; pos < cx.end; ) {
|
|
1096
|
+
let next = cx.char(pos);
|
|
1097
|
+
for (let token of this.inlineParsers)
|
|
1098
|
+
if (token) {
|
|
1099
|
+
let result = token(cx, next, pos);
|
|
1100
|
+
if (result >= 0) {
|
|
1101
|
+
pos = result;
|
|
1102
|
+
continue outer;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
pos++;
|
|
1106
|
+
}
|
|
1107
|
+
return cx.resolveMarkers(0);
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
__name(_MarkdownParser, "MarkdownParser");
|
|
1111
|
+
let MarkdownParser = _MarkdownParser;
|
|
1112
|
+
function nonEmpty(a) {
|
|
1113
|
+
return a != null && a.length > 0;
|
|
1114
|
+
}
|
|
1115
|
+
__name(nonEmpty, "nonEmpty");
|
|
1116
|
+
function resolveConfig(spec) {
|
|
1117
|
+
if (!Array.isArray(spec))
|
|
1118
|
+
return spec;
|
|
1119
|
+
if (spec.length == 0)
|
|
1120
|
+
return null;
|
|
1121
|
+
let conf = resolveConfig(spec[0]);
|
|
1122
|
+
if (spec.length == 1)
|
|
1123
|
+
return conf;
|
|
1124
|
+
let rest = resolveConfig(spec.slice(1));
|
|
1125
|
+
if (!rest || !conf)
|
|
1126
|
+
return conf || rest;
|
|
1127
|
+
let conc = /* @__PURE__ */ __name((a, b) => (a || none).concat(b || none), "conc");
|
|
1128
|
+
let wrapA = conf.wrap, wrapB = rest.wrap;
|
|
1129
|
+
return {
|
|
1130
|
+
props: conc(conf.props, rest.props),
|
|
1131
|
+
defineNodes: conc(conf.defineNodes, rest.defineNodes),
|
|
1132
|
+
parseBlock: conc(conf.parseBlock, rest.parseBlock),
|
|
1133
|
+
parseInline: conc(conf.parseInline, rest.parseInline),
|
|
1134
|
+
remove: conc(conf.remove, rest.remove),
|
|
1135
|
+
wrap: !wrapA ? wrapB : !wrapB ? wrapA : (inner, input, fragments, ranges) => wrapA(wrapB(inner, input, fragments, ranges), input, fragments, ranges)
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
__name(resolveConfig, "resolveConfig");
|
|
1139
|
+
function findName(names, name) {
|
|
1140
|
+
let found = names.indexOf(name);
|
|
1141
|
+
if (found < 0)
|
|
1142
|
+
throw new RangeError(`Position specified relative to unknown parser ${name}`);
|
|
1143
|
+
return found;
|
|
1144
|
+
}
|
|
1145
|
+
__name(findName, "findName");
|
|
1146
|
+
let nodeTypes = [NodeType.none];
|
|
1147
|
+
for (let i = 1, name; name = Type[i]; i++) {
|
|
1148
|
+
nodeTypes[i] = NodeType.define({
|
|
1149
|
+
id: i,
|
|
1150
|
+
name,
|
|
1151
|
+
props: i >= Type.Escape ? [] : [[NodeProp.group, i in DefaultSkipMarkup ? ["Block", "BlockContext"] : ["Block", "LeafBlock"]]],
|
|
1152
|
+
top: name == "Document"
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
const none = [];
|
|
1156
|
+
const _Buffer = class _Buffer {
|
|
1157
|
+
constructor(nodeSet) {
|
|
1158
|
+
this.nodeSet = nodeSet;
|
|
1159
|
+
this.content = [];
|
|
1160
|
+
this.nodes = [];
|
|
1161
|
+
}
|
|
1162
|
+
write(type, from, to, children = 0) {
|
|
1163
|
+
this.content.push(type, from, to, 4 + children * 4);
|
|
1164
|
+
return this;
|
|
1165
|
+
}
|
|
1166
|
+
writeElements(elts, offset = 0) {
|
|
1167
|
+
for (let e of elts)
|
|
1168
|
+
e.writeTo(this, offset);
|
|
1169
|
+
return this;
|
|
1170
|
+
}
|
|
1171
|
+
finish(type, length) {
|
|
1172
|
+
return Tree.build({
|
|
1173
|
+
buffer: this.content,
|
|
1174
|
+
nodeSet: this.nodeSet,
|
|
1175
|
+
reused: this.nodes,
|
|
1176
|
+
topID: type,
|
|
1177
|
+
length
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
__name(_Buffer, "Buffer");
|
|
1182
|
+
let Buffer2 = _Buffer;
|
|
1183
|
+
const _Element = class _Element {
|
|
1184
|
+
/**
|
|
1185
|
+
@internal
|
|
1186
|
+
*/
|
|
1187
|
+
constructor(type, from, to, children = none) {
|
|
1188
|
+
this.type = type;
|
|
1189
|
+
this.from = from;
|
|
1190
|
+
this.to = to;
|
|
1191
|
+
this.children = children;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
@internal
|
|
1195
|
+
*/
|
|
1196
|
+
writeTo(buf, offset) {
|
|
1197
|
+
let startOff = buf.content.length;
|
|
1198
|
+
buf.writeElements(this.children, offset);
|
|
1199
|
+
buf.content.push(this.type, this.from + offset, this.to + offset, buf.content.length + 4 - startOff);
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
@internal
|
|
1203
|
+
*/
|
|
1204
|
+
toTree(nodeSet) {
|
|
1205
|
+
return new Buffer2(nodeSet).writeElements(this.children, -this.from).finish(this.type, this.to - this.from);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
__name(_Element, "Element");
|
|
1209
|
+
let Element = _Element;
|
|
1210
|
+
const _TreeElement = class _TreeElement {
|
|
1211
|
+
constructor(tree, from) {
|
|
1212
|
+
this.tree = tree;
|
|
1213
|
+
this.from = from;
|
|
1214
|
+
}
|
|
1215
|
+
get to() {
|
|
1216
|
+
return this.from + this.tree.length;
|
|
1217
|
+
}
|
|
1218
|
+
get type() {
|
|
1219
|
+
return this.tree.type.id;
|
|
1220
|
+
}
|
|
1221
|
+
get children() {
|
|
1222
|
+
return none;
|
|
1223
|
+
}
|
|
1224
|
+
writeTo(buf, offset) {
|
|
1225
|
+
buf.nodes.push(this.tree);
|
|
1226
|
+
buf.content.push(buf.nodes.length - 1, this.from + offset, this.to + offset, -1);
|
|
1227
|
+
}
|
|
1228
|
+
toTree() {
|
|
1229
|
+
return this.tree;
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
__name(_TreeElement, "TreeElement");
|
|
1233
|
+
let TreeElement = _TreeElement;
|
|
1234
|
+
function elt(type, from, to, children) {
|
|
1235
|
+
return new Element(type, from, to, children);
|
|
1236
|
+
}
|
|
1237
|
+
__name(elt, "elt");
|
|
1238
|
+
const EmphasisUnderscore = { resolve: "Emphasis", mark: "EmphasisMark" };
|
|
1239
|
+
const EmphasisAsterisk = { resolve: "Emphasis", mark: "EmphasisMark" };
|
|
1240
|
+
const LinkStart = {}, ImageStart = {};
|
|
1241
|
+
const _InlineDelimiter = class _InlineDelimiter {
|
|
1242
|
+
constructor(type, from, to, side) {
|
|
1243
|
+
this.type = type;
|
|
1244
|
+
this.from = from;
|
|
1245
|
+
this.to = to;
|
|
1246
|
+
this.side = side;
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
__name(_InlineDelimiter, "InlineDelimiter");
|
|
1250
|
+
let InlineDelimiter = _InlineDelimiter;
|
|
1251
|
+
const Escapable = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
|
1252
|
+
let Punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;
|
|
1253
|
+
try {
|
|
1254
|
+
Punctuation = new RegExp("[\\p{S}|\\p{P}]", "u");
|
|
1255
|
+
} catch (_) {
|
|
1256
|
+
}
|
|
1257
|
+
const DefaultInline = {
|
|
1258
|
+
Escape(cx, next, start) {
|
|
1259
|
+
if (next != 92 || start == cx.end - 1)
|
|
1260
|
+
return -1;
|
|
1261
|
+
let escaped = cx.char(start + 1);
|
|
1262
|
+
for (let i = 0; i < Escapable.length; i++)
|
|
1263
|
+
if (Escapable.charCodeAt(i) == escaped)
|
|
1264
|
+
return cx.append(elt(Type.Escape, start, start + 2));
|
|
1265
|
+
return -1;
|
|
1266
|
+
},
|
|
1267
|
+
Entity(cx, next, start) {
|
|
1268
|
+
if (next != 38)
|
|
1269
|
+
return -1;
|
|
1270
|
+
let m = /^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(cx.slice(start + 1, start + 31));
|
|
1271
|
+
return m ? cx.append(elt(Type.Entity, start, start + 1 + m[0].length)) : -1;
|
|
1272
|
+
},
|
|
1273
|
+
InlineCode(cx, next, start) {
|
|
1274
|
+
if (next != 96 || start && cx.char(start - 1) == 96)
|
|
1275
|
+
return -1;
|
|
1276
|
+
let pos = start + 1;
|
|
1277
|
+
while (pos < cx.end && cx.char(pos) == 96)
|
|
1278
|
+
pos++;
|
|
1279
|
+
let size = pos - start, curSize = 0;
|
|
1280
|
+
for (; pos < cx.end; pos++) {
|
|
1281
|
+
if (cx.char(pos) == 96) {
|
|
1282
|
+
curSize++;
|
|
1283
|
+
if (curSize == size && cx.char(pos + 1) != 96)
|
|
1284
|
+
return cx.append(elt(Type.InlineCode, start, pos + 1, [
|
|
1285
|
+
elt(Type.CodeMark, start, start + size),
|
|
1286
|
+
elt(Type.CodeMark, pos + 1 - size, pos + 1)
|
|
1287
|
+
]));
|
|
1288
|
+
} else {
|
|
1289
|
+
curSize = 0;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return -1;
|
|
1293
|
+
},
|
|
1294
|
+
HTMLTag(cx, next, start) {
|
|
1295
|
+
if (next != 60 || start == cx.end - 1)
|
|
1296
|
+
return -1;
|
|
1297
|
+
let after = cx.slice(start + 1, cx.end);
|
|
1298
|
+
let url = /^(?:[a-z][-\w+.]+:[^\s>]+|[a-z\d.!#$%&'*+/=?^_`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)>/i.exec(after);
|
|
1299
|
+
if (url) {
|
|
1300
|
+
return cx.append(elt(Type.Autolink, start, start + 1 + url[0].length, [
|
|
1301
|
+
elt(Type.LinkMark, start, start + 1),
|
|
1302
|
+
// url[0] includes the closing bracket, so exclude it from this slice
|
|
1303
|
+
elt(Type.URL, start + 1, start + url[0].length),
|
|
1304
|
+
elt(Type.LinkMark, start + url[0].length, start + 1 + url[0].length)
|
|
1305
|
+
]));
|
|
1306
|
+
}
|
|
1307
|
+
let comment = /^!--[^>](?:-[^-]|[^-])*?-->/i.exec(after);
|
|
1308
|
+
if (comment)
|
|
1309
|
+
return cx.append(elt(Type.Comment, start, start + 1 + comment[0].length));
|
|
1310
|
+
let procInst = /^\?[^]*?\?>/.exec(after);
|
|
1311
|
+
if (procInst)
|
|
1312
|
+
return cx.append(elt(Type.ProcessingInstruction, start, start + 1 + procInst[0].length));
|
|
1313
|
+
let m = /^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(after);
|
|
1314
|
+
if (!m)
|
|
1315
|
+
return -1;
|
|
1316
|
+
return cx.append(elt(Type.HTMLTag, start, start + 1 + m[0].length));
|
|
1317
|
+
},
|
|
1318
|
+
Emphasis(cx, next, start) {
|
|
1319
|
+
if (next != 95 && next != 42)
|
|
1320
|
+
return -1;
|
|
1321
|
+
let pos = start + 1;
|
|
1322
|
+
while (cx.char(pos) == next)
|
|
1323
|
+
pos++;
|
|
1324
|
+
let before = cx.slice(start - 1, start), after = cx.slice(pos, pos + 1);
|
|
1325
|
+
let pBefore = Punctuation.test(before), pAfter = Punctuation.test(after);
|
|
1326
|
+
let sBefore = /\s|^$/.test(before), sAfter = /\s|^$/.test(after);
|
|
1327
|
+
let leftFlanking = !sAfter && (!pAfter || sBefore || pBefore);
|
|
1328
|
+
let rightFlanking = !sBefore && (!pBefore || sAfter || pAfter);
|
|
1329
|
+
let canOpen = leftFlanking && (next == 42 || !rightFlanking || pBefore);
|
|
1330
|
+
let canClose = rightFlanking && (next == 42 || !leftFlanking || pAfter);
|
|
1331
|
+
return cx.append(new InlineDelimiter(next == 95 ? EmphasisUnderscore : EmphasisAsterisk, start, pos, (canOpen ? 1 : 0) | (canClose ? 2 : 0)));
|
|
1332
|
+
},
|
|
1333
|
+
HardBreak(cx, next, start) {
|
|
1334
|
+
if (next == 92 && cx.char(start + 1) == 10)
|
|
1335
|
+
return cx.append(elt(Type.HardBreak, start, start + 2));
|
|
1336
|
+
if (next == 32) {
|
|
1337
|
+
let pos = start + 1;
|
|
1338
|
+
while (cx.char(pos) == 32)
|
|
1339
|
+
pos++;
|
|
1340
|
+
if (cx.char(pos) == 10 && pos >= start + 2)
|
|
1341
|
+
return cx.append(elt(Type.HardBreak, start, pos + 1));
|
|
1342
|
+
}
|
|
1343
|
+
return -1;
|
|
1344
|
+
},
|
|
1345
|
+
Link(cx, next, start) {
|
|
1346
|
+
return next == 91 ? cx.append(new InlineDelimiter(
|
|
1347
|
+
LinkStart,
|
|
1348
|
+
start,
|
|
1349
|
+
start + 1,
|
|
1350
|
+
1
|
|
1351
|
+
/* Mark.Open */
|
|
1352
|
+
)) : -1;
|
|
1353
|
+
},
|
|
1354
|
+
Image(cx, next, start) {
|
|
1355
|
+
return next == 33 && cx.char(start + 1) == 91 ? cx.append(new InlineDelimiter(
|
|
1356
|
+
ImageStart,
|
|
1357
|
+
start,
|
|
1358
|
+
start + 2,
|
|
1359
|
+
1
|
|
1360
|
+
/* Mark.Open */
|
|
1361
|
+
)) : -1;
|
|
1362
|
+
},
|
|
1363
|
+
LinkEnd(cx, next, start) {
|
|
1364
|
+
if (next != 93)
|
|
1365
|
+
return -1;
|
|
1366
|
+
for (let i = cx.parts.length - 1; i >= 0; i--) {
|
|
1367
|
+
let part = cx.parts[i];
|
|
1368
|
+
if (part instanceof InlineDelimiter && (part.type == LinkStart || part.type == ImageStart)) {
|
|
1369
|
+
if (!part.side || cx.skipSpace(part.to) == start && !/[(\[]/.test(cx.slice(start + 1, start + 2))) {
|
|
1370
|
+
cx.parts[i] = null;
|
|
1371
|
+
return -1;
|
|
1372
|
+
}
|
|
1373
|
+
let content = cx.takeContent(i);
|
|
1374
|
+
let link = cx.parts[i] = finishLink(cx, content, part.type == LinkStart ? Type.Link : Type.Image, part.from, start + 1);
|
|
1375
|
+
if (part.type == LinkStart)
|
|
1376
|
+
for (let j = 0; j < i; j++) {
|
|
1377
|
+
let p = cx.parts[j];
|
|
1378
|
+
if (p instanceof InlineDelimiter && p.type == LinkStart)
|
|
1379
|
+
p.side = 0;
|
|
1380
|
+
}
|
|
1381
|
+
return link.to;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
return -1;
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
function finishLink(cx, content, type, start, startPos) {
|
|
1388
|
+
let { text } = cx, next = cx.char(startPos), endPos = startPos;
|
|
1389
|
+
content.unshift(elt(Type.LinkMark, start, start + (type == Type.Image ? 2 : 1)));
|
|
1390
|
+
content.push(elt(Type.LinkMark, startPos - 1, startPos));
|
|
1391
|
+
if (next == 40) {
|
|
1392
|
+
let pos = cx.skipSpace(startPos + 1);
|
|
1393
|
+
let dest = parseURL(text, pos - cx.offset, cx.offset), title;
|
|
1394
|
+
if (dest) {
|
|
1395
|
+
pos = cx.skipSpace(dest.to);
|
|
1396
|
+
if (pos != dest.to) {
|
|
1397
|
+
title = parseLinkTitle(text, pos - cx.offset, cx.offset);
|
|
1398
|
+
if (title)
|
|
1399
|
+
pos = cx.skipSpace(title.to);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (cx.char(pos) == 41) {
|
|
1403
|
+
content.push(elt(Type.LinkMark, startPos, startPos + 1));
|
|
1404
|
+
endPos = pos + 1;
|
|
1405
|
+
if (dest)
|
|
1406
|
+
content.push(dest);
|
|
1407
|
+
if (title)
|
|
1408
|
+
content.push(title);
|
|
1409
|
+
content.push(elt(Type.LinkMark, pos, endPos));
|
|
1410
|
+
}
|
|
1411
|
+
} else if (next == 91) {
|
|
1412
|
+
let label = parseLinkLabel(text, startPos - cx.offset, cx.offset, false);
|
|
1413
|
+
if (label) {
|
|
1414
|
+
content.push(label);
|
|
1415
|
+
endPos = label.to;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return elt(type, start, endPos, content);
|
|
1419
|
+
}
|
|
1420
|
+
__name(finishLink, "finishLink");
|
|
1421
|
+
function parseURL(text, start, offset) {
|
|
1422
|
+
let next = text.charCodeAt(start);
|
|
1423
|
+
if (next == 60) {
|
|
1424
|
+
for (let pos = start + 1; pos < text.length; pos++) {
|
|
1425
|
+
let ch = text.charCodeAt(pos);
|
|
1426
|
+
if (ch == 62)
|
|
1427
|
+
return elt(Type.URL, start + offset, pos + 1 + offset);
|
|
1428
|
+
if (ch == 60 || ch == 10)
|
|
1429
|
+
return false;
|
|
1430
|
+
}
|
|
1431
|
+
return null;
|
|
1432
|
+
} else {
|
|
1433
|
+
let depth = 0, pos = start;
|
|
1434
|
+
for (let escaped = false; pos < text.length; pos++) {
|
|
1435
|
+
let ch = text.charCodeAt(pos);
|
|
1436
|
+
if (space(ch)) {
|
|
1437
|
+
break;
|
|
1438
|
+
} else if (escaped) {
|
|
1439
|
+
escaped = false;
|
|
1440
|
+
} else if (ch == 40) {
|
|
1441
|
+
depth++;
|
|
1442
|
+
} else if (ch == 41) {
|
|
1443
|
+
if (!depth)
|
|
1444
|
+
break;
|
|
1445
|
+
depth--;
|
|
1446
|
+
} else if (ch == 92) {
|
|
1447
|
+
escaped = true;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return pos > start ? elt(Type.URL, start + offset, pos + offset) : pos == text.length ? null : false;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
__name(parseURL, "parseURL");
|
|
1454
|
+
function parseLinkTitle(text, start, offset) {
|
|
1455
|
+
let next = text.charCodeAt(start);
|
|
1456
|
+
if (next != 39 && next != 34 && next != 40)
|
|
1457
|
+
return false;
|
|
1458
|
+
let end = next == 40 ? 41 : next;
|
|
1459
|
+
for (let pos = start + 1, escaped = false; pos < text.length; pos++) {
|
|
1460
|
+
let ch = text.charCodeAt(pos);
|
|
1461
|
+
if (escaped)
|
|
1462
|
+
escaped = false;
|
|
1463
|
+
else if (ch == end)
|
|
1464
|
+
return elt(Type.LinkTitle, start + offset, pos + 1 + offset);
|
|
1465
|
+
else if (ch == 92)
|
|
1466
|
+
escaped = true;
|
|
1467
|
+
}
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1470
|
+
__name(parseLinkTitle, "parseLinkTitle");
|
|
1471
|
+
function parseLinkLabel(text, start, offset, requireNonWS) {
|
|
1472
|
+
for (let escaped = false, pos = start + 1, end = Math.min(text.length, pos + 999); pos < end; pos++) {
|
|
1473
|
+
let ch = text.charCodeAt(pos);
|
|
1474
|
+
if (escaped)
|
|
1475
|
+
escaped = false;
|
|
1476
|
+
else if (ch == 93)
|
|
1477
|
+
return requireNonWS ? false : elt(Type.LinkLabel, start + offset, pos + 1 + offset);
|
|
1478
|
+
else {
|
|
1479
|
+
if (requireNonWS && !space(ch))
|
|
1480
|
+
requireNonWS = false;
|
|
1481
|
+
if (ch == 91)
|
|
1482
|
+
return false;
|
|
1483
|
+
else if (ch == 92)
|
|
1484
|
+
escaped = true;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
return null;
|
|
1488
|
+
}
|
|
1489
|
+
__name(parseLinkLabel, "parseLinkLabel");
|
|
1490
|
+
const _InlineContext = class _InlineContext {
|
|
1491
|
+
/**
|
|
1492
|
+
@internal
|
|
1493
|
+
*/
|
|
1494
|
+
constructor(parser2, text, offset) {
|
|
1495
|
+
this.parser = parser2;
|
|
1496
|
+
this.text = text;
|
|
1497
|
+
this.offset = offset;
|
|
1498
|
+
this.parts = [];
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
Get the character code at the given (document-relative)
|
|
1502
|
+
position.
|
|
1503
|
+
*/
|
|
1504
|
+
char(pos) {
|
|
1505
|
+
return pos >= this.end ? -1 : this.text.charCodeAt(pos - this.offset);
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
The position of the end of this inline section.
|
|
1509
|
+
*/
|
|
1510
|
+
get end() {
|
|
1511
|
+
return this.offset + this.text.length;
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
Get a substring of this inline section. Again uses
|
|
1515
|
+
document-relative positions.
|
|
1516
|
+
*/
|
|
1517
|
+
slice(from, to) {
|
|
1518
|
+
return this.text.slice(from - this.offset, to - this.offset);
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
@internal
|
|
1522
|
+
*/
|
|
1523
|
+
append(elt2) {
|
|
1524
|
+
this.parts.push(elt2);
|
|
1525
|
+
return elt2.to;
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
Add a [delimiter](#DelimiterType) at this given position. `open`
|
|
1529
|
+
and `close` indicate whether this delimiter is opening, closing,
|
|
1530
|
+
or both. Returns the end of the delimiter, for convenient
|
|
1531
|
+
returning from [parse functions](#InlineParser.parse).
|
|
1532
|
+
*/
|
|
1533
|
+
addDelimiter(type, from, to, open, close) {
|
|
1534
|
+
return this.append(new InlineDelimiter(type, from, to, (open ? 1 : 0) | (close ? 2 : 0)));
|
|
1535
|
+
}
|
|
1536
|
+
/**
|
|
1537
|
+
Returns true when there is an unmatched link or image opening
|
|
1538
|
+
token before the current position.
|
|
1539
|
+
*/
|
|
1540
|
+
get hasOpenLink() {
|
|
1541
|
+
for (let i = this.parts.length - 1; i >= 0; i--) {
|
|
1542
|
+
let part = this.parts[i];
|
|
1543
|
+
if (part instanceof InlineDelimiter && (part.type == LinkStart || part.type == ImageStart))
|
|
1544
|
+
return true;
|
|
1545
|
+
}
|
|
1546
|
+
return false;
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
Add an inline element. Returns the end of the element.
|
|
1550
|
+
*/
|
|
1551
|
+
addElement(elt2) {
|
|
1552
|
+
return this.append(elt2);
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
Resolve markers between this.parts.length and from, wrapping matched markers in the
|
|
1556
|
+
appropriate node and updating the content of this.parts. @internal
|
|
1557
|
+
*/
|
|
1558
|
+
resolveMarkers(from) {
|
|
1559
|
+
for (let i = from; i < this.parts.length; i++) {
|
|
1560
|
+
let close = this.parts[i];
|
|
1561
|
+
if (!(close instanceof InlineDelimiter && close.type.resolve && close.side & 2))
|
|
1562
|
+
continue;
|
|
1563
|
+
let emp = close.type == EmphasisUnderscore || close.type == EmphasisAsterisk;
|
|
1564
|
+
let closeSize = close.to - close.from;
|
|
1565
|
+
let open, j = i - 1;
|
|
1566
|
+
for (; j >= from; j--) {
|
|
1567
|
+
let part = this.parts[j];
|
|
1568
|
+
if (part instanceof InlineDelimiter && part.side & 1 && part.type == close.type && // Ignore emphasis delimiters where the character count doesn't match
|
|
1569
|
+
!(emp && (close.side & 1 || part.side & 2) && (part.to - part.from + closeSize) % 3 == 0 && ((part.to - part.from) % 3 || closeSize % 3))) {
|
|
1570
|
+
open = part;
|
|
1571
|
+
break;
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
if (!open)
|
|
1575
|
+
continue;
|
|
1576
|
+
let type = close.type.resolve, content = [];
|
|
1577
|
+
let start = open.from, end = close.to;
|
|
1578
|
+
if (emp) {
|
|
1579
|
+
let size = Math.min(2, open.to - open.from, closeSize);
|
|
1580
|
+
start = open.to - size;
|
|
1581
|
+
end = close.from + size;
|
|
1582
|
+
type = size == 1 ? "Emphasis" : "StrongEmphasis";
|
|
1583
|
+
}
|
|
1584
|
+
if (open.type.mark)
|
|
1585
|
+
content.push(this.elt(open.type.mark, start, open.to));
|
|
1586
|
+
for (let k = j + 1; k < i; k++) {
|
|
1587
|
+
if (this.parts[k] instanceof Element)
|
|
1588
|
+
content.push(this.parts[k]);
|
|
1589
|
+
this.parts[k] = null;
|
|
1590
|
+
}
|
|
1591
|
+
if (close.type.mark)
|
|
1592
|
+
content.push(this.elt(close.type.mark, close.from, end));
|
|
1593
|
+
let element = this.elt(type, start, end, content);
|
|
1594
|
+
this.parts[j] = emp && open.from != start ? new InlineDelimiter(open.type, open.from, start, open.side) : null;
|
|
1595
|
+
let keep = this.parts[i] = emp && close.to != end ? new InlineDelimiter(close.type, end, close.to, close.side) : null;
|
|
1596
|
+
if (keep)
|
|
1597
|
+
this.parts.splice(i, 0, element);
|
|
1598
|
+
else
|
|
1599
|
+
this.parts[i] = element;
|
|
1600
|
+
}
|
|
1601
|
+
let result = [];
|
|
1602
|
+
for (let i = from; i < this.parts.length; i++) {
|
|
1603
|
+
let part = this.parts[i];
|
|
1604
|
+
if (part instanceof Element)
|
|
1605
|
+
result.push(part);
|
|
1606
|
+
}
|
|
1607
|
+
return result;
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
Find an opening delimiter of the given type. Returns `null` if
|
|
1611
|
+
no delimiter is found, or an index that can be passed to
|
|
1612
|
+
[`takeContent`](#InlineContext.takeContent) otherwise.
|
|
1613
|
+
*/
|
|
1614
|
+
findOpeningDelimiter(type) {
|
|
1615
|
+
for (let i = this.parts.length - 1; i >= 0; i--) {
|
|
1616
|
+
let part = this.parts[i];
|
|
1617
|
+
if (part instanceof InlineDelimiter && part.type == type)
|
|
1618
|
+
return i;
|
|
1619
|
+
}
|
|
1620
|
+
return null;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
Remove all inline elements and delimiters starting from the
|
|
1624
|
+
given index (which you should get from
|
|
1625
|
+
[`findOpeningDelimiter`](#InlineContext.findOpeningDelimiter),
|
|
1626
|
+
resolve delimiters inside of them, and return them as an array
|
|
1627
|
+
of elements.
|
|
1628
|
+
*/
|
|
1629
|
+
takeContent(startIndex) {
|
|
1630
|
+
let content = this.resolveMarkers(startIndex);
|
|
1631
|
+
this.parts.length = startIndex;
|
|
1632
|
+
return content;
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
Skip space after the given (document) position, returning either
|
|
1636
|
+
the position of the next non-space character or the end of the
|
|
1637
|
+
section.
|
|
1638
|
+
*/
|
|
1639
|
+
skipSpace(from) {
|
|
1640
|
+
return skipSpace(this.text, from - this.offset) + this.offset;
|
|
1641
|
+
}
|
|
1642
|
+
elt(type, from, to, children) {
|
|
1643
|
+
if (typeof type == "string")
|
|
1644
|
+
return elt(this.parser.getNodeType(type), from, to, children);
|
|
1645
|
+
return new TreeElement(type, from);
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1648
|
+
__name(_InlineContext, "InlineContext");
|
|
1649
|
+
let InlineContext = _InlineContext;
|
|
1650
|
+
function injectMarks(elements, marks) {
|
|
1651
|
+
if (!marks.length)
|
|
1652
|
+
return elements;
|
|
1653
|
+
if (!elements.length)
|
|
1654
|
+
return marks;
|
|
1655
|
+
let elts = elements.slice(), eI = 0;
|
|
1656
|
+
for (let mark of marks) {
|
|
1657
|
+
while (eI < elts.length && elts[eI].to < mark.to)
|
|
1658
|
+
eI++;
|
|
1659
|
+
if (eI < elts.length && elts[eI].from < mark.from) {
|
|
1660
|
+
let e = elts[eI];
|
|
1661
|
+
if (e instanceof Element)
|
|
1662
|
+
elts[eI] = new Element(e.type, e.from, e.to, injectMarks(e.children, [mark]));
|
|
1663
|
+
} else {
|
|
1664
|
+
elts.splice(eI++, 0, mark);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
return elts;
|
|
1668
|
+
}
|
|
1669
|
+
__name(injectMarks, "injectMarks");
|
|
1670
|
+
const NotLast = [Type.CodeBlock, Type.ListItem, Type.OrderedList, Type.BulletList];
|
|
1671
|
+
const _FragmentCursor = class _FragmentCursor {
|
|
1672
|
+
constructor(fragments, input) {
|
|
1673
|
+
this.fragments = fragments;
|
|
1674
|
+
this.input = input;
|
|
1675
|
+
this.i = 0;
|
|
1676
|
+
this.fragment = null;
|
|
1677
|
+
this.fragmentEnd = -1;
|
|
1678
|
+
this.cursor = null;
|
|
1679
|
+
if (fragments.length)
|
|
1680
|
+
this.fragment = fragments[this.i++];
|
|
1681
|
+
}
|
|
1682
|
+
nextFragment() {
|
|
1683
|
+
this.fragment = this.i < this.fragments.length ? this.fragments[this.i++] : null;
|
|
1684
|
+
this.cursor = null;
|
|
1685
|
+
this.fragmentEnd = -1;
|
|
1686
|
+
}
|
|
1687
|
+
moveTo(pos, lineStart) {
|
|
1688
|
+
while (this.fragment && this.fragment.to <= pos)
|
|
1689
|
+
this.nextFragment();
|
|
1690
|
+
if (!this.fragment || this.fragment.from > (pos ? pos - 1 : 0))
|
|
1691
|
+
return false;
|
|
1692
|
+
if (this.fragmentEnd < 0) {
|
|
1693
|
+
let end = this.fragment.to;
|
|
1694
|
+
while (end > 0 && this.input.read(end - 1, end) != "\n")
|
|
1695
|
+
end--;
|
|
1696
|
+
this.fragmentEnd = end ? end - 1 : 0;
|
|
1697
|
+
}
|
|
1698
|
+
let c = this.cursor;
|
|
1699
|
+
if (!c) {
|
|
1700
|
+
c = this.cursor = this.fragment.tree.cursor();
|
|
1701
|
+
c.firstChild();
|
|
1702
|
+
}
|
|
1703
|
+
let rPos = pos + this.fragment.offset;
|
|
1704
|
+
while (c.to <= rPos)
|
|
1705
|
+
if (!c.parent())
|
|
1706
|
+
return false;
|
|
1707
|
+
for (; ; ) {
|
|
1708
|
+
if (c.from >= rPos)
|
|
1709
|
+
return this.fragment.from <= lineStart;
|
|
1710
|
+
if (!c.childAfter(rPos))
|
|
1711
|
+
return false;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
matches(hash) {
|
|
1715
|
+
let tree = this.cursor.tree;
|
|
1716
|
+
return tree && tree.prop(NodeProp.contextHash) == hash;
|
|
1717
|
+
}
|
|
1718
|
+
takeNodes(cx) {
|
|
1719
|
+
let cur = this.cursor, off = this.fragment.offset, fragEnd = this.fragmentEnd - (this.fragment.openEnd ? 1 : 0);
|
|
1720
|
+
let start = cx.absoluteLineStart, end = start, blockI = cx.block.children.length;
|
|
1721
|
+
let prevEnd = end, prevI = blockI;
|
|
1722
|
+
for (; ; ) {
|
|
1723
|
+
if (cur.to - off > fragEnd) {
|
|
1724
|
+
if (cur.type.isAnonymous && cur.firstChild())
|
|
1725
|
+
continue;
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
let pos = toRelative(cur.from - off, cx.ranges);
|
|
1729
|
+
if (cur.to - off <= cx.ranges[cx.rangeI].to) {
|
|
1730
|
+
cx.addNode(cur.tree, pos);
|
|
1731
|
+
} else {
|
|
1732
|
+
let dummy = new Tree(cx.parser.nodeSet.types[Type.Paragraph], [], [], 0, cx.block.hashProp);
|
|
1733
|
+
cx.reusePlaceholders.set(dummy, cur.tree);
|
|
1734
|
+
cx.addNode(dummy, pos);
|
|
1735
|
+
}
|
|
1736
|
+
if (cur.type.is("Block")) {
|
|
1737
|
+
if (NotLast.indexOf(cur.type.id) < 0) {
|
|
1738
|
+
end = cur.to - off;
|
|
1739
|
+
blockI = cx.block.children.length;
|
|
1740
|
+
} else {
|
|
1741
|
+
end = prevEnd;
|
|
1742
|
+
blockI = prevI;
|
|
1743
|
+
prevEnd = cur.to - off;
|
|
1744
|
+
prevI = cx.block.children.length;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
if (!cur.nextSibling())
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
while (cx.block.children.length > blockI) {
|
|
1751
|
+
cx.block.children.pop();
|
|
1752
|
+
cx.block.positions.pop();
|
|
1753
|
+
}
|
|
1754
|
+
return end - start;
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
__name(_FragmentCursor, "FragmentCursor");
|
|
1758
|
+
let FragmentCursor = _FragmentCursor;
|
|
1759
|
+
function toRelative(abs, ranges) {
|
|
1760
|
+
let pos = abs;
|
|
1761
|
+
for (let i = 1; i < ranges.length; i++) {
|
|
1762
|
+
let gapFrom = ranges[i - 1].to, gapTo = ranges[i].from;
|
|
1763
|
+
if (gapFrom < abs)
|
|
1764
|
+
pos -= gapTo - gapFrom;
|
|
1765
|
+
}
|
|
1766
|
+
return pos;
|
|
1767
|
+
}
|
|
1768
|
+
__name(toRelative, "toRelative");
|
|
1769
|
+
const markdownHighlighting = styleTags({
|
|
1770
|
+
"Blockquote/...": tags.quote,
|
|
1771
|
+
HorizontalRule: tags.contentSeparator,
|
|
1772
|
+
"ATXHeading1/... SetextHeading1/...": tags.heading1,
|
|
1773
|
+
"ATXHeading2/... SetextHeading2/...": tags.heading2,
|
|
1774
|
+
"ATXHeading3/...": tags.heading3,
|
|
1775
|
+
"ATXHeading4/...": tags.heading4,
|
|
1776
|
+
"ATXHeading5/...": tags.heading5,
|
|
1777
|
+
"ATXHeading6/...": tags.heading6,
|
|
1778
|
+
"Comment CommentBlock": tags.comment,
|
|
1779
|
+
Escape: tags.escape,
|
|
1780
|
+
Entity: tags.character,
|
|
1781
|
+
"Emphasis/...": tags.emphasis,
|
|
1782
|
+
"StrongEmphasis/...": tags.strong,
|
|
1783
|
+
"Link/... Image/...": tags.link,
|
|
1784
|
+
"OrderedList/... BulletList/...": tags.list,
|
|
1785
|
+
"BlockQuote/...": tags.quote,
|
|
1786
|
+
"InlineCode CodeText": tags.monospace,
|
|
1787
|
+
"URL Autolink": tags.url,
|
|
1788
|
+
"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark": tags.processingInstruction,
|
|
1789
|
+
"CodeInfo LinkLabel": tags.labelName,
|
|
1790
|
+
LinkTitle: tags.string,
|
|
1791
|
+
Paragraph: tags.content
|
|
1792
|
+
});
|
|
1793
|
+
const parser = new MarkdownParser(new NodeSet(nodeTypes).extend(markdownHighlighting), Object.keys(DefaultBlockParsers).map((n) => DefaultBlockParsers[n]), Object.keys(DefaultBlockParsers).map((n) => DefaultLeafBlocks[n]), Object.keys(DefaultBlockParsers), DefaultEndLeaf, DefaultSkipMarkup, Object.keys(DefaultInline).map((n) => DefaultInline[n]), Object.keys(DefaultInline), []);
|
|
1794
|
+
({
|
|
1795
|
+
defineNodes: [
|
|
1796
|
+
{ name: "Superscript", style: tags.special(tags.content) },
|
|
1797
|
+
{ name: "SuperscriptMark", style: tags.processingInstruction }
|
|
1798
|
+
]
|
|
1799
|
+
});
|
|
1800
|
+
({
|
|
1801
|
+
defineNodes: [
|
|
1802
|
+
{ name: "Subscript", style: tags.special(tags.content) },
|
|
1803
|
+
{ name: "SubscriptMark", style: tags.processingInstruction }
|
|
1804
|
+
]
|
|
1805
|
+
});
|
|
1806
|
+
export {
|
|
1807
|
+
BlockContext,
|
|
1808
|
+
Element,
|
|
1809
|
+
InlineContext,
|
|
1810
|
+
LeafBlock,
|
|
1811
|
+
Line,
|
|
1812
|
+
MarkdownParser,
|
|
1813
|
+
parser
|
|
1814
|
+
};
|
|
1815
|
+
//# sourceMappingURL=index-CP3HrqN0.js.map
|