supamde 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +1228 -2
- package/dist/commands/block.d.ts +20 -0
- package/dist/commands/code-indent.d.ts +38 -0
- package/dist/commands/history.d.ts +6 -0
- package/dist/commands/indent.d.ts +28 -0
- package/dist/commands/inline.d.ts +9 -0
- package/dist/commands/keymap.d.ts +8 -0
- package/dist/commands/link-image.d.ts +13 -0
- package/dist/commands/list.d.ts +20 -0
- package/dist/commands/prefixes.d.ts +29 -0
- package/dist/commands/queries.d.ts +25 -0
- package/dist/commands/table.d.ts +7 -0
- package/dist/commands/types.d.ts +17 -0
- package/dist/editor/extensions.d.ts +14 -0
- package/dist/editor/highlight.d.ts +11 -0
- package/dist/editor/link-click.d.ts +53 -0
- package/dist/editor/link-hover-cursor.d.ts +44 -0
- package/dist/editor/math.d.ts +8 -0
- package/dist/editor/setup.d.ts +26 -0
- package/dist/editor/theme.d.ts +7 -0
- package/dist/editor/tokens.d.ts +16 -0
- package/dist/editor/value.d.ts +10 -0
- package/dist/features/autosave.d.ts +31 -0
- package/dist/features/image-upload.d.ts +73 -0
- package/dist/features/storage.d.ts +30 -0
- package/dist/features/upload-dom.d.ts +20 -0
- package/dist/features/upload-placeholder.d.ts +35 -0
- package/dist/features/word-count.d.ts +5 -0
- package/dist/i18n/de.d.ts +3 -0
- package/dist/i18n/en.d.ts +3 -0
- package/dist/i18n/facet.d.ts +9 -0
- package/dist/i18n/translator.d.ts +17 -0
- package/dist/i18n/types.d.ts +82 -0
- package/dist/index.d.ts +133 -0
- package/dist/livepreview/index.d.ts +22 -0
- package/dist/livepreview/plugin.d.ts +3 -0
- package/dist/livepreview/ranges.d.ts +62 -0
- package/dist/markdown/katex-marked.d.ts +20 -0
- package/dist/markdown/parse.d.ts +27 -0
- package/dist/markdown/sanitize.d.ts +6 -0
- package/dist/options.d.ts +83 -0
- package/dist/supamde.css +2 -0
- package/dist/supamde.mjs +3617 -0
- package/dist/supamde.mjs.map +1 -0
- package/dist/ui/actions.d.ts +51 -0
- package/dist/ui/fullscreen.d.ts +16 -0
- package/dist/ui/icons.d.ts +4 -0
- package/dist/ui/inject-styles.d.ts +13 -0
- package/dist/ui/preview.d.ts +27 -0
- package/dist/ui/shortcut-label.d.ts +24 -0
- package/dist/ui/statusbar.d.ts +28 -0
- package/dist/ui/toolbar-config.d.ts +36 -0
- package/dist/ui/toolbar.d.ts +16 -0
- package/dist/ui/update-listener.d.ts +15 -0
- package/dist/util/text-format.d.ts +11 -0
- package/dist/utils/html.d.ts +2 -0
- package/dist/utils/text.d.ts +41 -0
- package/dist/version.d.ts +2 -0
- package/package.json +96 -4
package/dist/supamde.mjs
ADDED
|
@@ -0,0 +1,3617 @@
|
|
|
1
|
+
import { Decoration as e, EditorView as t, ViewPlugin as n, keymap as r, placeholder as i } from "@codemirror/view";
|
|
2
|
+
import { Compartment as a, EditorState as o, Facet as s, RangeSet as c, StateEffect as l, StateField as u } from "@codemirror/state";
|
|
3
|
+
import { HighlightStyle as d, ensureSyntaxTree as f, getIndentUnit as p, indentUnit as m, syntaxHighlighting as ee, syntaxTree as h } from "@codemirror/language";
|
|
4
|
+
import { copyLineDown as te, copyLineUp as ne, defaultKeymap as re, deleteLine as ie, history as ae, historyKeymap as oe, moveLineDown as se, moveLineUp as ce, redo as le, undo as ue } from "@codemirror/commands";
|
|
5
|
+
import { deleteMarkupBackward as de, markdown as fe } from "@codemirror/lang-markdown";
|
|
6
|
+
import { GFM as pe } from "@lezer/markdown";
|
|
7
|
+
import { tags as g } from "@lezer/highlight";
|
|
8
|
+
//#region src/version.ts
|
|
9
|
+
var me = "0.1.0";
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/livepreview/ranges.ts
|
|
12
|
+
function he(e) {
|
|
13
|
+
return new Map(e.map((e) => [e, void 0]));
|
|
14
|
+
}
|
|
15
|
+
function ge(e) {
|
|
16
|
+
return (t) => t.startsWith(e);
|
|
17
|
+
}
|
|
18
|
+
var _e = {
|
|
19
|
+
inline: new Map([...he(["EmphasisMark", "StrikethroughMark"]), ["CodeMark", (e) => e === "InlineCode"]]),
|
|
20
|
+
block: new Map([...he(["QuoteMark"]), ["HeaderMark", ge("ATXHeading")]])
|
|
21
|
+
};
|
|
22
|
+
function ve(e, t) {
|
|
23
|
+
return t.some((t) => t.from <= e.to && t.to >= e.from);
|
|
24
|
+
}
|
|
25
|
+
function ye(e, t, n) {
|
|
26
|
+
let r = e.doc.lineAt(t.from), i = e.doc.sliceString(r.from, r.to);
|
|
27
|
+
if (t.to >= n.to) {
|
|
28
|
+
let e = t.from;
|
|
29
|
+
for (; e > r.from && i[e - r.from - 1] === " ";) e--;
|
|
30
|
+
return {
|
|
31
|
+
from: e,
|
|
32
|
+
to: t.to
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
let a = t.to;
|
|
36
|
+
for (; a < r.to && i[a - r.from] === " ";) a++;
|
|
37
|
+
return {
|
|
38
|
+
from: t.from,
|
|
39
|
+
to: a
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function be(e, t, n = _e) {
|
|
43
|
+
let r = e.selection.ranges, i = [], a = h(e);
|
|
44
|
+
for (let o of t) a.iterate({
|
|
45
|
+
from: o.from,
|
|
46
|
+
to: o.to,
|
|
47
|
+
enter: (t) => {
|
|
48
|
+
let a = t.name, o = n.inline.has(a), s = n.block.has(a);
|
|
49
|
+
if (!o && !s) return;
|
|
50
|
+
let c = t.node.parent;
|
|
51
|
+
if (!c) return;
|
|
52
|
+
let l = s ? n.block.get(a) : n.inline.get(a);
|
|
53
|
+
(!l || l(c.name)) && (ve(c, r) || i.push(s ? ye(e, t.node, c) : {
|
|
54
|
+
from: t.from,
|
|
55
|
+
to: t.to
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
i.sort((e, t) => e.from - t.from || e.to - t.to);
|
|
60
|
+
let o = [];
|
|
61
|
+
for (let e of i) {
|
|
62
|
+
let t = o[o.length - 1];
|
|
63
|
+
t && e.from <= t.to ? e.to > t.to && (t.to = e.to) : o.push({ ...e });
|
|
64
|
+
}
|
|
65
|
+
return o;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/livepreview/plugin.ts
|
|
69
|
+
var xe = e.replace({});
|
|
70
|
+
function Se(e) {
|
|
71
|
+
let t = be(e.state, e.visibleRanges);
|
|
72
|
+
return c.of(t.map((e) => xe.range(e.from, e.to)), !1);
|
|
73
|
+
}
|
|
74
|
+
var Ce = n.fromClass(class {
|
|
75
|
+
decorations;
|
|
76
|
+
constructor(e) {
|
|
77
|
+
this.decorations = Se(e);
|
|
78
|
+
}
|
|
79
|
+
update(e) {
|
|
80
|
+
(e.docChanged || e.selectionSet || e.viewportChanged) && (this.decorations = Se(e.view));
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
decorations: (e) => e.decorations,
|
|
84
|
+
provide: (n) => t.atomicRanges.of((t) => t.plugin(n)?.decorations ?? e.none)
|
|
85
|
+
}), we = ["source", "live"], Te = Ce, Ee = new a();
|
|
86
|
+
function De(e) {
|
|
87
|
+
return e === "live" ? Te : [];
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/options.ts
|
|
91
|
+
function Oe(e) {
|
|
92
|
+
return e === void 0 ? "source" : we.includes(e) ? e : (console.warn(`SupaMDE: unknown editorMode "${String(e)}" — using "source".`), "source");
|
|
93
|
+
}
|
|
94
|
+
function ke(e, t) {
|
|
95
|
+
return e === void 0 ? t : e === "tab" || Number.isInteger(e) && e > 0 ? e : (console.warn(`SupaMDE: invalid codeIndentUnit "${String(e)}" — using indentUnit (${t}).`), t);
|
|
96
|
+
}
|
|
97
|
+
function Ae(e) {
|
|
98
|
+
let t = e.indentUnit ?? 2;
|
|
99
|
+
return {
|
|
100
|
+
lineWrapping: e.lineWrapping ?? !0,
|
|
101
|
+
placeholder: e.placeholder ?? null,
|
|
102
|
+
autofocus: e.autofocus ?? !1,
|
|
103
|
+
tabSize: e.tabSize ?? 2,
|
|
104
|
+
indentUnit: t,
|
|
105
|
+
codeIndentUnit: ke(e.codeIndentUnit, t),
|
|
106
|
+
extraKeys: e.extraKeys ?? [],
|
|
107
|
+
editorMode: Oe(e.editorMode)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/commands/code-indent.ts
|
|
112
|
+
var je = s.define({ combine: (e) => e[0] ?? null });
|
|
113
|
+
function Me(e, t, n = h(e)) {
|
|
114
|
+
let r = !1;
|
|
115
|
+
return n.iterate({
|
|
116
|
+
from: t.from,
|
|
117
|
+
to: t.to,
|
|
118
|
+
enter: (e) => {
|
|
119
|
+
if (r) return !1;
|
|
120
|
+
if (e.name === "CodeBlock") return r = !0, !1;
|
|
121
|
+
if (e.name !== "FencedCode") return;
|
|
122
|
+
if (e.from >= t.from) return !1;
|
|
123
|
+
let n = e.node.firstChild, i = e.node.lastChild;
|
|
124
|
+
return i !== null && i.name === "CodeMark" && i.from !== n?.from && i.from >= t.from && i.from <= t.to || (r = !0), !1;
|
|
125
|
+
}
|
|
126
|
+
}), r;
|
|
127
|
+
}
|
|
128
|
+
function Ne(e, t) {
|
|
129
|
+
return f(e, t, 200) ?? h(e);
|
|
130
|
+
}
|
|
131
|
+
function Pe(e, t, n) {
|
|
132
|
+
let r = -1;
|
|
133
|
+
if (n.iterate({
|
|
134
|
+
from: t.from,
|
|
135
|
+
to: t.to,
|
|
136
|
+
enter: (e) => {
|
|
137
|
+
e.name === "QuoteMark" && e.from >= t.from && e.to <= t.to && (r = Math.max(r, e.to));
|
|
138
|
+
}
|
|
139
|
+
}), r < 0) return {
|
|
140
|
+
at: t.from,
|
|
141
|
+
missingSpace: !1
|
|
142
|
+
};
|
|
143
|
+
let i = e.doc.sliceString(r, r + 1) === " " && r < t.to;
|
|
144
|
+
return {
|
|
145
|
+
at: i ? r + 1 : r,
|
|
146
|
+
missingSpace: !i
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/editor/tokens.ts
|
|
151
|
+
var Fe = {
|
|
152
|
+
quote: "#6a737d",
|
|
153
|
+
link: "#0366d6",
|
|
154
|
+
border: "#ddd"
|
|
155
|
+
}, Ie = "system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif", Le = d.define([
|
|
156
|
+
{
|
|
157
|
+
tag: g.heading1,
|
|
158
|
+
fontSize: "1.6em",
|
|
159
|
+
fontWeight: "bold"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
tag: g.heading2,
|
|
163
|
+
fontSize: "1.4em",
|
|
164
|
+
fontWeight: "bold"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
tag: g.heading3,
|
|
168
|
+
fontSize: "1.25em",
|
|
169
|
+
fontWeight: "bold"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
tag: g.heading4,
|
|
173
|
+
fontSize: "1.15em",
|
|
174
|
+
fontWeight: "bold"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
tag: [g.heading5, g.heading6],
|
|
178
|
+
fontWeight: "bold"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
tag: g.strong,
|
|
182
|
+
fontWeight: "bold"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
tag: g.emphasis,
|
|
186
|
+
fontStyle: "italic"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
tag: g.strikethrough,
|
|
190
|
+
textDecoration: "line-through"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
tag: g.monospace,
|
|
194
|
+
fontFamily: "monospace"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
tag: g.quote,
|
|
198
|
+
color: Fe.quote,
|
|
199
|
+
fontStyle: "italic"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
tag: g.link,
|
|
203
|
+
color: Fe.link,
|
|
204
|
+
textDecoration: "underline"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
tag: g.url,
|
|
208
|
+
color: Fe.link
|
|
209
|
+
}
|
|
210
|
+
]), Re = ee(Le), ze = 36;
|
|
211
|
+
function Be(e, t, n) {
|
|
212
|
+
if (t != ze || e.char(n + 1) != ze) return -1;
|
|
213
|
+
let r = e.text.indexOf("$$", n + 2 - e.offset);
|
|
214
|
+
if (r < 0) return -1;
|
|
215
|
+
let i = r + e.offset + 2;
|
|
216
|
+
return e.addElement(e.elt("BlockMath", n, i));
|
|
217
|
+
}
|
|
218
|
+
function Ve(e, t, n) {
|
|
219
|
+
if (t != ze) return -1;
|
|
220
|
+
let r = e.text.indexOf("$", n + 1 - e.offset);
|
|
221
|
+
if (r < 0) return -1;
|
|
222
|
+
let i = r + e.offset + 1;
|
|
223
|
+
return i == n + 2 ? -1 : e.addElement(e.elt("InlineMath", n, i));
|
|
224
|
+
}
|
|
225
|
+
var He = {
|
|
226
|
+
defineNodes: ["InlineMath", "BlockMath"],
|
|
227
|
+
parseInline: [{
|
|
228
|
+
name: "BlockMath",
|
|
229
|
+
before: "Escape",
|
|
230
|
+
parse: Be
|
|
231
|
+
}, {
|
|
232
|
+
name: "InlineMath",
|
|
233
|
+
before: "Escape",
|
|
234
|
+
parse: Ve
|
|
235
|
+
}]
|
|
236
|
+
}, Ue = /^(https?:\/\/|mailto:)/i, We = /^[^\s@]+@[^\s@]+$/, Ge = /^www\./i, Ke = /* @__PURE__ */ new Set([
|
|
237
|
+
"/",
|
|
238
|
+
":",
|
|
239
|
+
"@",
|
|
240
|
+
"."
|
|
241
|
+
]);
|
|
242
|
+
function qe(e, t) {
|
|
243
|
+
return Ue.test(e) ? e : Ge.test(e) ? `https://${e}` : We.test(e) ? t !== void 0 && Ke.has(t) ? null : `mailto:${e}` : e;
|
|
244
|
+
}
|
|
245
|
+
function Je(e) {
|
|
246
|
+
for (let t = e; t; t = t.parent) if (t.name === "Link" || t.name === "Autolink") return t;
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
function Ye(e) {
|
|
250
|
+
for (let t = e; t; t = t.parent) {
|
|
251
|
+
if (t.name === "URL") return t;
|
|
252
|
+
if (t.name === "Link" || t.name === "Autolink") return null;
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
function Xe(e, t) {
|
|
257
|
+
let n = h(e).resolveInner(t, 0), r = Je(n);
|
|
258
|
+
if (r) {
|
|
259
|
+
let t = r.getChild("URL");
|
|
260
|
+
if (!t) return null;
|
|
261
|
+
let n = e.doc.sliceString(t.from, t.to);
|
|
262
|
+
return Ue.test(n) ? n : null;
|
|
263
|
+
}
|
|
264
|
+
let i = Ye(n);
|
|
265
|
+
if (i) {
|
|
266
|
+
let t = i.from > 0 ? e.doc.sliceString(i.from - 1, i.from) : void 0, n = qe(e.doc.sliceString(i.from, i.to), t);
|
|
267
|
+
return n === null ? null : Ue.test(n) ? n : null;
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
function Ze(e, t) {
|
|
272
|
+
if (!e.metaKey && !e.ctrlKey) return !1;
|
|
273
|
+
let n = t.posAtCoords({
|
|
274
|
+
x: e.clientX,
|
|
275
|
+
y: e.clientY
|
|
276
|
+
});
|
|
277
|
+
if (n === null) return !1;
|
|
278
|
+
let r = Xe(t.state, n);
|
|
279
|
+
return r ? (window.open(r, "_blank", "noopener,noreferrer"), e.preventDefault(), !0) : !1;
|
|
280
|
+
}
|
|
281
|
+
var Qe = t.domEventHandlers({ mousedown: Ze }), $e = "supamde-link-hover";
|
|
282
|
+
function et(e) {
|
|
283
|
+
return e.ctrlKey || e.metaKey;
|
|
284
|
+
}
|
|
285
|
+
var tt = class {
|
|
286
|
+
view;
|
|
287
|
+
lastX = 0;
|
|
288
|
+
lastY = 0;
|
|
289
|
+
hasMousePosition = !1;
|
|
290
|
+
modifierDown = !1;
|
|
291
|
+
onMouseMove = (e) => {
|
|
292
|
+
this.lastX = e.clientX, this.lastY = e.clientY, this.hasMousePosition = !0, this.updateState();
|
|
293
|
+
};
|
|
294
|
+
onKeyDown = (e) => {
|
|
295
|
+
et(e) && (this.modifierDown = !0, this.updateState());
|
|
296
|
+
};
|
|
297
|
+
onKeyUp = (e) => {
|
|
298
|
+
(e.key === "Control" || e.key === "Meta") && (this.modifierDown = e.ctrlKey || e.metaKey, this.updateState());
|
|
299
|
+
};
|
|
300
|
+
onBlur = () => {
|
|
301
|
+
this.modifierDown = !1, this.updateState();
|
|
302
|
+
};
|
|
303
|
+
constructor(e) {
|
|
304
|
+
this.view = e, window.addEventListener("mousemove", this.onMouseMove), window.addEventListener("keydown", this.onKeyDown), window.addEventListener("keyup", this.onKeyUp), window.addEventListener("blur", this.onBlur);
|
|
305
|
+
}
|
|
306
|
+
update(e) {
|
|
307
|
+
this.modifierDown && this.hasMousePosition && this.view.requestMeasure({ read: () => this.updateState() });
|
|
308
|
+
}
|
|
309
|
+
destroy() {
|
|
310
|
+
window.removeEventListener("mousemove", this.onMouseMove), window.removeEventListener("keydown", this.onKeyDown), window.removeEventListener("keyup", this.onKeyUp), window.removeEventListener("blur", this.onBlur);
|
|
311
|
+
}
|
|
312
|
+
updateState() {
|
|
313
|
+
let e = this.modifierDown && this.hasMousePosition && this.pointerIsOverLink();
|
|
314
|
+
this.view.contentDOM.classList.toggle($e, e);
|
|
315
|
+
}
|
|
316
|
+
pointerIsOverLink() {
|
|
317
|
+
let e = this.view.posAtCoords({
|
|
318
|
+
x: this.lastX,
|
|
319
|
+
y: this.lastY
|
|
320
|
+
});
|
|
321
|
+
return e !== null && Xe(this.view.state, e) !== null;
|
|
322
|
+
}
|
|
323
|
+
}, nt = n.fromClass(tt), rt = t.theme({
|
|
324
|
+
"&": {
|
|
325
|
+
fontFamily: Ie,
|
|
326
|
+
fontSize: "16px"
|
|
327
|
+
},
|
|
328
|
+
".cm-content": {
|
|
329
|
+
padding: "10px 12px",
|
|
330
|
+
lineHeight: "1.5"
|
|
331
|
+
},
|
|
332
|
+
".cm-scroller": { fontFamily: "inherit" },
|
|
333
|
+
[`.cm-content.${$e}`]: { cursor: "pointer" }
|
|
334
|
+
}), it = [
|
|
335
|
+
/^#{1,6} /,
|
|
336
|
+
/^> /,
|
|
337
|
+
/^- \[[ xX]\] /,
|
|
338
|
+
/^\d+\. /,
|
|
339
|
+
/^[-*] /
|
|
340
|
+
];
|
|
341
|
+
function _(e) {
|
|
342
|
+
let t = /^[ \t]*/.exec(e)[0], n = e.slice(t.length);
|
|
343
|
+
for (let e of it) {
|
|
344
|
+
let r = e.exec(n);
|
|
345
|
+
if (r) return {
|
|
346
|
+
indent: t,
|
|
347
|
+
prefix: r[0],
|
|
348
|
+
rest: n.slice(r[0].length)
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
function at(e, t) {
|
|
354
|
+
if (e.startsWith(" ")) return 1;
|
|
355
|
+
let n = 0;
|
|
356
|
+
for (; n < t && e[n] === " ";) n++;
|
|
357
|
+
return n;
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/utils/text.ts
|
|
361
|
+
function v(e, t) {
|
|
362
|
+
let n = e.state.changes(t);
|
|
363
|
+
e.dispatch({
|
|
364
|
+
changes: n,
|
|
365
|
+
selection: e.state.selection.map(n, 1)
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function y(e) {
|
|
369
|
+
let t = e.selection.main, n = e.doc.lineAt(t.from), r = e.doc.lineAt(t.to);
|
|
370
|
+
return {
|
|
371
|
+
from: n.from,
|
|
372
|
+
to: r.to,
|
|
373
|
+
firstLine: n.number,
|
|
374
|
+
lastLine: r.number
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function ot(e, t) {
|
|
378
|
+
let n = y(e.state), r = [];
|
|
379
|
+
for (let i = n.firstLine; i <= n.lastLine; i++) {
|
|
380
|
+
let n = t(e.state.doc.line(i));
|
|
381
|
+
n !== null && r.push(n);
|
|
382
|
+
}
|
|
383
|
+
return r.length !== 0 && (v(e, r), !0);
|
|
384
|
+
}
|
|
385
|
+
function st(e, t) {
|
|
386
|
+
let { state: n } = e, r = y(n), i = [], a = !0;
|
|
387
|
+
for (let e = r.firstLine; e <= r.lastLine; e++) if (!n.doc.line(e).text.startsWith(t)) {
|
|
388
|
+
a = !1;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
for (let e = r.firstLine; e <= r.lastLine; e++) {
|
|
392
|
+
let r = n.doc.line(e);
|
|
393
|
+
a ? i.push({
|
|
394
|
+
from: r.from,
|
|
395
|
+
to: r.from + t.length,
|
|
396
|
+
insert: ""
|
|
397
|
+
}) : r.text.startsWith(t) || i.push({
|
|
398
|
+
from: r.from,
|
|
399
|
+
to: r.from,
|
|
400
|
+
insert: t
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return i.length !== 0 && (v(e, i), !0);
|
|
404
|
+
}
|
|
405
|
+
function ct(e, t, n) {
|
|
406
|
+
let r = e.state.selection.main;
|
|
407
|
+
return e.dispatch({
|
|
408
|
+
changes: [{
|
|
409
|
+
from: r.from,
|
|
410
|
+
insert: t
|
|
411
|
+
}, {
|
|
412
|
+
from: r.to,
|
|
413
|
+
insert: n
|
|
414
|
+
}],
|
|
415
|
+
selection: r.empty ? { anchor: r.from + t.length } : {
|
|
416
|
+
anchor: r.from + t.length,
|
|
417
|
+
head: r.to + t.length
|
|
418
|
+
}
|
|
419
|
+
}), !0;
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/commands/queries.ts
|
|
423
|
+
function b(e, t) {
|
|
424
|
+
let n = e.selection.main, r = h(e).resolveInner(n.from, 1);
|
|
425
|
+
for (; r;) {
|
|
426
|
+
if (r.name === t && r.from <= n.from && r.to >= n.to) return r;
|
|
427
|
+
r = r.parent;
|
|
428
|
+
}
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
function x(e) {
|
|
432
|
+
let { firstLine: t } = y(e);
|
|
433
|
+
return e.doc.line(t).text;
|
|
434
|
+
}
|
|
435
|
+
function lt(e) {
|
|
436
|
+
return b(e, "StrongEmphasis") !== null;
|
|
437
|
+
}
|
|
438
|
+
function ut(e) {
|
|
439
|
+
return b(e, "Emphasis") !== null;
|
|
440
|
+
}
|
|
441
|
+
function dt(e) {
|
|
442
|
+
return b(e, "Strikethrough") !== null;
|
|
443
|
+
}
|
|
444
|
+
function ft(e) {
|
|
445
|
+
return b(e, "InlineCode") !== null;
|
|
446
|
+
}
|
|
447
|
+
function S(e) {
|
|
448
|
+
let t = /^(#{1,6}) /.exec(x(e));
|
|
449
|
+
return t ? t[0].length - 1 : 0;
|
|
450
|
+
}
|
|
451
|
+
function pt(e) {
|
|
452
|
+
return x(e).startsWith("> ");
|
|
453
|
+
}
|
|
454
|
+
function mt(e) {
|
|
455
|
+
let t = x(e);
|
|
456
|
+
return /^[-*] /.test(t) && !/^- \[[ xX]\] /.test(t);
|
|
457
|
+
}
|
|
458
|
+
function ht(e) {
|
|
459
|
+
return /^\d+\. /.test(x(e));
|
|
460
|
+
}
|
|
461
|
+
function gt(e) {
|
|
462
|
+
return /^- \[[ xX]\] /.test(x(e));
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/commands/block.ts
|
|
466
|
+
function _t(e, t) {
|
|
467
|
+
let n = y(e.state), r = [];
|
|
468
|
+
for (let i = n.firstLine; i <= n.lastLine; i++) {
|
|
469
|
+
let n = e.state.doc.line(i), a = /^(#{1,6}) /.exec(n.text), o = a ? a[0].length : 0, s = t === 0 ? "" : "#".repeat(t) + " ";
|
|
470
|
+
r.push({
|
|
471
|
+
from: n.from,
|
|
472
|
+
to: n.from + o,
|
|
473
|
+
insert: s
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
return r.some((e) => e.from !== e.to || e.insert !== "") ? (e.dispatch({ changes: r }), !0) : !1;
|
|
477
|
+
}
|
|
478
|
+
function C(e) {
|
|
479
|
+
return (t) => _t(t, S(t.state) === e ? 0 : e);
|
|
480
|
+
}
|
|
481
|
+
var vt = (e) => _t(e, Math.min(S(e.state) + 1, 6)), yt = (e) => _t(e, Math.max(S(e.state) - 1, 0)), bt = (e) => st(e, "> "), xt = (e) => {
|
|
482
|
+
let t = e.state.selection.main, n = "```\n", r = "\n```", i = e.state.sliceDoc(Math.max(0, t.from - 4), t.from), a = e.state.sliceDoc(t.to, Math.min(e.state.doc.length, t.to + 4));
|
|
483
|
+
return i === n && a === r ? (e.dispatch({ changes: [{
|
|
484
|
+
from: t.from - 4,
|
|
485
|
+
to: t.from,
|
|
486
|
+
insert: ""
|
|
487
|
+
}, {
|
|
488
|
+
from: t.to,
|
|
489
|
+
to: t.to + 4,
|
|
490
|
+
insert: ""
|
|
491
|
+
}] }), !0) : ct(e, n, r);
|
|
492
|
+
}, St = (e) => {
|
|
493
|
+
let t = e.state.doc.lineAt(e.state.selection.main.head);
|
|
494
|
+
return e.dispatch({ changes: {
|
|
495
|
+
from: t.to,
|
|
496
|
+
insert: "\n---\n"
|
|
497
|
+
} }), !0;
|
|
498
|
+
}, Ct = (e) => {
|
|
499
|
+
let t = y(e.state), n = [];
|
|
500
|
+
for (let r = t.firstLine; r <= t.lastLine; r++) {
|
|
501
|
+
let t = e.state.doc.line(r), i = _(t.text);
|
|
502
|
+
if (i) {
|
|
503
|
+
let e = t.from + i.indent.length;
|
|
504
|
+
n.push({
|
|
505
|
+
from: e,
|
|
506
|
+
to: e + i.prefix.length,
|
|
507
|
+
insert: ""
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return n.length !== 0 && (e.dispatch({ changes: n }), !0);
|
|
512
|
+
}, wt = /^[-*] $/;
|
|
513
|
+
function Tt(e) {
|
|
514
|
+
let t = _(e);
|
|
515
|
+
if (t === null) return {
|
|
516
|
+
indent: /^[ \t]*/.exec(e)[0],
|
|
517
|
+
bullet: null,
|
|
518
|
+
hasPrefix: !1
|
|
519
|
+
};
|
|
520
|
+
let n = wt.test(t.prefix);
|
|
521
|
+
return {
|
|
522
|
+
indent: t.indent,
|
|
523
|
+
bullet: n ? t.prefix : null,
|
|
524
|
+
hasPrefix: !0
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function Et(e, t) {
|
|
528
|
+
let n = y(e.state), r = [];
|
|
529
|
+
for (let t = n.firstLine; t <= n.lastLine; t++) {
|
|
530
|
+
let n = e.state.doc.line(t);
|
|
531
|
+
r.push({
|
|
532
|
+
from: n.from,
|
|
533
|
+
...Tt(n.text)
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
let i = r.every((e) => e.bullet === t), a = [];
|
|
537
|
+
for (let e of r) {
|
|
538
|
+
let { indent: n, bullet: r, hasPrefix: o } = e, s = e.from + n.length;
|
|
539
|
+
i ? a.push({
|
|
540
|
+
from: s,
|
|
541
|
+
to: s + t.length,
|
|
542
|
+
insert: ""
|
|
543
|
+
}) : r === null ? o || a.push({
|
|
544
|
+
from: s,
|
|
545
|
+
to: s,
|
|
546
|
+
insert: t
|
|
547
|
+
}) : a.push({
|
|
548
|
+
from: s,
|
|
549
|
+
to: s + r.length,
|
|
550
|
+
insert: t
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return a.length !== 0 && (v(e, a), !0);
|
|
554
|
+
}
|
|
555
|
+
var Dt = (e) => Et(e, "- "), Ot = (e) => Et(e, "* "), kt = (e) => st(e, "- [ ] "), At = (e) => {
|
|
556
|
+
let t = y(e.state), n = !0;
|
|
557
|
+
for (let r = t.firstLine; r <= t.lastLine; r++) if (!/^\d+\. /.test(e.state.doc.line(r).text)) {
|
|
558
|
+
n = !1;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
let r = [], i = 1;
|
|
562
|
+
for (let a = t.firstLine; a <= t.lastLine; a++) {
|
|
563
|
+
let t = e.state.doc.line(a);
|
|
564
|
+
if (n) {
|
|
565
|
+
let e = /^\d+\. /.exec(t.text), n = e ? e[0].length : 0;
|
|
566
|
+
r.push({
|
|
567
|
+
from: t.from,
|
|
568
|
+
to: t.from + n,
|
|
569
|
+
insert: ""
|
|
570
|
+
});
|
|
571
|
+
} else r.push({
|
|
572
|
+
from: t.from,
|
|
573
|
+
to: t.from,
|
|
574
|
+
insert: `${i}. `
|
|
575
|
+
}), i++;
|
|
576
|
+
}
|
|
577
|
+
return v(e, r), !0;
|
|
578
|
+
};
|
|
579
|
+
function jt(e) {
|
|
580
|
+
if (/^- \[[ xX]\] $/.test(e)) return "- [ ] ";
|
|
581
|
+
let t = /^(\d+)\. $/.exec(e);
|
|
582
|
+
return t ? `${Number(t[1]) + 1}. ` : e === "* " || e === "- " ? e : null;
|
|
583
|
+
}
|
|
584
|
+
function Mt(e) {
|
|
585
|
+
let t = e.state.selection.main, n = e.state.doc.lineAt(t.head), r = _(n.text);
|
|
586
|
+
if (r === null) return !1;
|
|
587
|
+
let i = jt(r.prefix);
|
|
588
|
+
if (i === null) return !1;
|
|
589
|
+
let a = n.from + r.indent.length + r.prefix.length;
|
|
590
|
+
if (t.from < a) return !1;
|
|
591
|
+
if (r.rest.length === 0) return e.dispatch({
|
|
592
|
+
changes: {
|
|
593
|
+
from: n.from,
|
|
594
|
+
to: n.to,
|
|
595
|
+
insert: ""
|
|
596
|
+
},
|
|
597
|
+
selection: { anchor: n.from }
|
|
598
|
+
}), !0;
|
|
599
|
+
let o = `\n${r.indent}${i}`;
|
|
600
|
+
return e.dispatch({
|
|
601
|
+
changes: {
|
|
602
|
+
from: t.head,
|
|
603
|
+
insert: o
|
|
604
|
+
},
|
|
605
|
+
selection: { anchor: t.head + o.length }
|
|
606
|
+
}), !0;
|
|
607
|
+
}
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/commands/indent.ts
|
|
610
|
+
var Nt = (e) => {
|
|
611
|
+
let { state: t } = e, n = " ".repeat(p(t)), r = t.facet(je), i = r !== null && r !== n ? Ne(t, t.doc.lineAt(t.selection.main.to).to) : null;
|
|
612
|
+
return ot(e, (e) => {
|
|
613
|
+
if (i === null || r === null || !Me(t, e, i)) return {
|
|
614
|
+
from: e.from,
|
|
615
|
+
to: e.from,
|
|
616
|
+
insert: n
|
|
617
|
+
};
|
|
618
|
+
let { at: a, missingSpace: o } = Pe(t, e, i);
|
|
619
|
+
return {
|
|
620
|
+
from: a,
|
|
621
|
+
to: a,
|
|
622
|
+
insert: (o ? " " : "") + r
|
|
623
|
+
};
|
|
624
|
+
}), !0;
|
|
625
|
+
}, Pt = (e) => {
|
|
626
|
+
let { state: t } = e, n = p(t), r = t.facet(je), i = r === null ? n : r === " " ? t.tabSize : r.length, a = i === n ? null : Ne(t, t.doc.lineAt(t.selection.main.to).to);
|
|
627
|
+
return ot(e, (e) => {
|
|
628
|
+
if (a === null || !Me(t, e, a)) {
|
|
629
|
+
let t = at(e.text, n);
|
|
630
|
+
return t > 0 ? {
|
|
631
|
+
from: e.from,
|
|
632
|
+
to: e.from + t,
|
|
633
|
+
insert: ""
|
|
634
|
+
} : null;
|
|
635
|
+
}
|
|
636
|
+
let { at: r } = Pe(t, e, a), o = at(t.doc.sliceString(r, e.to), i);
|
|
637
|
+
return o > 0 ? {
|
|
638
|
+
from: r,
|
|
639
|
+
to: r + o,
|
|
640
|
+
insert: ""
|
|
641
|
+
} : null;
|
|
642
|
+
}), !0;
|
|
643
|
+
};
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/commands/inline.ts
|
|
646
|
+
function Ft(e, t) {
|
|
647
|
+
return b(e.state, t.node);
|
|
648
|
+
}
|
|
649
|
+
function It(e, t, n) {
|
|
650
|
+
let r = [];
|
|
651
|
+
for (let e = t.firstChild; e; e = e.nextSibling) e.name === n && r.push({
|
|
652
|
+
from: e.from,
|
|
653
|
+
to: e.to
|
|
654
|
+
});
|
|
655
|
+
return r.length !== 0 && (e.dispatch({ changes: r.map((e) => ({
|
|
656
|
+
from: e.from,
|
|
657
|
+
to: e.to,
|
|
658
|
+
insert: ""
|
|
659
|
+
})) }), !0);
|
|
660
|
+
}
|
|
661
|
+
function w(e) {
|
|
662
|
+
return (t) => {
|
|
663
|
+
let n = Ft(t, e);
|
|
664
|
+
return n ? It(t, n, e.mark) : ct(t, e.before, e.after);
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
var Lt = w({
|
|
668
|
+
node: "StrongEmphasis",
|
|
669
|
+
mark: "EmphasisMark",
|
|
670
|
+
before: "**",
|
|
671
|
+
after: "**"
|
|
672
|
+
}), Rt = w({
|
|
673
|
+
node: "Emphasis",
|
|
674
|
+
mark: "EmphasisMark",
|
|
675
|
+
before: "*",
|
|
676
|
+
after: "*"
|
|
677
|
+
}), zt = w({
|
|
678
|
+
node: "Strikethrough",
|
|
679
|
+
mark: "StrikethroughMark",
|
|
680
|
+
before: "~~",
|
|
681
|
+
after: "~~"
|
|
682
|
+
}), Bt = w({
|
|
683
|
+
node: "InlineCode",
|
|
684
|
+
mark: "CodeMark",
|
|
685
|
+
before: "`",
|
|
686
|
+
after: "`"
|
|
687
|
+
}), T = {
|
|
688
|
+
code: "en",
|
|
689
|
+
texts: {
|
|
690
|
+
"toolbar.bold": "Bold",
|
|
691
|
+
"toolbar.italic": "Italic",
|
|
692
|
+
"toolbar.strikethrough": "Strikethrough",
|
|
693
|
+
"toolbar.code": "Inline code",
|
|
694
|
+
"toolbar.heading-smaller": "Smaller heading",
|
|
695
|
+
"toolbar.heading-bigger": "Bigger heading",
|
|
696
|
+
"toolbar.heading-1": "Heading 1",
|
|
697
|
+
"toolbar.heading-2": "Heading 2",
|
|
698
|
+
"toolbar.heading-3": "Heading 3",
|
|
699
|
+
"toolbar.heading-4": "Heading 4",
|
|
700
|
+
"toolbar.heading-5": "Heading 5",
|
|
701
|
+
"toolbar.heading-6": "Heading 6",
|
|
702
|
+
"toolbar.quote": "Blockquote",
|
|
703
|
+
"toolbar.code-block": "Code block",
|
|
704
|
+
"toolbar.horizontal-rule": "Horizontal rule",
|
|
705
|
+
"toolbar.clean-block": "Clear formatting",
|
|
706
|
+
"toolbar.unordered-list": "Bulleted list",
|
|
707
|
+
"toolbar.ordered-list": "Numbered list",
|
|
708
|
+
"toolbar.check-list": "Checklist",
|
|
709
|
+
"toolbar.link": "Link",
|
|
710
|
+
"toolbar.image": "Image",
|
|
711
|
+
"toolbar.table": "Table",
|
|
712
|
+
"toolbar.undo": "Undo",
|
|
713
|
+
"toolbar.redo": "Redo",
|
|
714
|
+
"toolbar.side-by-side": "Side-by-side preview",
|
|
715
|
+
"toolbar.fullscreen": "Fullscreen",
|
|
716
|
+
"toolbar.preview-fullscreen": "Fullscreen preview",
|
|
717
|
+
"toolbar.editor-mode": "Live preview",
|
|
718
|
+
"toolbar.upload-image": "Upload image",
|
|
719
|
+
"status.lines": {
|
|
720
|
+
one: "{count} line",
|
|
721
|
+
other: "{count} lines"
|
|
722
|
+
},
|
|
723
|
+
"status.words": {
|
|
724
|
+
one: "{count} word",
|
|
725
|
+
other: "{count} words"
|
|
726
|
+
},
|
|
727
|
+
"status.autosaved": "Saved: {time}",
|
|
728
|
+
"upload.placeholder": "![Uploading {name}…]()",
|
|
729
|
+
"upload.statusInit": "Drag an image here or paste it",
|
|
730
|
+
"upload.statusUploading": "Uploading {name}…",
|
|
731
|
+
"upload.statusDone": "{name} uploaded",
|
|
732
|
+
"upload.errorTooLarge": "{name} is too large (max. {maxSize}).",
|
|
733
|
+
"upload.errorType": "{name} is not a supported image format.",
|
|
734
|
+
"upload.errorFailed": "Upload of {name} failed.",
|
|
735
|
+
"prompt.linkUrl": "Link URL:",
|
|
736
|
+
"prompt.imageUrl": "Image URL:",
|
|
737
|
+
"table.column": "Column {n}"
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/util/text-format.ts
|
|
742
|
+
function Vt(e, t) {
|
|
743
|
+
return e.replace(/\{(\w+)\}/g, (e, n) => Object.prototype.hasOwnProperty.call(t, n) ? t[n] : e);
|
|
744
|
+
}
|
|
745
|
+
function Ht(e) {
|
|
746
|
+
return e >= 1048576 ? `${Math.round(e / 1048576)} MB` : e >= 1024 ? `${Math.round(e / 1024)} KB` : `${e} B`;
|
|
747
|
+
}
|
|
748
|
+
//#endregion
|
|
749
|
+
//#region src/i18n/translator.ts
|
|
750
|
+
var E = "en", Ut = {
|
|
751
|
+
hour: "2-digit",
|
|
752
|
+
minute: "2-digit"
|
|
753
|
+
};
|
|
754
|
+
function Wt(e, t) {
|
|
755
|
+
return typeof e == "string" ? typeof t == "string" : typeof t == "object" && !!t && typeof t.other == "string";
|
|
756
|
+
}
|
|
757
|
+
function Gt(e) {
|
|
758
|
+
let t = { ...T.texts };
|
|
759
|
+
for (let n of e) if (typeof n == "object" && n) for (let e of Object.keys(T.texts)) {
|
|
760
|
+
let r = n[e];
|
|
761
|
+
Wt(T.texts[e], r) && (t[e] = r);
|
|
762
|
+
}
|
|
763
|
+
return t;
|
|
764
|
+
}
|
|
765
|
+
function Kt(e) {
|
|
766
|
+
if (typeof e == "string") try {
|
|
767
|
+
return {
|
|
768
|
+
code: e,
|
|
769
|
+
rules: new Intl.PluralRules(e),
|
|
770
|
+
time: new Intl.DateTimeFormat(e, Ut)
|
|
771
|
+
};
|
|
772
|
+
} catch {}
|
|
773
|
+
return console.warn(`SupaMDE: invalid locale code "${String(e)}" — using "${E}" for plural rules and time format.`), {
|
|
774
|
+
code: E,
|
|
775
|
+
rules: new Intl.PluralRules(E),
|
|
776
|
+
time: new Intl.DateTimeFormat(E, Ut)
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function D(e, t) {
|
|
780
|
+
let n = Gt([e?.texts, t]), r = Kt(e == null ? E : e.code), i = n;
|
|
781
|
+
return {
|
|
782
|
+
code: r.code,
|
|
783
|
+
t(e, t = {}) {
|
|
784
|
+
let n = i[e];
|
|
785
|
+
return typeof n == "string" ? Vt(n, t) : e;
|
|
786
|
+
},
|
|
787
|
+
plural(e, t, i = {}) {
|
|
788
|
+
let a = n[e], o = a[r.rules.select(t)];
|
|
789
|
+
return Vt(typeof o == "string" ? o : a.other, {
|
|
790
|
+
...i,
|
|
791
|
+
count: String(t)
|
|
792
|
+
});
|
|
793
|
+
},
|
|
794
|
+
formatTime(e) {
|
|
795
|
+
return r.time.format(e);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region src/i18n/facet.ts
|
|
801
|
+
var qt = D(), O = s.define({ combine: (e) => e[0] ?? qt });
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/commands/link-image.ts
|
|
804
|
+
function Jt(e, t) {
|
|
805
|
+
return (n) => {
|
|
806
|
+
if (!e) return !1;
|
|
807
|
+
let r = n.state.selection.main, i = `[${t ?? n.state.sliceDoc(r.from, r.to)}](${e})`;
|
|
808
|
+
return n.dispatch({
|
|
809
|
+
changes: {
|
|
810
|
+
from: r.from,
|
|
811
|
+
to: r.to,
|
|
812
|
+
insert: i
|
|
813
|
+
},
|
|
814
|
+
selection: { anchor: r.from + i.length }
|
|
815
|
+
}), !0;
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function Yt(e, t) {
|
|
819
|
+
return (n) => {
|
|
820
|
+
if (!e) return !1;
|
|
821
|
+
let r = n.state.selection.main, i = ``;
|
|
822
|
+
return n.dispatch({
|
|
823
|
+
changes: {
|
|
824
|
+
from: r.from,
|
|
825
|
+
to: r.to,
|
|
826
|
+
insert: i
|
|
827
|
+
},
|
|
828
|
+
selection: { anchor: r.from + i.length }
|
|
829
|
+
}), !0;
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function Xt(e) {
|
|
833
|
+
let t = window.prompt(e.state.facet(O).t("prompt.linkUrl"), "https://");
|
|
834
|
+
return t ? Jt(t)(e) : !1;
|
|
835
|
+
}
|
|
836
|
+
function Zt(e) {
|
|
837
|
+
let t = window.prompt(e.state.facet(O).t("prompt.imageUrl"), "https://");
|
|
838
|
+
return t ? Yt(t)(e) : !1;
|
|
839
|
+
}
|
|
840
|
+
//#endregion
|
|
841
|
+
//#region src/commands/table.ts
|
|
842
|
+
var Qt = (e) => {
|
|
843
|
+
let t = e.state.facet(O), n = `| ${t.t("table.column", { n: "1" })} | ${t.t("table.column", { n: "2" })} |\n| --- | --- |\n| | |\n`, r = e.state.selection.main;
|
|
844
|
+
return e.dispatch({
|
|
845
|
+
changes: {
|
|
846
|
+
from: r.from,
|
|
847
|
+
to: r.to,
|
|
848
|
+
insert: n
|
|
849
|
+
},
|
|
850
|
+
selection: { anchor: r.from + n.length }
|
|
851
|
+
}), !0;
|
|
852
|
+
};
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region src/ui/actions.ts
|
|
855
|
+
function k(e) {
|
|
856
|
+
return (t) => S(t) === e;
|
|
857
|
+
}
|
|
858
|
+
var $t = {
|
|
859
|
+
bold: {
|
|
860
|
+
kind: "command",
|
|
861
|
+
command: Lt,
|
|
862
|
+
query: lt,
|
|
863
|
+
icon: "bold",
|
|
864
|
+
shortcut: "Mod-b"
|
|
865
|
+
},
|
|
866
|
+
italic: {
|
|
867
|
+
kind: "command",
|
|
868
|
+
command: Rt,
|
|
869
|
+
query: ut,
|
|
870
|
+
icon: "italic",
|
|
871
|
+
shortcut: "Mod-i"
|
|
872
|
+
},
|
|
873
|
+
strikethrough: {
|
|
874
|
+
kind: "command",
|
|
875
|
+
command: zt,
|
|
876
|
+
query: dt,
|
|
877
|
+
icon: "strikethrough"
|
|
878
|
+
},
|
|
879
|
+
code: {
|
|
880
|
+
kind: "command",
|
|
881
|
+
command: Bt,
|
|
882
|
+
query: ft,
|
|
883
|
+
icon: "code"
|
|
884
|
+
},
|
|
885
|
+
"heading-smaller": {
|
|
886
|
+
kind: "command",
|
|
887
|
+
command: vt,
|
|
888
|
+
icon: "heading",
|
|
889
|
+
shortcut: "Mod-h"
|
|
890
|
+
},
|
|
891
|
+
"heading-bigger": {
|
|
892
|
+
kind: "command",
|
|
893
|
+
command: yt,
|
|
894
|
+
icon: "heading",
|
|
895
|
+
shortcut: "Shift-Mod-h"
|
|
896
|
+
},
|
|
897
|
+
"heading-1": {
|
|
898
|
+
kind: "command",
|
|
899
|
+
command: C(1),
|
|
900
|
+
query: k(1),
|
|
901
|
+
icon: "heading",
|
|
902
|
+
shortcut: "Ctrl-Alt-1"
|
|
903
|
+
},
|
|
904
|
+
"heading-2": {
|
|
905
|
+
kind: "command",
|
|
906
|
+
command: C(2),
|
|
907
|
+
query: k(2),
|
|
908
|
+
icon: "heading",
|
|
909
|
+
shortcut: "Ctrl-Alt-2"
|
|
910
|
+
},
|
|
911
|
+
"heading-3": {
|
|
912
|
+
kind: "command",
|
|
913
|
+
command: C(3),
|
|
914
|
+
query: k(3),
|
|
915
|
+
icon: "heading",
|
|
916
|
+
shortcut: "Ctrl-Alt-3"
|
|
917
|
+
},
|
|
918
|
+
"heading-4": {
|
|
919
|
+
kind: "command",
|
|
920
|
+
command: C(4),
|
|
921
|
+
query: k(4),
|
|
922
|
+
icon: "heading",
|
|
923
|
+
shortcut: "Ctrl-Alt-4"
|
|
924
|
+
},
|
|
925
|
+
"heading-5": {
|
|
926
|
+
kind: "command",
|
|
927
|
+
command: C(5),
|
|
928
|
+
query: k(5),
|
|
929
|
+
icon: "heading",
|
|
930
|
+
shortcut: "Ctrl-Alt-5"
|
|
931
|
+
},
|
|
932
|
+
"heading-6": {
|
|
933
|
+
kind: "command",
|
|
934
|
+
command: C(6),
|
|
935
|
+
query: k(6),
|
|
936
|
+
icon: "heading",
|
|
937
|
+
shortcut: "Ctrl-Alt-6"
|
|
938
|
+
},
|
|
939
|
+
quote: {
|
|
940
|
+
kind: "command",
|
|
941
|
+
command: bt,
|
|
942
|
+
query: pt,
|
|
943
|
+
icon: "quote",
|
|
944
|
+
shortcut: "Mod-'"
|
|
945
|
+
},
|
|
946
|
+
"code-block": {
|
|
947
|
+
kind: "command",
|
|
948
|
+
command: xt,
|
|
949
|
+
icon: "code-block",
|
|
950
|
+
shortcut: "Mod-Alt-c"
|
|
951
|
+
},
|
|
952
|
+
"horizontal-rule": {
|
|
953
|
+
kind: "command",
|
|
954
|
+
command: St,
|
|
955
|
+
icon: "horizontal-rule"
|
|
956
|
+
},
|
|
957
|
+
"clean-block": {
|
|
958
|
+
kind: "command",
|
|
959
|
+
command: Ct,
|
|
960
|
+
icon: "clean-block",
|
|
961
|
+
shortcut: "Mod-e"
|
|
962
|
+
},
|
|
963
|
+
"unordered-list": {
|
|
964
|
+
kind: "command",
|
|
965
|
+
command: Dt,
|
|
966
|
+
query: mt,
|
|
967
|
+
icon: "unordered-list",
|
|
968
|
+
shortcut: "Mod-l"
|
|
969
|
+
},
|
|
970
|
+
"ordered-list": {
|
|
971
|
+
kind: "command",
|
|
972
|
+
command: At,
|
|
973
|
+
query: ht,
|
|
974
|
+
icon: "ordered-list",
|
|
975
|
+
shortcut: "Mod-Alt-l"
|
|
976
|
+
},
|
|
977
|
+
"check-list": {
|
|
978
|
+
kind: "command",
|
|
979
|
+
command: kt,
|
|
980
|
+
query: gt,
|
|
981
|
+
icon: "check-list",
|
|
982
|
+
shortcut: "Shift-Mod-l"
|
|
983
|
+
},
|
|
984
|
+
link: {
|
|
985
|
+
kind: "command",
|
|
986
|
+
command: Xt,
|
|
987
|
+
icon: "link",
|
|
988
|
+
shortcut: "Mod-k"
|
|
989
|
+
},
|
|
990
|
+
image: {
|
|
991
|
+
kind: "command",
|
|
992
|
+
command: Zt,
|
|
993
|
+
icon: "image",
|
|
994
|
+
shortcut: "Mod-Alt-i"
|
|
995
|
+
},
|
|
996
|
+
table: {
|
|
997
|
+
kind: "command",
|
|
998
|
+
command: Qt,
|
|
999
|
+
icon: "table"
|
|
1000
|
+
},
|
|
1001
|
+
undo: {
|
|
1002
|
+
kind: "command",
|
|
1003
|
+
command: ue,
|
|
1004
|
+
icon: "undo",
|
|
1005
|
+
shortcut: "Mod-z"
|
|
1006
|
+
},
|
|
1007
|
+
redo: {
|
|
1008
|
+
kind: "command",
|
|
1009
|
+
command: le,
|
|
1010
|
+
icon: "redo",
|
|
1011
|
+
shortcut: {
|
|
1012
|
+
default: "Mod-y",
|
|
1013
|
+
mac: "Mod-Shift-z"
|
|
1014
|
+
}
|
|
1015
|
+
},
|
|
1016
|
+
"side-by-side": {
|
|
1017
|
+
kind: "view",
|
|
1018
|
+
run: (e) => e.toggleSideBySide(),
|
|
1019
|
+
active: (e) => e.isSideBySideActive(),
|
|
1020
|
+
icon: "side-by-side",
|
|
1021
|
+
shortcut: "F9"
|
|
1022
|
+
},
|
|
1023
|
+
fullscreen: {
|
|
1024
|
+
kind: "view",
|
|
1025
|
+
run: (e) => e.toggleFullScreen(),
|
|
1026
|
+
active: (e) => e.isFullscreenActive(),
|
|
1027
|
+
icon: "fullscreen",
|
|
1028
|
+
shortcut: {
|
|
1029
|
+
default: "F11",
|
|
1030
|
+
mac: "Mod-Shift-F"
|
|
1031
|
+
}
|
|
1032
|
+
},
|
|
1033
|
+
"preview-fullscreen": {
|
|
1034
|
+
kind: "view",
|
|
1035
|
+
run: (e) => e.togglePreviewFullScreen(),
|
|
1036
|
+
active: (e) => e.isPreviewFullScreenActive(),
|
|
1037
|
+
icon: "preview-fullscreen",
|
|
1038
|
+
shortcut: "F8"
|
|
1039
|
+
},
|
|
1040
|
+
"editor-mode": {
|
|
1041
|
+
kind: "view",
|
|
1042
|
+
run: (e) => e.toggleEditorMode(),
|
|
1043
|
+
active: (e) => e.getEditorMode() === "live",
|
|
1044
|
+
icon: "editor-mode",
|
|
1045
|
+
shortcut: "F10"
|
|
1046
|
+
},
|
|
1047
|
+
"upload-image": {
|
|
1048
|
+
kind: "view",
|
|
1049
|
+
run: (e) => e.openBrowseFileWindow(),
|
|
1050
|
+
icon: "upload-image"
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
function en(e) {
|
|
1054
|
+
return $t[e];
|
|
1055
|
+
}
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region src/commands/keymap.ts
|
|
1058
|
+
var tn = /* @__PURE__ */ new Set(["undo", "redo"]);
|
|
1059
|
+
function nn(e) {
|
|
1060
|
+
return typeof e == "string" ? e : e.default;
|
|
1061
|
+
}
|
|
1062
|
+
var rn = Object.entries($t).filter((e) => e[1].kind === "command" && !!e[1].shortcut && !tn.has(e[0])).map(([, e]) => ({
|
|
1063
|
+
key: nn(e.shortcut),
|
|
1064
|
+
run: e.command,
|
|
1065
|
+
preventDefault: !0
|
|
1066
|
+
})), an = [
|
|
1067
|
+
{
|
|
1068
|
+
key: "Ctrl-Alt-q",
|
|
1069
|
+
run: bt,
|
|
1070
|
+
preventDefault: !0
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
key: "Shift-Alt-Mod-l",
|
|
1074
|
+
run: Ot,
|
|
1075
|
+
preventDefault: !0
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
key: "Enter",
|
|
1079
|
+
run: Mt
|
|
1080
|
+
},
|
|
1081
|
+
{
|
|
1082
|
+
key: "Backspace",
|
|
1083
|
+
run: de
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
key: "Tab",
|
|
1087
|
+
run: Nt,
|
|
1088
|
+
preventDefault: !0
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
key: "Shift-Tab",
|
|
1092
|
+
run: Pt,
|
|
1093
|
+
preventDefault: !0
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
key: "Shift-Mod-k",
|
|
1097
|
+
run: ie,
|
|
1098
|
+
preventDefault: !0
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
key: "Shift-Alt-ArrowDown",
|
|
1102
|
+
run: te,
|
|
1103
|
+
preventDefault: !0
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
key: "Shift-Alt-ArrowUp",
|
|
1107
|
+
run: ne,
|
|
1108
|
+
preventDefault: !0
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
key: "Alt-ArrowDown",
|
|
1112
|
+
run: se,
|
|
1113
|
+
preventDefault: !0
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
key: "Alt-ArrowUp",
|
|
1117
|
+
run: ce,
|
|
1118
|
+
preventDefault: !0
|
|
1119
|
+
}
|
|
1120
|
+
], on = [...rn, ...an];
|
|
1121
|
+
//#endregion
|
|
1122
|
+
//#region src/ui/update-listener.ts
|
|
1123
|
+
function sn(e) {
|
|
1124
|
+
return t.updateListener.of((t) => {
|
|
1125
|
+
(t.docChanged || t.selectionSet) && e.onUpdate({
|
|
1126
|
+
state: t.state,
|
|
1127
|
+
docChanged: t.docChanged,
|
|
1128
|
+
selectionSet: t.selectionSet
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region src/editor/extensions.ts
|
|
1134
|
+
function cn(e, n, a) {
|
|
1135
|
+
let s = [
|
|
1136
|
+
fe({
|
|
1137
|
+
extensions: [pe, He],
|
|
1138
|
+
addKeymap: !1
|
|
1139
|
+
}),
|
|
1140
|
+
Re,
|
|
1141
|
+
Ee.of(De(e.editorMode)),
|
|
1142
|
+
Qe,
|
|
1143
|
+
nt,
|
|
1144
|
+
ae(),
|
|
1145
|
+
r.of([
|
|
1146
|
+
...e.extraKeys,
|
|
1147
|
+
...on,
|
|
1148
|
+
...oe,
|
|
1149
|
+
...re
|
|
1150
|
+
]),
|
|
1151
|
+
rt,
|
|
1152
|
+
o.tabSize.of(e.tabSize),
|
|
1153
|
+
m.of(" ".repeat(e.indentUnit)),
|
|
1154
|
+
je.of(e.codeIndentUnit === "tab" ? " " : " ".repeat(e.codeIndentUnit))
|
|
1155
|
+
];
|
|
1156
|
+
return e.lineWrapping && s.push(t.lineWrapping), e.placeholder !== null && s.push(i(e.placeholder)), n && s.push(sn(n)), a && s.push(...a), s;
|
|
1157
|
+
}
|
|
1158
|
+
//#endregion
|
|
1159
|
+
//#region src/editor/setup.ts
|
|
1160
|
+
function ln(e, n, r) {
|
|
1161
|
+
let i = e.element;
|
|
1162
|
+
if (!i) throw Error("SupaMDE: `element` is required (a <textarea>).");
|
|
1163
|
+
if (!(i instanceof HTMLTextAreaElement)) throw Error("SupaMDE: `element` must be a <textarea>.");
|
|
1164
|
+
let a = i, o = Ae(e), s = e.initialValue ?? a.value, c = new t({
|
|
1165
|
+
doc: s,
|
|
1166
|
+
extensions: cn(o, n, r)
|
|
1167
|
+
});
|
|
1168
|
+
a.parentNode?.insertBefore(c.dom, a);
|
|
1169
|
+
let l = a.style.display;
|
|
1170
|
+
a.style.display = "none";
|
|
1171
|
+
let u = () => {
|
|
1172
|
+
a.value = c.state.doc.toString();
|
|
1173
|
+
}, d = () => u(), f = a.form;
|
|
1174
|
+
return f?.addEventListener("submit", d), o.autofocus && c.focus(), {
|
|
1175
|
+
view: c,
|
|
1176
|
+
toTextArea: () => (u(), f?.removeEventListener("submit", d), c.destroy(), c.dom.remove(), a.style.display = l, a),
|
|
1177
|
+
forceSync: u,
|
|
1178
|
+
resolved: o
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
//#endregion
|
|
1182
|
+
//#region src/editor/value.ts
|
|
1183
|
+
function un(e) {
|
|
1184
|
+
return e.state.doc.toString();
|
|
1185
|
+
}
|
|
1186
|
+
function dn(e, t) {
|
|
1187
|
+
e.dispatch({ changes: {
|
|
1188
|
+
from: 0,
|
|
1189
|
+
to: e.state.doc.length,
|
|
1190
|
+
insert: t
|
|
1191
|
+
} });
|
|
1192
|
+
}
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/ui/toolbar-config.ts
|
|
1195
|
+
var fn = /* @__PURE__ */ "bold.italic.strikethrough.code.|.heading-smaller.heading-bigger.|.quote.unordered-list.ordered-list.check-list.|.code-block.horizontal-rule.|.link.image.table.|.clean-block.|.undo.redo.|.preview-fullscreen".split(".");
|
|
1196
|
+
function pn(e) {
|
|
1197
|
+
if (e === !1) return null;
|
|
1198
|
+
let t = e ?? fn, n = [];
|
|
1199
|
+
for (let e of t) if (typeof e == "string") {
|
|
1200
|
+
if (e === "|") {
|
|
1201
|
+
n.push({ kind: "separator" });
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
let t = en(e);
|
|
1205
|
+
if (!t) {
|
|
1206
|
+
console.warn(`SupaMDE: unknown toolbar action "${e}" is skipped.`);
|
|
1207
|
+
continue;
|
|
1208
|
+
}
|
|
1209
|
+
n.push({
|
|
1210
|
+
kind: "builtin",
|
|
1211
|
+
name: e,
|
|
1212
|
+
action: t
|
|
1213
|
+
});
|
|
1214
|
+
} else n.push({
|
|
1215
|
+
kind: "custom",
|
|
1216
|
+
button: e
|
|
1217
|
+
});
|
|
1218
|
+
return n;
|
|
1219
|
+
}
|
|
1220
|
+
//#endregion
|
|
1221
|
+
//#region node_modules/lucide/dist/esm/defaultAttributes.mjs
|
|
1222
|
+
var mn = {
|
|
1223
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1224
|
+
width: 24,
|
|
1225
|
+
height: 24,
|
|
1226
|
+
viewBox: "0 0 24 24",
|
|
1227
|
+
fill: "none",
|
|
1228
|
+
stroke: "currentColor",
|
|
1229
|
+
"stroke-width": 2,
|
|
1230
|
+
"stroke-linecap": "round",
|
|
1231
|
+
"stroke-linejoin": "round"
|
|
1232
|
+
}, hn = ([e, t, n]) => {
|
|
1233
|
+
let r = document.createElementNS("http://www.w3.org/2000/svg", e);
|
|
1234
|
+
return Object.keys(t).forEach((e) => {
|
|
1235
|
+
r.setAttribute(e, String(t[e]));
|
|
1236
|
+
}), n?.length && n.forEach((e) => {
|
|
1237
|
+
let t = hn(e);
|
|
1238
|
+
r.appendChild(t);
|
|
1239
|
+
}), r;
|
|
1240
|
+
}, gn = (e, t = {}) => hn([
|
|
1241
|
+
"svg",
|
|
1242
|
+
{
|
|
1243
|
+
...mn,
|
|
1244
|
+
...t
|
|
1245
|
+
},
|
|
1246
|
+
e
|
|
1247
|
+
]), _n = {
|
|
1248
|
+
bold: [["path", { d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" }]],
|
|
1249
|
+
italic: [
|
|
1250
|
+
["line", {
|
|
1251
|
+
x1: "19",
|
|
1252
|
+
x2: "10",
|
|
1253
|
+
y1: "4",
|
|
1254
|
+
y2: "4"
|
|
1255
|
+
}],
|
|
1256
|
+
["line", {
|
|
1257
|
+
x1: "14",
|
|
1258
|
+
x2: "5",
|
|
1259
|
+
y1: "20",
|
|
1260
|
+
y2: "20"
|
|
1261
|
+
}],
|
|
1262
|
+
["line", {
|
|
1263
|
+
x1: "15",
|
|
1264
|
+
x2: "9",
|
|
1265
|
+
y1: "4",
|
|
1266
|
+
y2: "20"
|
|
1267
|
+
}]
|
|
1268
|
+
],
|
|
1269
|
+
strikethrough: [
|
|
1270
|
+
["path", { d: "M16 4H9a3 3 0 0 0-2.83 4" }],
|
|
1271
|
+
["path", { d: "M14 12a4 4 0 0 1 0 8H6" }],
|
|
1272
|
+
["line", {
|
|
1273
|
+
x1: "4",
|
|
1274
|
+
x2: "20",
|
|
1275
|
+
y1: "12",
|
|
1276
|
+
y2: "12"
|
|
1277
|
+
}]
|
|
1278
|
+
],
|
|
1279
|
+
code: [["path", { d: "m16 18 6-6-6-6" }], ["path", { d: "m8 6-6 6 6 6" }]],
|
|
1280
|
+
heading: [
|
|
1281
|
+
["path", { d: "M6 12h12" }],
|
|
1282
|
+
["path", { d: "M6 20V4" }],
|
|
1283
|
+
["path", { d: "M18 20V4" }]
|
|
1284
|
+
],
|
|
1285
|
+
quote: [["path", { d: "M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }], ["path", { d: "M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }]],
|
|
1286
|
+
"code-block": [
|
|
1287
|
+
["path", { d: "m10 9-3 3 3 3" }],
|
|
1288
|
+
["path", { d: "m14 15 3-3-3-3" }],
|
|
1289
|
+
["rect", {
|
|
1290
|
+
x: "3",
|
|
1291
|
+
y: "3",
|
|
1292
|
+
width: "18",
|
|
1293
|
+
height: "18",
|
|
1294
|
+
rx: "2"
|
|
1295
|
+
}]
|
|
1296
|
+
],
|
|
1297
|
+
"horizontal-rule": [["path", { d: "M5 12h14" }]],
|
|
1298
|
+
"clean-block": [["path", { d: "M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21" }], ["path", { d: "m5.082 11.09 8.828 8.828" }]],
|
|
1299
|
+
"unordered-list": [
|
|
1300
|
+
["path", { d: "M3 5h.01" }],
|
|
1301
|
+
["path", { d: "M3 12h.01" }],
|
|
1302
|
+
["path", { d: "M3 19h.01" }],
|
|
1303
|
+
["path", { d: "M8 5h13" }],
|
|
1304
|
+
["path", { d: "M8 12h13" }],
|
|
1305
|
+
["path", { d: "M8 19h13" }]
|
|
1306
|
+
],
|
|
1307
|
+
"ordered-list": [
|
|
1308
|
+
["path", { d: "M11 5h10" }],
|
|
1309
|
+
["path", { d: "M11 12h10" }],
|
|
1310
|
+
["path", { d: "M11 19h10" }],
|
|
1311
|
+
["path", { d: "M4 4h1v5" }],
|
|
1312
|
+
["path", { d: "M4 9h2" }],
|
|
1313
|
+
["path", { d: "M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02" }]
|
|
1314
|
+
],
|
|
1315
|
+
"check-list": [
|
|
1316
|
+
["path", { d: "M13 5h8" }],
|
|
1317
|
+
["path", { d: "M13 12h8" }],
|
|
1318
|
+
["path", { d: "M13 19h8" }],
|
|
1319
|
+
["path", { d: "m3 17 2 2 4-4" }],
|
|
1320
|
+
["path", { d: "m3 7 2 2 4-4" }]
|
|
1321
|
+
],
|
|
1322
|
+
link: [["path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" }], ["path", { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" }]],
|
|
1323
|
+
image: [
|
|
1324
|
+
["rect", {
|
|
1325
|
+
width: "18",
|
|
1326
|
+
height: "18",
|
|
1327
|
+
x: "3",
|
|
1328
|
+
y: "3",
|
|
1329
|
+
rx: "2",
|
|
1330
|
+
ry: "2"
|
|
1331
|
+
}],
|
|
1332
|
+
["circle", {
|
|
1333
|
+
cx: "9",
|
|
1334
|
+
cy: "9",
|
|
1335
|
+
r: "2"
|
|
1336
|
+
}],
|
|
1337
|
+
["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" }]
|
|
1338
|
+
],
|
|
1339
|
+
table: [
|
|
1340
|
+
["path", { d: "M12 3v18" }],
|
|
1341
|
+
["rect", {
|
|
1342
|
+
width: "18",
|
|
1343
|
+
height: "18",
|
|
1344
|
+
x: "3",
|
|
1345
|
+
y: "3",
|
|
1346
|
+
rx: "2"
|
|
1347
|
+
}],
|
|
1348
|
+
["path", { d: "M3 9h18" }],
|
|
1349
|
+
["path", { d: "M3 15h18" }]
|
|
1350
|
+
],
|
|
1351
|
+
undo: [["path", { d: "M3 7v6h6" }], ["path", { d: "M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" }]],
|
|
1352
|
+
redo: [["path", { d: "M21 7v6h-6" }], ["path", { d: "M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" }]],
|
|
1353
|
+
"side-by-side": [["rect", {
|
|
1354
|
+
width: "18",
|
|
1355
|
+
height: "18",
|
|
1356
|
+
x: "3",
|
|
1357
|
+
y: "3",
|
|
1358
|
+
rx: "2"
|
|
1359
|
+
}], ["path", { d: "M12 3v18" }]],
|
|
1360
|
+
fullscreen: [
|
|
1361
|
+
["path", { d: "M3 7V5a2 2 0 0 1 2-2h2" }],
|
|
1362
|
+
["path", { d: "M17 3h2a2 2 0 0 1 2 2v2" }],
|
|
1363
|
+
["path", { d: "M21 17v2a2 2 0 0 1-2 2h-2" }],
|
|
1364
|
+
["path", { d: "M7 21H5a2 2 0 0 1-2-2v-2" }],
|
|
1365
|
+
["rect", {
|
|
1366
|
+
width: "10",
|
|
1367
|
+
height: "8",
|
|
1368
|
+
x: "7",
|
|
1369
|
+
y: "8",
|
|
1370
|
+
rx: "1"
|
|
1371
|
+
}]
|
|
1372
|
+
],
|
|
1373
|
+
"preview-fullscreen": [
|
|
1374
|
+
["path", { d: "M15 3h6v6" }],
|
|
1375
|
+
["path", { d: "m21 3-7 7" }],
|
|
1376
|
+
["path", { d: "m3 21 7-7" }],
|
|
1377
|
+
["path", { d: "M9 21H3v-6" }]
|
|
1378
|
+
],
|
|
1379
|
+
"editor-mode": [["path", { d: "M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0" }], ["circle", {
|
|
1380
|
+
cx: "12",
|
|
1381
|
+
cy: "12",
|
|
1382
|
+
r: "3"
|
|
1383
|
+
}]],
|
|
1384
|
+
"upload-image": [
|
|
1385
|
+
["path", { d: "M10.3 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10l-3.1-3.1a2 2 0 0 0-2.814.014L6 21" }],
|
|
1386
|
+
["path", { d: "m14 19.5 3-3 3 3" }],
|
|
1387
|
+
["path", { d: "M17 22v-5.5" }],
|
|
1388
|
+
["circle", {
|
|
1389
|
+
cx: "9",
|
|
1390
|
+
cy: "9",
|
|
1391
|
+
r: "2"
|
|
1392
|
+
}]
|
|
1393
|
+
]
|
|
1394
|
+
};
|
|
1395
|
+
function vn(e) {
|
|
1396
|
+
let t = _n[e];
|
|
1397
|
+
if (!t) throw Error(`SupaMDE: unknown icon "${e}".`);
|
|
1398
|
+
return gn(t);
|
|
1399
|
+
}
|
|
1400
|
+
//#endregion
|
|
1401
|
+
//#region src/ui/shortcut-label.ts
|
|
1402
|
+
function yn() {
|
|
1403
|
+
try {
|
|
1404
|
+
let e = navigator;
|
|
1405
|
+
if (typeof navigator < "u" && e.userAgentData?.platform) return e.userAgentData.platform.toLowerCase().includes("mac");
|
|
1406
|
+
if (typeof navigator < "u" && navigator.userAgent) return /mac/i.test(navigator.userAgent);
|
|
1407
|
+
} catch {}
|
|
1408
|
+
return !1;
|
|
1409
|
+
}
|
|
1410
|
+
function bn(e, t) {
|
|
1411
|
+
let n = t ?? yn(), r = typeof e == "string" ? e : n ? e.mac : e.default, i = r.split("-");
|
|
1412
|
+
if (i.length === 0) return r;
|
|
1413
|
+
let a = i[i.length - 1];
|
|
1414
|
+
if (!a) return r;
|
|
1415
|
+
let o = a, s = i.slice(0, -1);
|
|
1416
|
+
return n ? xn(s, o) : Sn(s, o);
|
|
1417
|
+
}
|
|
1418
|
+
function xn(e, t) {
|
|
1419
|
+
let n = [], r = !1, i = !1, a = !1, o = !1, s = !1;
|
|
1420
|
+
for (let t of e) t === "Mod" ? r = !0 : t === "Cmd" ? i = !0 : t === "Ctrl" ? a = !0 : t === "Alt" ? o = !0 : t === "Shift" && (s = !0);
|
|
1421
|
+
r && n.push("⌘"), i && n.push("⌘"), a && n.push("⌃"), o && n.push("⌥"), s && n.push("⇧");
|
|
1422
|
+
let c = t.length === 1 ? t.toUpperCase() : t;
|
|
1423
|
+
return n.join("") + c;
|
|
1424
|
+
}
|
|
1425
|
+
function Sn(e, t) {
|
|
1426
|
+
let n = [], r = !1, i = !1, a = !1;
|
|
1427
|
+
for (let t of e) t === "Mod" || t === "Ctrl" ? r = !0 : t === "Alt" ? i = !0 : t === "Shift" && (a = !0);
|
|
1428
|
+
r && n.push("Ctrl"), i && n.push("Alt"), a && n.push("Shift");
|
|
1429
|
+
let o = t.length === 1 ? t.toUpperCase() : t;
|
|
1430
|
+
return n.push(o), n.join("+");
|
|
1431
|
+
}
|
|
1432
|
+
//#endregion
|
|
1433
|
+
//#region src/ui/toolbar.ts
|
|
1434
|
+
function Cn(e) {
|
|
1435
|
+
return typeof e == "object" && !!e && typeof e.toggleSideBySide == "function" && typeof e.toggleFullScreen == "function" && typeof e.isSideBySideActive == "function" && typeof e.isFullscreenActive == "function";
|
|
1436
|
+
}
|
|
1437
|
+
function wn(e, t, n, r, i, a) {
|
|
1438
|
+
if (t.kind === "separator") {
|
|
1439
|
+
let e = document.createElement("i");
|
|
1440
|
+
return e.className = "supamde-separator", e;
|
|
1441
|
+
}
|
|
1442
|
+
let o = document.createElement("button");
|
|
1443
|
+
if (o.type = "button", t.kind === "builtin") {
|
|
1444
|
+
let { action: s, name: c } = t, l = r.t(`toolbar.${c}`), u = s.shortcut ? `${l} (${bn(s.shortcut)})` : l;
|
|
1445
|
+
if (o.title = u, o.setAttribute("aria-label", u), o.dataset.action = c, o.appendChild(vn(s.icon)), s.kind === "command") {
|
|
1446
|
+
let t = s.command;
|
|
1447
|
+
o.addEventListener("click", () => {
|
|
1448
|
+
e.focus(), t(e);
|
|
1449
|
+
}), s.query && i.push({
|
|
1450
|
+
el: o,
|
|
1451
|
+
query: (e) => s.query(e)
|
|
1452
|
+
});
|
|
1453
|
+
} else {
|
|
1454
|
+
let e = s.run;
|
|
1455
|
+
o.addEventListener("click", () => e(n)), s.active && a.push({
|
|
1456
|
+
el: o,
|
|
1457
|
+
active: s.active
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
} else {
|
|
1461
|
+
let { button: e } = t;
|
|
1462
|
+
if (o.title = e.title ?? e.name, o.dataset.action = e.name, e.className) {
|
|
1463
|
+
let t = document.createElement("i");
|
|
1464
|
+
t.className = e.className, o.appendChild(t);
|
|
1465
|
+
} else o.textContent = e.name;
|
|
1466
|
+
o.addEventListener("click", () => e.action(n));
|
|
1467
|
+
}
|
|
1468
|
+
return o;
|
|
1469
|
+
}
|
|
1470
|
+
function Tn(e, t, n, r = D()) {
|
|
1471
|
+
let i = pn(t);
|
|
1472
|
+
if (i === null) return null;
|
|
1473
|
+
let a = document.createElement("div");
|
|
1474
|
+
a.className = "supamde-toolbar";
|
|
1475
|
+
let o = [], s = [];
|
|
1476
|
+
for (let t of i) a.appendChild(wn(e, t, n, r, o, s));
|
|
1477
|
+
let c = !1;
|
|
1478
|
+
return {
|
|
1479
|
+
dom: a,
|
|
1480
|
+
update: (e) => {
|
|
1481
|
+
for (let { el: t, query: n } of o) t.classList.toggle("active", n(e));
|
|
1482
|
+
if (s.length > 0) {
|
|
1483
|
+
if (Cn(n)) for (let { el: e, active: t } of s) e.classList.toggle("active", t(n));
|
|
1484
|
+
else c || (c = !0, console.warn("SupaMDE: toolbar contains view buttons (preview-fullscreen/side-by-side/fullscreen/editor-mode), but the given editor instance does not satisfy SupaLike (toggleSideBySide/toggleFullScreen/isSideBySideActive/isFullscreenActive) — the active state of these buttons is not updated."));
|
|
1485
|
+
}
|
|
1486
|
+
},
|
|
1487
|
+
destroy: () => {
|
|
1488
|
+
a.remove();
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
//#endregion
|
|
1493
|
+
//#region src/features/word-count.ts
|
|
1494
|
+
function En(e) {
|
|
1495
|
+
let t = e.trim();
|
|
1496
|
+
return t.length === 0 ? 0 : t.split(/\s+/).length;
|
|
1497
|
+
}
|
|
1498
|
+
//#endregion
|
|
1499
|
+
//#region src/ui/statusbar.ts
|
|
1500
|
+
var Dn = [
|
|
1501
|
+
"lines",
|
|
1502
|
+
"words",
|
|
1503
|
+
"cursor"
|
|
1504
|
+
], On = /* @__PURE__ */ new Set([
|
|
1505
|
+
"lines",
|
|
1506
|
+
"words",
|
|
1507
|
+
"cursor",
|
|
1508
|
+
"autosave",
|
|
1509
|
+
"upload-image"
|
|
1510
|
+
]), kn = /* @__PURE__ */ new Set(["autosave", "upload-image"]);
|
|
1511
|
+
function An(e, t, n) {
|
|
1512
|
+
switch (e) {
|
|
1513
|
+
case "lines": return n.plural("status.lines", t.doc.lines);
|
|
1514
|
+
case "words": return n.plural("status.words", En(t.doc.toString()));
|
|
1515
|
+
case "cursor": {
|
|
1516
|
+
let e = t.selection.main.head, n = t.doc.lineAt(e);
|
|
1517
|
+
return `${n.number}:${e - n.from + 1}`;
|
|
1518
|
+
}
|
|
1519
|
+
case "autosave":
|
|
1520
|
+
case "upload-image": return "";
|
|
1521
|
+
default: return "";
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
function jn(e, t = D()) {
|
|
1525
|
+
if (e === !1) return null;
|
|
1526
|
+
let n = e ?? Dn, r = document.createElement("div");
|
|
1527
|
+
r.className = "supamde-statusbar";
|
|
1528
|
+
let i = [], a = [];
|
|
1529
|
+
for (let e of n) {
|
|
1530
|
+
let t = document.createElement("span");
|
|
1531
|
+
typeof e == "string" ? (t.className = `supamde-status-${e}`, r.appendChild(t), On.has(e) && i.push({
|
|
1532
|
+
name: e,
|
|
1533
|
+
el: t
|
|
1534
|
+
})) : (t.className = `supamde-status-custom ${e.className}`, t.textContent = e.defaultValue ?? "", r.appendChild(t), a.push({
|
|
1535
|
+
item: e,
|
|
1536
|
+
el: t
|
|
1537
|
+
}));
|
|
1538
|
+
}
|
|
1539
|
+
return {
|
|
1540
|
+
dom: r,
|
|
1541
|
+
update: (e, n) => {
|
|
1542
|
+
for (let { name: n, el: r } of i) kn.has(n) || (r.textContent = An(n, e, t));
|
|
1543
|
+
for (let { item: e, el: t } of a) n.docChanged && e.onUpdate?.(t), n.selectionSet && e.onActivity?.(t);
|
|
1544
|
+
},
|
|
1545
|
+
setItem: (e, t) => {
|
|
1546
|
+
let n = i.find((t) => t.name === e);
|
|
1547
|
+
n && (n.el.textContent = t);
|
|
1548
|
+
},
|
|
1549
|
+
destroy: () => {
|
|
1550
|
+
r.remove();
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
//#endregion
|
|
1555
|
+
//#region src/ui/preview.ts
|
|
1556
|
+
function Mn(e, t) {
|
|
1557
|
+
let n = document.createElement("div");
|
|
1558
|
+
if (n.className = "supamde-preview-side", t.previewClass) {
|
|
1559
|
+
let e = Array.isArray(t.previewClass) ? t.previewClass : [t.previewClass];
|
|
1560
|
+
n.classList.add(...e);
|
|
1561
|
+
}
|
|
1562
|
+
n.style.display = "none";
|
|
1563
|
+
let r = !1, i = t.syncScroll ?? !0, a = (e) => {
|
|
1564
|
+
n.innerHTML = t.render(e.doc.toString());
|
|
1565
|
+
}, o = null, s = e.scrollDOM, c = (e) => {
|
|
1566
|
+
let t = () => {
|
|
1567
|
+
o === e && (o = null);
|
|
1568
|
+
};
|
|
1569
|
+
typeof requestAnimationFrame == "function" ? requestAnimationFrame(t) : t();
|
|
1570
|
+
}, l = () => {
|
|
1571
|
+
if (!r || !i) return;
|
|
1572
|
+
if (o === "preview") {
|
|
1573
|
+
o = null;
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
o = "editor";
|
|
1577
|
+
let e = s.scrollHeight - s.clientHeight, t = e > 0 ? s.scrollTop / e : 0;
|
|
1578
|
+
n.scrollTop = (n.scrollHeight - n.clientHeight) * t, c("editor");
|
|
1579
|
+
}, u = () => {
|
|
1580
|
+
if (!r || !i) return;
|
|
1581
|
+
if (o === "editor") {
|
|
1582
|
+
o = null;
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
o = "preview";
|
|
1586
|
+
let e = n.scrollHeight - n.clientHeight, t = e > 0 ? n.scrollTop / e : 0;
|
|
1587
|
+
s.scrollTop = (s.scrollHeight - s.clientHeight) * t, c("preview");
|
|
1588
|
+
};
|
|
1589
|
+
i && (s.addEventListener("scroll", l), n.addEventListener("scroll", u));
|
|
1590
|
+
let d = (t) => {
|
|
1591
|
+
t !== r && (r = t, n.style.display = r ? "" : "none", r && a(e.state));
|
|
1592
|
+
};
|
|
1593
|
+
return {
|
|
1594
|
+
dom: n,
|
|
1595
|
+
toggle: () => d(!r),
|
|
1596
|
+
set: d,
|
|
1597
|
+
isActive: () => r,
|
|
1598
|
+
update: (e) => {
|
|
1599
|
+
r && a(e);
|
|
1600
|
+
},
|
|
1601
|
+
destroy: () => {
|
|
1602
|
+
i && (s.removeEventListener("scroll", l), n.removeEventListener("scroll", u)), n.remove();
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
//#endregion
|
|
1607
|
+
//#region src/ui/fullscreen.ts
|
|
1608
|
+
var A = 0, Nn = "";
|
|
1609
|
+
function Pn(e, t = {}) {
|
|
1610
|
+
let n = !1, r = (r) => {
|
|
1611
|
+
r !== n && (n = r, e.classList.toggle("supamde-fullscreen", n), n ? (A === 0 && (Nn = document.body.style.overflow), A += 1, document.body.style.overflow = "hidden") : (A = Math.max(0, A - 1), A === 0 && (document.body.style.overflow = Nn)), t.onToggleFullScreen?.(n));
|
|
1612
|
+
}, i = (e) => {
|
|
1613
|
+
e.key === "Escape" && n && r(!1);
|
|
1614
|
+
};
|
|
1615
|
+
return e.addEventListener("keydown", i), {
|
|
1616
|
+
toggle: () => r(!n),
|
|
1617
|
+
set: r,
|
|
1618
|
+
isActive: () => n,
|
|
1619
|
+
destroy: () => {
|
|
1620
|
+
e.removeEventListener("keydown", i), n && r(!1);
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
//#endregion
|
|
1625
|
+
//#region src/ui/toolbar.css?inline
|
|
1626
|
+
var Fn = ".supamde-container{--supamde-border-color:#d0d0d0;--supamde-border-width:1px;--supamde-border-top-width:var(--supamde-border-width);--supamde-border-right-width:var(--supamde-border-width);--supamde-border-bottom-width:var(--supamde-border-width);--supamde-border-left-width:var(--supamde-border-width);--supamde-radius:4px;--supamde-divider-toolbar-width:1px;--supamde-divider-statusbar-width:1px;--supamde-divider-preview-width:1px;--supamde-toolbar-bg:#f7f7f7;--supamde-btn-hover:#e6e6e6;--supamde-btn-active:#d8e6ff;--supamde-btn-text:#333;border-style:solid;border-color:var(--supamde-border-color);border-top-width:var(--supamde-border-top-width);border-right-width:var(--supamde-border-right-width);border-bottom-width:var(--supamde-border-bottom-width);border-left-width:var(--supamde-border-left-width);border-radius:var(--supamde-radius);overflow:hidden}.supamde-toolbar{border-bottom:var(--supamde-divider-toolbar-width) solid var(--supamde-border-color);background:var(--supamde-toolbar-bg);flex-wrap:wrap;align-items:center;gap:2px;padding:4px;display:flex}.supamde-toolbar button{width:28px;height:28px;color:var(--supamde-btn-text);cursor:pointer;background:0 0;border:1px solid #0000;border-radius:3px;justify-content:center;align-items:center;padding:0;display:inline-flex}.supamde-toolbar button:hover{background:var(--supamde-btn-hover)}.supamde-toolbar button.active{background:var(--supamde-btn-active)}.supamde-toolbar button svg{width:16px;height:16px}.supamde-separator{background:var(--supamde-border-color);width:1px;height:20px;margin:0 4px;display:inline-block}", In = ".supamde-statusbar{border-top:var(--supamde-divider-statusbar-width,1px) solid var(--supamde-border-color,#d0d0d0);background:var(--supamde-statusbar-bg,#f7f7f7);color:#666;gap:12px;padding:4px 8px;font-size:12px;display:flex}.supamde-statusbar span{white-space:nowrap}", Ln = ".supamde-editor-row{flex-direction:row;align-items:stretch;display:flex}.supamde-editor-row .cm-editor{flex:1;min-width:0}.supamde-container.supamde-sided .supamde-editor-row .cm-editor{flex:0 0 50%;width:50%}.supamde-preview-side{border-left:var(--supamde-divider-preview-width,1px) solid var(--supamde-border-color,#ddd);box-sizing:border-box;width:50%;padding:.5rem 1rem;overflow-y:auto}", Rn = ".supamde-container.supamde-fullscreen{z-index:1000;background:var(--supamde-bg,#fff);flex-direction:column;max-width:none;display:flex;position:fixed;inset:0}.supamde-container.supamde-fullscreen .supamde-editor-row{flex:1;min-height:0}.supamde-container.supamde-fullscreen .supamde-editor-row .cm-editor{height:100%}", zn = "data-supamde-styles", Bn = [
|
|
1627
|
+
Fn,
|
|
1628
|
+
In,
|
|
1629
|
+
Ln,
|
|
1630
|
+
Rn
|
|
1631
|
+
].join("\n");
|
|
1632
|
+
function Vn(e = document) {
|
|
1633
|
+
let t = e.head;
|
|
1634
|
+
if (!t || t.querySelector(`style[${zn}]`)) return;
|
|
1635
|
+
let n = e.createElement("style");
|
|
1636
|
+
n.setAttribute(zn, ""), n.textContent = Bn, t.insertBefore(n, t.firstChild);
|
|
1637
|
+
}
|
|
1638
|
+
//#endregion
|
|
1639
|
+
//#region node_modules/marked/lib/marked.esm.js
|
|
1640
|
+
function Hn() {
|
|
1641
|
+
return {
|
|
1642
|
+
async: !1,
|
|
1643
|
+
breaks: !1,
|
|
1644
|
+
extensions: null,
|
|
1645
|
+
gfm: !0,
|
|
1646
|
+
hooks: null,
|
|
1647
|
+
pedantic: !1,
|
|
1648
|
+
renderer: null,
|
|
1649
|
+
silent: !1,
|
|
1650
|
+
tokenizer: null,
|
|
1651
|
+
walkTokens: null
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
var j = Hn();
|
|
1655
|
+
function Un(e) {
|
|
1656
|
+
j = e;
|
|
1657
|
+
}
|
|
1658
|
+
var M = { exec: () => null };
|
|
1659
|
+
function N(e) {
|
|
1660
|
+
let t = [];
|
|
1661
|
+
return (n) => {
|
|
1662
|
+
let r = Math.max(0, Math.min(3, n - 1)), i = t[r];
|
|
1663
|
+
return i || (i = e(r), t[r] = i), i;
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function P(e, t = "") {
|
|
1667
|
+
let n = typeof e == "string" ? e : e.source, r = {
|
|
1668
|
+
replace: (e, t) => {
|
|
1669
|
+
let i = typeof t == "string" ? t : t.source;
|
|
1670
|
+
return i = i.replace(F.caret, "$1"), n = n.replace(e, i), r;
|
|
1671
|
+
},
|
|
1672
|
+
getRegex: () => new RegExp(n, t)
|
|
1673
|
+
};
|
|
1674
|
+
return r;
|
|
1675
|
+
}
|
|
1676
|
+
var Wn = ((e = "") => {
|
|
1677
|
+
try {
|
|
1678
|
+
return !!RegExp("(?<=1)(?<!1)" + e);
|
|
1679
|
+
} catch {
|
|
1680
|
+
return !1;
|
|
1681
|
+
}
|
|
1682
|
+
})(), F = {
|
|
1683
|
+
codeRemoveIndent: /^(?: {0,3}\t| {1,4})/gm,
|
|
1684
|
+
outputLinkReplace: /\\([\[\]])/g,
|
|
1685
|
+
indentCodeCompensation: /^(\s+)(?:```)/,
|
|
1686
|
+
beginningSpace: /^\s+/,
|
|
1687
|
+
endingHash: /#$/,
|
|
1688
|
+
startingSpaceChar: /^ /,
|
|
1689
|
+
endingSpaceChar: / $/,
|
|
1690
|
+
endingSpaceTabChar: /[ \t]$/,
|
|
1691
|
+
nonSpaceChar: /[^ ]/,
|
|
1692
|
+
newLineCharGlobal: /\n/g,
|
|
1693
|
+
tabCharGlobal: /\t/g,
|
|
1694
|
+
leadingSpaceTab: /^[ \t]+/,
|
|
1695
|
+
multipleSpaceGlobal: /\s+/g,
|
|
1696
|
+
blankLine: /^[ \t]*$/,
|
|
1697
|
+
doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
|
|
1698
|
+
blockquoteStart: /^ {0,3}>/,
|
|
1699
|
+
blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
|
|
1700
|
+
blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
|
|
1701
|
+
listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
|
|
1702
|
+
listIsTask: /^\[[ xX]\] +\S/,
|
|
1703
|
+
listReplaceTask: /^\[[ xX]\] +/,
|
|
1704
|
+
listTaskCheckbox: /\[[ xX]\]/,
|
|
1705
|
+
anyLine: /\n.*\n/,
|
|
1706
|
+
hrefBrackets: /^<(.*)>$/,
|
|
1707
|
+
tableDelimiter: /[:|]/,
|
|
1708
|
+
tableAlignChars: /^\||\| *$/g,
|
|
1709
|
+
tableRowBlankLine: /\n[ \t]*$/,
|
|
1710
|
+
tableAlignRight: /^ *-+: *$/,
|
|
1711
|
+
tableAlignCenter: /^ *:-+: *$/,
|
|
1712
|
+
tableAlignLeft: /^ *:-+ *$/,
|
|
1713
|
+
startATag: /^<a /i,
|
|
1714
|
+
endATag: /^<\/a>/i,
|
|
1715
|
+
startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
|
|
1716
|
+
endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
|
|
1717
|
+
startAngleBracket: /^</,
|
|
1718
|
+
endAngleBracket: />$/,
|
|
1719
|
+
pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
|
|
1720
|
+
unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
|
|
1721
|
+
numericCharacterReference: /&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/g,
|
|
1722
|
+
escapeTest: /[&<>"']/,
|
|
1723
|
+
escapeReplace: /[&<>"']/g,
|
|
1724
|
+
escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
|
|
1725
|
+
escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
|
|
1726
|
+
caret: /(^|[^\[])\^/g,
|
|
1727
|
+
percentDecode: /%25/g,
|
|
1728
|
+
findPipe: /\|/g,
|
|
1729
|
+
splitPipe: / \|/,
|
|
1730
|
+
slashPipe: /\\\|/g,
|
|
1731
|
+
carriageReturn: /\r\n|\r/g,
|
|
1732
|
+
spaceLine: /^ +$/gm,
|
|
1733
|
+
notSpaceStart: /^\S*/,
|
|
1734
|
+
endingNewline: /\n$/,
|
|
1735
|
+
listItemRegex: (e) => RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
1736
|
+
nextBulletRegex: N((e) => RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),
|
|
1737
|
+
hrRegex: N((e) => RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),
|
|
1738
|
+
fencesBeginRegex: N((e) => RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),
|
|
1739
|
+
headingBeginRegex: N((e) => RegExp(`^ {0,${e}}#`)),
|
|
1740
|
+
htmlBeginRegex: N((e) => RegExp(`^ {0,${e}}(?:</?(?:${L})(?: +|$|/?>)|<(?:script|pre|style|textarea|!--))`, "i")),
|
|
1741
|
+
blockquoteBeginRegex: N((e) => RegExp(`^ {0,${e}}>`))
|
|
1742
|
+
}, Gn = /^(?:[ \t]*(?:\n|$))+/, Kn = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, qn = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, Jn = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, Yn = / {0,3}(?:[*+-]|\d{1,9}[.)])/, Xn = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, Zn = P(Xn).replace(/bull/g, Yn).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(), Qn = P(Xn).replace(/bull/g, Yn).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), $n = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/, er = /^[^\n]+/, tr = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/, nr = P(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", tr).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), rr = P(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, Yn).getRegex(), L = "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|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", ir = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, ar = P("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", ir).replace("tag", L).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), or = (e) => P($n).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", e).replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", L).getRegex(), sr = or(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/), cr = or(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/), lr = {
|
|
1743
|
+
blockquote: P(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", cr).getRegex(),
|
|
1744
|
+
code: Kn,
|
|
1745
|
+
def: nr,
|
|
1746
|
+
fences: qn,
|
|
1747
|
+
heading: Jn,
|
|
1748
|
+
hr: I,
|
|
1749
|
+
html: ar,
|
|
1750
|
+
lheading: Zn,
|
|
1751
|
+
list: rr,
|
|
1752
|
+
newline: Gn,
|
|
1753
|
+
paragraph: sr,
|
|
1754
|
+
table: M,
|
|
1755
|
+
text: er
|
|
1756
|
+
}, ur = P("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", L).getRegex(), dr = {
|
|
1757
|
+
...lr,
|
|
1758
|
+
lheading: Qn,
|
|
1759
|
+
table: ur,
|
|
1760
|
+
paragraph: P($n).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", ur).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", L).getRegex()
|
|
1761
|
+
}, fr = {
|
|
1762
|
+
...lr,
|
|
1763
|
+
html: P("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment", ir).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
|
|
1764
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
1765
|
+
heading: /^(#{1,6})(.*)(?:\n+|$)/,
|
|
1766
|
+
fences: M,
|
|
1767
|
+
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
1768
|
+
paragraph: P($n).replace("hr", I).replace("heading", " *#{1,6} *[^\n]").replace("lheading", Zn).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
|
|
1769
|
+
}, pr = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, mr = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, hr = /^( {2,}|\\)\n(?!\s*$)[ \t]*/, gr = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, R = /[\p{P}\p{S}]/u, z = /[\s\p{P}\p{S}]/u, B = /[^\s\p{P}\p{S}]/u, _r = P(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, z).getRegex(), vr = /[\p{Pi}\p{Ps}"']/u, yr = /(?!~)[\p{P}\p{S}]/u, br = /(?!~)[\s\p{P}\p{S}]/u, xr = /(?:[^\s\p{P}\p{S}]|~)/u, Sr = P(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Wn ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex(), Cr = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/, wr = P(Cr, "u").replace(/punct/g, R).getRegex(), Tr = P(Cr, "u").replace(/punct/g, yr).getRegex(), Er = P(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/, "u").replace(/openQuote/g, vr).replace(/punct/g, R).getRegex(), Dr = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", Or = P(Dr, "gu").replace(/notPunctSpace/g, B).replace(/punctSpace/g, z).replace(/punct/g, R).getRegex(), kr = P(Dr, "gu").replace(/notPunctSpace/g, xr).replace(/punctSpace/g, br).replace(/punct/g, yr).getRegex(), Ar = P("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, B).replace(/punctSpace/g, z).replace(/punct/g, R).getRegex(), jr = P("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, B).replace(/punctSpace/g, z).replace(/punct/g, R).getRegex(), Mr = P("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, B).replace(/punctSpace/g, z).replace(/punct/g, R).getRegex(), Nr = P(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, R).getRegex(), Pr = P("^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, B).replace(/punctSpace/g, z).replace(/punct/g, R).getRegex(), Fr = P(/\\(punct)/, "gu").replace(/punct/g, R).getRegex(), Ir = P(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(), Lr = P(ir).replace("(?:-->|$)", "-->").getRegex(), Rr = P("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Lr).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), zr = /\[(?:\\[\s\S]|[^\[\]\\])*\]/, V = P(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets", zr).getRegex(), Br = P(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label", V).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), Vr = P(/^!?\[(label)\]\[(ref)\]/).replace("label", V).replace("ref", tr).getRegex(), Hr = P(/^!?\[(ref)\](?:\[\])?/).replace("ref", tr).getRegex(), Ur = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/, Wr = P(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets", zr).getRegex(), Gr = P("reflink|nolink(?!\\()", "g").replace("reflink", P(/^!?\[(label)\]\[(ref)\]/).replace("label", Wr).replace("ref", Ur).getRegex()).replace("nolink", P(/^!?\[(ref)\](?:\[\])?/).replace("ref", Ur).getRegex()).getRegex(), Kr = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/, qr = P(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g, /[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(), Jr = {
|
|
1770
|
+
_backpedal: M,
|
|
1771
|
+
anyPunctuation: Fr,
|
|
1772
|
+
autolink: Ir,
|
|
1773
|
+
blockSkip: Sr,
|
|
1774
|
+
br: hr,
|
|
1775
|
+
code: mr,
|
|
1776
|
+
del: M,
|
|
1777
|
+
delLDelim: M,
|
|
1778
|
+
delRDelim: M,
|
|
1779
|
+
emStrongLDelim: wr,
|
|
1780
|
+
emStrongRDelimAst: Or,
|
|
1781
|
+
emStrongRDelimUnd: jr,
|
|
1782
|
+
escape: pr,
|
|
1783
|
+
link: Br,
|
|
1784
|
+
nolink: Hr,
|
|
1785
|
+
punctuation: _r,
|
|
1786
|
+
reflink: Vr,
|
|
1787
|
+
reflinkSearch: Gr,
|
|
1788
|
+
tag: Rr,
|
|
1789
|
+
text: gr,
|
|
1790
|
+
url: M
|
|
1791
|
+
}, Yr = {
|
|
1792
|
+
...Jr,
|
|
1793
|
+
emStrongLDelim: Er,
|
|
1794
|
+
emStrongRDelimAst: Ar,
|
|
1795
|
+
emStrongRDelimUnd: Mr,
|
|
1796
|
+
link: P(/^!?\[(label)\]\((.*?)\)/).replace("label", V).getRegex(),
|
|
1797
|
+
reflink: P(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", V).getRegex()
|
|
1798
|
+
}, Xr = {
|
|
1799
|
+
...Jr,
|
|
1800
|
+
emStrongRDelimAst: kr,
|
|
1801
|
+
emStrongLDelim: Tr,
|
|
1802
|
+
delLDelim: Nr,
|
|
1803
|
+
delRDelim: Pr,
|
|
1804
|
+
url: P(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol", qr).replace("protocol", Kr).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),
|
|
1805
|
+
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
1806
|
+
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
|
|
1807
|
+
text: P(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol", Kr).replace(/emailProtocol/g, /(?:mailto|xmpp):/).getRegex()
|
|
1808
|
+
}, Zr = {
|
|
1809
|
+
...Xr,
|
|
1810
|
+
br: P(hr).replace("{2,}", "*").getRegex(),
|
|
1811
|
+
text: P(Xr.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
|
|
1812
|
+
}, H = {
|
|
1813
|
+
normal: lr,
|
|
1814
|
+
gfm: dr,
|
|
1815
|
+
pedantic: fr
|
|
1816
|
+
}, U = {
|
|
1817
|
+
normal: Jr,
|
|
1818
|
+
gfm: Xr,
|
|
1819
|
+
breaks: Zr,
|
|
1820
|
+
pedantic: Yr
|
|
1821
|
+
}, Qr = {
|
|
1822
|
+
"&": "&",
|
|
1823
|
+
"<": "<",
|
|
1824
|
+
">": ">",
|
|
1825
|
+
"\"": """,
|
|
1826
|
+
"'": "'"
|
|
1827
|
+
}, $r = (e) => Qr[e];
|
|
1828
|
+
function W(e, t) {
|
|
1829
|
+
if (t) {
|
|
1830
|
+
if (F.escapeTest.test(e)) return e.replace(F.escapeReplace, $r);
|
|
1831
|
+
} else if (F.escapeTestNoEncode.test(e)) return e.replace(F.escapeReplaceNoEncode, $r);
|
|
1832
|
+
return e;
|
|
1833
|
+
}
|
|
1834
|
+
function ei(e) {
|
|
1835
|
+
return e.replace(F.numericCharacterReference, (e, t, n) => {
|
|
1836
|
+
let r = t === void 0 ? Number.parseInt(n, 16) : Number.parseInt(t, 10);
|
|
1837
|
+
return r === 0 || r > 1114111 || r >= 55296 && r <= 57343 ? "�" : String.fromCodePoint(r);
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
function ti(e) {
|
|
1841
|
+
try {
|
|
1842
|
+
e = encodeURI(e).replace(F.percentDecode, "%");
|
|
1843
|
+
} catch {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
return e;
|
|
1847
|
+
}
|
|
1848
|
+
function ni(e, t) {
|
|
1849
|
+
let n = e.replace(F.findPipe, (e, t, n) => {
|
|
1850
|
+
let r = !1, i = t;
|
|
1851
|
+
for (; --i >= 0 && n[i] === "\\";) r = !r;
|
|
1852
|
+
return r ? "|" : " |";
|
|
1853
|
+
}).split(F.splitPipe), r = 0;
|
|
1854
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), t) {
|
|
1855
|
+
if (n.length > t) n.splice(t);
|
|
1856
|
+
else for (; n.length < t;) n.push("");
|
|
1857
|
+
}
|
|
1858
|
+
for (; r < n.length; r++) n[r] = n[r].trim().replace(F.slashPipe, "|");
|
|
1859
|
+
return n;
|
|
1860
|
+
}
|
|
1861
|
+
function G(e, t, n) {
|
|
1862
|
+
let r = e.length;
|
|
1863
|
+
if (r === 0) return "";
|
|
1864
|
+
let i = 0;
|
|
1865
|
+
for (; i < r;) {
|
|
1866
|
+
let a = e.charAt(r - i - 1);
|
|
1867
|
+
if (a === t && !n) i++;
|
|
1868
|
+
else if (a !== t && n) i++;
|
|
1869
|
+
else break;
|
|
1870
|
+
}
|
|
1871
|
+
return e.slice(0, r - i);
|
|
1872
|
+
}
|
|
1873
|
+
function ri(e) {
|
|
1874
|
+
let t = e.split("\n"), n = t.length - 1;
|
|
1875
|
+
for (; n >= 0 && F.blankLine.test(t[n]);) n--;
|
|
1876
|
+
return t.length - n <= 2 ? e : t.slice(0, n + 1).join("\n");
|
|
1877
|
+
}
|
|
1878
|
+
function K(e) {
|
|
1879
|
+
return e.trim().toLowerCase().toUpperCase().toLowerCase();
|
|
1880
|
+
}
|
|
1881
|
+
function ii(e, t) {
|
|
1882
|
+
if (e.indexOf(t[0]) === -1 && e.indexOf(t[1]) === -1) return -1;
|
|
1883
|
+
let n = 0;
|
|
1884
|
+
for (let r = 0; r < e.length; r++) if (e[r] === "\\") r++;
|
|
1885
|
+
else if (e[r] === t[0]) n++;
|
|
1886
|
+
else if (e[r] === t[1] && (n--, n < 0)) return r;
|
|
1887
|
+
return n > 0 ? -2 : -1;
|
|
1888
|
+
}
|
|
1889
|
+
function ai(e, t = 0) {
|
|
1890
|
+
let n = t, r = "";
|
|
1891
|
+
for (let t of e) if (t === " ") {
|
|
1892
|
+
let e = 4 - n % 4;
|
|
1893
|
+
r += " ".repeat(e), n += e;
|
|
1894
|
+
} else r += t, n++;
|
|
1895
|
+
return r;
|
|
1896
|
+
}
|
|
1897
|
+
function oi(e, t, n, r, i) {
|
|
1898
|
+
let a = t.href, o = t.title || null, s = e[1].replace(i.other.outputLinkReplace, "$1"), c = e[0].charAt(0) === "!";
|
|
1899
|
+
r.state.inLink = !0;
|
|
1900
|
+
let l = r.state.linkEmitted, u = r.state.inRawBlock;
|
|
1901
|
+
r.state.linkEmitted = !1;
|
|
1902
|
+
let d = r.inlineTokens(s), f = r.state.linkEmitted;
|
|
1903
|
+
if (r.state.linkEmitted = l, r.state.inLink = !1, !c) {
|
|
1904
|
+
if (f) {
|
|
1905
|
+
r.state.inRawBlock = u;
|
|
1906
|
+
return;
|
|
1907
|
+
}
|
|
1908
|
+
r.state.linkEmitted = !0;
|
|
1909
|
+
}
|
|
1910
|
+
return {
|
|
1911
|
+
type: c ? "image" : "link",
|
|
1912
|
+
raw: n,
|
|
1913
|
+
href: a,
|
|
1914
|
+
title: o,
|
|
1915
|
+
text: s,
|
|
1916
|
+
tokens: d
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
function si(e, t, n) {
|
|
1920
|
+
let r = e.match(n.other.indentCodeCompensation);
|
|
1921
|
+
if (r === null) return t;
|
|
1922
|
+
let i = r[1];
|
|
1923
|
+
return t.split("\n").map((e) => {
|
|
1924
|
+
let t = e.match(n.other.beginningSpace);
|
|
1925
|
+
if (t === null) return e;
|
|
1926
|
+
let [r] = t;
|
|
1927
|
+
return e.slice(Math.min(r.length, i.length));
|
|
1928
|
+
}).join("\n");
|
|
1929
|
+
}
|
|
1930
|
+
function ci(e, t, n, r) {
|
|
1931
|
+
if (!t.includes("<")) return !1;
|
|
1932
|
+
for (let i = 0; i < t.length; i++) {
|
|
1933
|
+
if (t[i] === "\\") {
|
|
1934
|
+
i++;
|
|
1935
|
+
continue;
|
|
1936
|
+
}
|
|
1937
|
+
if (t[i] === "`") {
|
|
1938
|
+
let e = r.inline.code.exec(t.slice(i));
|
|
1939
|
+
if (e) {
|
|
1940
|
+
i += e[0].length - 1;
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (t[i] !== "<") continue;
|
|
1945
|
+
let a = e.slice(n + i), o = r.inline.tag.exec(a) || r.inline.autolink.exec(a);
|
|
1946
|
+
if (o) {
|
|
1947
|
+
if (o[0].length > t.length - i) return !0;
|
|
1948
|
+
i += o[0].length - 1;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return !1;
|
|
1952
|
+
}
|
|
1953
|
+
var q = class {
|
|
1954
|
+
options;
|
|
1955
|
+
rules;
|
|
1956
|
+
lexer;
|
|
1957
|
+
constructor(e) {
|
|
1958
|
+
this.options = e || j;
|
|
1959
|
+
}
|
|
1960
|
+
space(e) {
|
|
1961
|
+
let t = this.rules.block.newline.exec(e);
|
|
1962
|
+
if (t && t[0].length > 0) return {
|
|
1963
|
+
type: "space",
|
|
1964
|
+
raw: t[0]
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
code(e) {
|
|
1968
|
+
let t = this.rules.block.code.exec(e);
|
|
1969
|
+
if (t) {
|
|
1970
|
+
let e = this.options.pedantic ? t[0] : ri(t[0]);
|
|
1971
|
+
return {
|
|
1972
|
+
type: "code",
|
|
1973
|
+
raw: e,
|
|
1974
|
+
codeBlockStyle: "indented",
|
|
1975
|
+
text: e.replace(this.rules.other.codeRemoveIndent, "")
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
fences(e) {
|
|
1980
|
+
let t = this.rules.block.fences.exec(e);
|
|
1981
|
+
if (t) {
|
|
1982
|
+
let e = t[0], n = si(e, t[3] || "", this.rules);
|
|
1983
|
+
return {
|
|
1984
|
+
type: "code",
|
|
1985
|
+
raw: e,
|
|
1986
|
+
lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
|
|
1987
|
+
text: n
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
heading(e) {
|
|
1992
|
+
let t = this.rules.block.heading.exec(e);
|
|
1993
|
+
if (t) {
|
|
1994
|
+
let e = t[2].trim();
|
|
1995
|
+
if (this.rules.other.endingHash.test(e)) {
|
|
1996
|
+
let t = G(e, "#");
|
|
1997
|
+
(this.options.pedantic || !t || this.rules.other.endingSpaceTabChar.test(t)) && (e = t.trim());
|
|
1998
|
+
}
|
|
1999
|
+
return {
|
|
2000
|
+
type: "heading",
|
|
2001
|
+
raw: G(t[0], "\n"),
|
|
2002
|
+
depth: t[1].length,
|
|
2003
|
+
text: e,
|
|
2004
|
+
tokens: this.lexer.inline(e)
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
hr(e) {
|
|
2009
|
+
let t = this.rules.block.hr.exec(e);
|
|
2010
|
+
if (t) return {
|
|
2011
|
+
type: "hr",
|
|
2012
|
+
raw: G(t[0], "\n")
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
blockquote(e) {
|
|
2016
|
+
let t = this.rules.block.blockquote.exec(e);
|
|
2017
|
+
if (t) {
|
|
2018
|
+
let e = G(t[0], "\n").split("\n"), n = "", r = "", i = [];
|
|
2019
|
+
for (; e.length > 0;) {
|
|
2020
|
+
let t = !1, a = [], o = 0;
|
|
2021
|
+
for (; o < e.length; o++) if (this.rules.other.blockquoteStart.test(e[o])) a.push(e[o]), t = !0;
|
|
2022
|
+
else if (!t) a.push(e[o]);
|
|
2023
|
+
else break;
|
|
2024
|
+
e = e.slice(o);
|
|
2025
|
+
let s = a.join("\n"), c = s.replace(this.rules.other.blockquoteSetextReplace, "\n $1").replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
2026
|
+
n = n ? `${n}
|
|
2027
|
+
${s}` : s, r = r ? `${r}
|
|
2028
|
+
${c}` : c;
|
|
2029
|
+
let l = this.lexer.state.top;
|
|
2030
|
+
if (this.lexer.state.top = !0, this.lexer.blockTokens(c, i, !0), this.lexer.state.top = l, e.length === 0) break;
|
|
2031
|
+
let u = i.at(-1);
|
|
2032
|
+
if (u?.type === "code") break;
|
|
2033
|
+
if (u?.type === "blockquote") {
|
|
2034
|
+
let t = u, a = e.join("\n"), o = t.raw + "\n" + a.replace(this.rules.other.blockquoteSetextReplace2, ""), s = this.blockquote(o);
|
|
2035
|
+
i[i.length - 1] = s;
|
|
2036
|
+
let c = o.substring(s.raw.length).replace(/^\n/, ""), l = c ? c.split("\n").length : 0, d = l ? e.slice(0, -l) : e;
|
|
2037
|
+
d.length > 0 && (n = `${n}
|
|
2038
|
+
${d.join("\n")}`), r = r.substring(0, r.length - t.text.length) + s.text;
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
2041
|
+
if (u?.type === "list") {
|
|
2042
|
+
let t = u, a = t.raw + "\n" + e.join("\n"), o = this.list(a);
|
|
2043
|
+
i[i.length - 1] = o, n = n.substring(0, n.length - u.raw.length) + o.raw, r = r.substring(0, r.length - t.raw.length) + o.raw, e = a.substring(i.at(-1).raw.length).split("\n");
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
return {
|
|
2047
|
+
type: "blockquote",
|
|
2048
|
+
raw: n,
|
|
2049
|
+
tokens: i,
|
|
2050
|
+
text: r
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
list(e) {
|
|
2055
|
+
let t = this.rules.block.list.exec(e);
|
|
2056
|
+
if (t) {
|
|
2057
|
+
let n = t[1].trim(), r = n.length > 1, i = {
|
|
2058
|
+
type: "list",
|
|
2059
|
+
raw: "",
|
|
2060
|
+
ordered: r,
|
|
2061
|
+
start: r ? +n.slice(0, -1) : "",
|
|
2062
|
+
loose: !1,
|
|
2063
|
+
items: []
|
|
2064
|
+
};
|
|
2065
|
+
n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
|
|
2066
|
+
let a = this.rules.other.listItemRegex(n), o = !1;
|
|
2067
|
+
for (; e;) {
|
|
2068
|
+
let n = !1, r = "", s = "";
|
|
2069
|
+
if (!(t = a.exec(e)) || this.rules.block.hr.test(e)) break;
|
|
2070
|
+
r = t[0], e = e.substring(r.length);
|
|
2071
|
+
let c = t[2].split("\n", 1)[0], l = t[1].length, u = this.options.pedantic ? ai(c, l) : c.replace(this.rules.other.leadingSpaceTab, (e) => ai(e, l)), d = e.split("\n", 1)[0], f = !u.trim(), p = 0;
|
|
2072
|
+
if (this.options.pedantic ? (p = 2, s = u.trimStart()) : f ? p = l + 1 : (p = u.search(this.rules.other.nonSpaceChar), p = p > 4 ? 1 : p, s = u.slice(p), p += l), f && this.rules.other.blankLine.test(d) && (r += d + "\n", e = e.substring(d.length + 1), n = !0), !n) {
|
|
2073
|
+
let t = this.rules.other.nextBulletRegex(p), n = this.rules.other.hrRegex(p), i = this.rules.other.fencesBeginRegex(p), a = this.rules.other.headingBeginRegex(p), o = this.rules.other.htmlBeginRegex(p), c = this.rules.other.blockquoteBeginRegex(p);
|
|
2074
|
+
for (; e;) {
|
|
2075
|
+
let l = e.split("\n", 1)[0], m;
|
|
2076
|
+
if (d = l, this.options.pedantic ? (d = d.replace(this.rules.other.listReplaceNesting, " "), m = d) : m = d.replace(this.rules.other.leadingSpaceTab, (e) => e.replace(this.rules.other.tabCharGlobal, " ")), i.test(d) || a.test(d) || o.test(d) || c.test(d) || t.test(d) || n.test(d)) break;
|
|
2077
|
+
if (m.search(this.rules.other.nonSpaceChar) >= p || !d.trim()) s += "\n" + m.slice(p);
|
|
2078
|
+
else {
|
|
2079
|
+
if (f || u.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || i.test(u) || a.test(u) || n.test(u)) break;
|
|
2080
|
+
s += "\n" + d;
|
|
2081
|
+
}
|
|
2082
|
+
f = !d.trim(), r += l + "\n", e = e.substring(l.length + 1), u = m.slice(p);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
i.loose || (o ? i.loose = !0 : this.rules.other.doubleBlankLine.test(r) && (o = !0)), i.items.push({
|
|
2086
|
+
type: "list_item",
|
|
2087
|
+
raw: r,
|
|
2088
|
+
task: !!this.options.gfm && this.rules.other.listIsTask.test(s),
|
|
2089
|
+
loose: !1,
|
|
2090
|
+
text: s,
|
|
2091
|
+
tokens: []
|
|
2092
|
+
}), i.raw += r;
|
|
2093
|
+
}
|
|
2094
|
+
let s = i.items.at(-1);
|
|
2095
|
+
if (s) s.raw = s.raw.trimEnd(), s.text = s.text.trimEnd();
|
|
2096
|
+
else return;
|
|
2097
|
+
i.raw = i.raw.trimEnd();
|
|
2098
|
+
for (let e of i.items) if (this.lexer.state.top = !1, e.tokens = this.lexer.blockTokens(e.text, []), !i.loose) {
|
|
2099
|
+
let t = e.tokens.filter((e) => e.type === "space");
|
|
2100
|
+
i.loose = t.length > 0 && t.some((e) => this.rules.other.anyLine.test(e.raw));
|
|
2101
|
+
}
|
|
2102
|
+
for (let e of i.items) {
|
|
2103
|
+
let t = e.tokens[0];
|
|
2104
|
+
if (e.task && (t?.type === "text" || t?.type === "paragraph")) {
|
|
2105
|
+
e.text = e.text.replace(this.rules.other.listReplaceTask, ""), t.raw = t.raw.replace(this.rules.other.listReplaceTask, ""), t.text = t.text.replace(this.rules.other.listReplaceTask, "");
|
|
2106
|
+
for (let e = this.lexer.inlineQueue.length - 1; e >= 0; e--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)) {
|
|
2107
|
+
this.lexer.inlineQueue[e].src = this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask, "");
|
|
2108
|
+
break;
|
|
2109
|
+
}
|
|
2110
|
+
let n = this.rules.other.listTaskCheckbox.exec(e.raw);
|
|
2111
|
+
if (n) {
|
|
2112
|
+
let t = {
|
|
2113
|
+
type: "checkbox",
|
|
2114
|
+
raw: n[0] + " ",
|
|
2115
|
+
checked: n[0] !== "[ ]"
|
|
2116
|
+
};
|
|
2117
|
+
e.checked = t.checked, i.loose ? e.tokens[0] && ["paragraph", "text"].includes(e.tokens[0].type) && "tokens" in e.tokens[0] && e.tokens[0].tokens ? (e.tokens[0].raw = t.raw + e.tokens[0].raw, e.tokens[0].text = t.raw + e.tokens[0].text, e.tokens[0].tokens.unshift(t)) : e.tokens.unshift({
|
|
2118
|
+
type: "paragraph",
|
|
2119
|
+
raw: t.raw,
|
|
2120
|
+
text: t.raw,
|
|
2121
|
+
tokens: [t]
|
|
2122
|
+
}) : e.tokens.unshift(t);
|
|
2123
|
+
}
|
|
2124
|
+
} else e.task &&= !1;
|
|
2125
|
+
}
|
|
2126
|
+
if (i.loose) for (let e of i.items) {
|
|
2127
|
+
e.loose = !0;
|
|
2128
|
+
for (let t of e.tokens) t.type === "text" && (t.type = "paragraph");
|
|
2129
|
+
}
|
|
2130
|
+
return i;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
html(e) {
|
|
2134
|
+
let t = this.rules.block.html.exec(e);
|
|
2135
|
+
if (t) {
|
|
2136
|
+
let e = ri(t[0]);
|
|
2137
|
+
return {
|
|
2138
|
+
type: "html",
|
|
2139
|
+
block: !0,
|
|
2140
|
+
raw: e,
|
|
2141
|
+
pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
|
|
2142
|
+
text: e
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
def(e) {
|
|
2147
|
+
let t = this.rules.block.def.exec(e);
|
|
2148
|
+
if (t) {
|
|
2149
|
+
if (!this.rules.other.startAngleBracket.test(t[2]) && ii(t[2], "()") !== -1) return;
|
|
2150
|
+
let e = K(t[1]).replace(this.rules.other.multipleSpaceGlobal, " "), n = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
|
|
2151
|
+
return {
|
|
2152
|
+
type: "def",
|
|
2153
|
+
tag: e,
|
|
2154
|
+
raw: G(t[0], "\n"),
|
|
2155
|
+
href: n,
|
|
2156
|
+
title: r
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
table(e) {
|
|
2161
|
+
let t = this.rules.block.table.exec(e);
|
|
2162
|
+
if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
|
|
2163
|
+
let n = ni(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split("\n") : [], a = {
|
|
2164
|
+
type: "table",
|
|
2165
|
+
raw: G(t[0], "\n"),
|
|
2166
|
+
header: [],
|
|
2167
|
+
align: [],
|
|
2168
|
+
rows: []
|
|
2169
|
+
};
|
|
2170
|
+
if (n.length === r.length) {
|
|
2171
|
+
for (let e of r) this.rules.other.tableAlignRight.test(e) ? a.align.push("right") : this.rules.other.tableAlignCenter.test(e) ? a.align.push("center") : this.rules.other.tableAlignLeft.test(e) ? a.align.push("left") : a.align.push(null);
|
|
2172
|
+
for (let e = 0; e < n.length; e++) a.header.push({
|
|
2173
|
+
text: n[e],
|
|
2174
|
+
tokens: this.lexer.inline(n[e]),
|
|
2175
|
+
header: !0,
|
|
2176
|
+
align: a.align[e]
|
|
2177
|
+
});
|
|
2178
|
+
for (let e of i) a.rows.push(ni(e, a.header.length).map((e, t) => ({
|
|
2179
|
+
text: e,
|
|
2180
|
+
tokens: this.lexer.inline(e),
|
|
2181
|
+
header: !1,
|
|
2182
|
+
align: a.align[t]
|
|
2183
|
+
})));
|
|
2184
|
+
return a;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
lheading(e) {
|
|
2188
|
+
let t = this.rules.block.lheading.exec(e);
|
|
2189
|
+
if (t) {
|
|
2190
|
+
let e = t[1].trim();
|
|
2191
|
+
return {
|
|
2192
|
+
type: "heading",
|
|
2193
|
+
raw: G(t[0], "\n"),
|
|
2194
|
+
depth: t[2].charAt(0) === "=" ? 1 : 2,
|
|
2195
|
+
text: e,
|
|
2196
|
+
tokens: this.lexer.inline(e)
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
paragraph(e) {
|
|
2201
|
+
let t = this.rules.block.paragraph.exec(e);
|
|
2202
|
+
if (t) {
|
|
2203
|
+
let e = t[1].charAt(t[1].length - 1) === "\n" ? t[1].slice(0, -1) : t[1];
|
|
2204
|
+
return {
|
|
2205
|
+
type: "paragraph",
|
|
2206
|
+
raw: t[0],
|
|
2207
|
+
text: e,
|
|
2208
|
+
tokens: this.lexer.inline(e)
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
text(e) {
|
|
2213
|
+
let t = this.rules.block.text.exec(e);
|
|
2214
|
+
if (t) return {
|
|
2215
|
+
type: "text",
|
|
2216
|
+
raw: t[0],
|
|
2217
|
+
text: t[0],
|
|
2218
|
+
tokens: this.lexer.inline(t[0])
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
escape(e) {
|
|
2222
|
+
let t = this.rules.inline.escape.exec(e);
|
|
2223
|
+
if (t) return {
|
|
2224
|
+
type: "escape",
|
|
2225
|
+
raw: t[0],
|
|
2226
|
+
text: t[1]
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
tag(e) {
|
|
2230
|
+
let t = this.rules.inline.tag.exec(e);
|
|
2231
|
+
if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = !1), {
|
|
2232
|
+
type: "html",
|
|
2233
|
+
raw: t[0],
|
|
2234
|
+
inLink: this.lexer.state.inLink,
|
|
2235
|
+
inRawBlock: this.lexer.state.inRawBlock,
|
|
2236
|
+
block: !1,
|
|
2237
|
+
text: t[0]
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
link(e) {
|
|
2241
|
+
if (this.lexer.state.linkParenPossible === !1) return;
|
|
2242
|
+
let t = this.rules.inline.link.exec(e);
|
|
2243
|
+
if (t) {
|
|
2244
|
+
let n = t[0].charAt(0) === "!" ? 2 : 1;
|
|
2245
|
+
if (!this.options.pedantic && ci(e, t[1], n, this.rules)) return;
|
|
2246
|
+
let r = t[2].trim();
|
|
2247
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(r)) {
|
|
2248
|
+
if (!this.rules.other.endAngleBracket.test(r)) return;
|
|
2249
|
+
let e = G(r.slice(0, -1), "\\");
|
|
2250
|
+
if ((r.length - e.length) % 2 == 0) return;
|
|
2251
|
+
} else {
|
|
2252
|
+
let e = ii(t[2], "()");
|
|
2253
|
+
if (e === -2) return;
|
|
2254
|
+
if (e > -1) {
|
|
2255
|
+
let n = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + e;
|
|
2256
|
+
t[2] = t[2].substring(0, e), t[0] = t[0].substring(0, n).trim(), t[3] = "";
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
let i = t[2], a = "";
|
|
2260
|
+
if (this.options.pedantic) {
|
|
2261
|
+
let e = this.rules.other.pedanticHrefTitle.exec(i);
|
|
2262
|
+
e && (i = e[1], a = e[3]);
|
|
2263
|
+
} else a = t[3] ? t[3].slice(1, -1) : "";
|
|
2264
|
+
return i = i.trim(), this.rules.other.startAngleBracket.test(i) && (i = this.options.pedantic && !this.rules.other.endAngleBracket.test(r) ? i.slice(1) : i.slice(1, -1)), oi(t, {
|
|
2265
|
+
href: i && i.replace(this.rules.inline.anyPunctuation, "$1"),
|
|
2266
|
+
title: a && a.replace(this.rules.inline.anyPunctuation, "$1")
|
|
2267
|
+
}, t[0], this.lexer, this.rules);
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
reflink(e, t) {
|
|
2271
|
+
let n;
|
|
2272
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
2273
|
+
let r = n[0].charAt(0) === "!" ? 2 : 1;
|
|
2274
|
+
if (!this.options.pedantic && ci(e, n[1], r, this.rules)) return;
|
|
2275
|
+
let i = t[K((n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "))];
|
|
2276
|
+
if (!i) {
|
|
2277
|
+
let e = n[0].charAt(0);
|
|
2278
|
+
return {
|
|
2279
|
+
type: "text",
|
|
2280
|
+
raw: e,
|
|
2281
|
+
text: e
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2284
|
+
return oi(n, i, n[0], this.lexer, this.rules);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
emStrong(e, t, n = "") {
|
|
2288
|
+
let r = this.rules.inline.emStrongLDelim.exec(e);
|
|
2289
|
+
if (!(!r || !r[1] && !r[2] && !r[3] && !r[4] || r[4] && n.match(this.rules.other.unicodeAlphaNumeric)) && (!(r[1] || r[3]) || !n || this.rules.inline.punctuation.exec(n))) {
|
|
2290
|
+
let i = [...r[0]].length - 1, a, o, s = i, c = 0, l = r[0][0], u = n === l, d = l === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
2291
|
+
for (d.lastIndex = 0, t = t.slice(-1 * e.length + i); (r = d.exec(t)) !== null;) {
|
|
2292
|
+
if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a) continue;
|
|
2293
|
+
if (o = [...a].length, r[3] || r[4]) {
|
|
2294
|
+
s += o;
|
|
2295
|
+
continue;
|
|
2296
|
+
}
|
|
2297
|
+
if (r[5] || r[6]) {
|
|
2298
|
+
if (i % 3 && !((i + o) % 3)) {
|
|
2299
|
+
c += o;
|
|
2300
|
+
continue;
|
|
2301
|
+
}
|
|
2302
|
+
if (u) break;
|
|
2303
|
+
}
|
|
2304
|
+
if (s -= o, s > 0) continue;
|
|
2305
|
+
o = Math.min(o, o + s + c);
|
|
2306
|
+
let t = [...r[0]][0].length, n = e.slice(0, i + r.index + t + o);
|
|
2307
|
+
if (Math.min(i, o) % 2) {
|
|
2308
|
+
let e = n.slice(1, -1);
|
|
2309
|
+
return {
|
|
2310
|
+
type: "em",
|
|
2311
|
+
raw: n,
|
|
2312
|
+
text: e,
|
|
2313
|
+
tokens: this.lexer.inlineTokens(e)
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
let l = n.slice(2, -2);
|
|
2317
|
+
return {
|
|
2318
|
+
type: "strong",
|
|
2319
|
+
raw: n,
|
|
2320
|
+
text: l,
|
|
2321
|
+
tokens: this.lexer.inlineTokens(l)
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
codespan(e) {
|
|
2327
|
+
let t = this.rules.inline.code.exec(e);
|
|
2328
|
+
if (t) {
|
|
2329
|
+
let e = t[2].replace(this.rules.other.newLineCharGlobal, " "), n = this.rules.other.nonSpaceChar.test(e), r = this.rules.other.startingSpaceChar.test(e) && this.rules.other.endingSpaceChar.test(e);
|
|
2330
|
+
return n && r && (e = e.substring(1, e.length - 1)), {
|
|
2331
|
+
type: "codespan",
|
|
2332
|
+
raw: t[0],
|
|
2333
|
+
text: e
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
br(e) {
|
|
2338
|
+
let t = this.rules.inline.br.exec(e);
|
|
2339
|
+
if (t) return {
|
|
2340
|
+
type: "br",
|
|
2341
|
+
raw: t[0]
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
del(e, t, n = "") {
|
|
2345
|
+
let r = this.rules.inline.delLDelim.exec(e);
|
|
2346
|
+
if (r && (!r[1] || !n || this.rules.inline.punctuation.exec(n))) {
|
|
2347
|
+
let n = [...r[0]].length - 1, i, a, o = n, s = this.rules.inline.delRDelim;
|
|
2348
|
+
for (s.lastIndex = 0, t = t.slice(-1 * e.length + n); (r = s.exec(t)) !== null;) {
|
|
2349
|
+
if (i = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !i || (a = [...i].length, a !== n)) continue;
|
|
2350
|
+
if (r[3] || r[4]) {
|
|
2351
|
+
o += a;
|
|
2352
|
+
continue;
|
|
2353
|
+
}
|
|
2354
|
+
if (o -= a, o > 0) continue;
|
|
2355
|
+
a = Math.min(a, a + o);
|
|
2356
|
+
let t = [...r[0]][0].length, s = e.slice(0, n + r.index + t + a), c = s.slice(n, -n);
|
|
2357
|
+
return {
|
|
2358
|
+
type: "del",
|
|
2359
|
+
raw: s,
|
|
2360
|
+
text: c,
|
|
2361
|
+
tokens: this.lexer.inlineTokens(c)
|
|
2362
|
+
};
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
autolink(e) {
|
|
2367
|
+
let t = this.rules.inline.autolink.exec(e);
|
|
2368
|
+
if (t) {
|
|
2369
|
+
let e, n;
|
|
2370
|
+
return t[2] === "@" ? (e = t[1], n = "mailto:" + e) : (e = t[1], n = e), {
|
|
2371
|
+
type: "link",
|
|
2372
|
+
raw: t[0],
|
|
2373
|
+
text: e,
|
|
2374
|
+
href: n,
|
|
2375
|
+
autolink: !0,
|
|
2376
|
+
tokens: [{
|
|
2377
|
+
type: "text",
|
|
2378
|
+
raw: e,
|
|
2379
|
+
text: e
|
|
2380
|
+
}]
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
url(e) {
|
|
2385
|
+
let t;
|
|
2386
|
+
if (t = this.rules.inline.url.exec(e)) {
|
|
2387
|
+
let e, n;
|
|
2388
|
+
if (t[2] === "@") e = t[0], n = "mailto:" + e;
|
|
2389
|
+
else {
|
|
2390
|
+
let r;
|
|
2391
|
+
do
|
|
2392
|
+
r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
|
|
2393
|
+
while (r !== t[0]);
|
|
2394
|
+
e = t[0], n = t[1] === "www." ? "http://" + t[0] : t[0];
|
|
2395
|
+
}
|
|
2396
|
+
return {
|
|
2397
|
+
type: "link",
|
|
2398
|
+
raw: t[0],
|
|
2399
|
+
text: e,
|
|
2400
|
+
href: n,
|
|
2401
|
+
autolink: !0,
|
|
2402
|
+
tokens: [{
|
|
2403
|
+
type: "text",
|
|
2404
|
+
raw: e,
|
|
2405
|
+
text: e
|
|
2406
|
+
}]
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
inlineText(e) {
|
|
2411
|
+
let t = this.rules.inline.text.exec(e);
|
|
2412
|
+
if (t) {
|
|
2413
|
+
let e = this.lexer.state.inRawBlock;
|
|
2414
|
+
return {
|
|
2415
|
+
type: "text",
|
|
2416
|
+
raw: t[0],
|
|
2417
|
+
text: e ? t[0] : ei(t[0]),
|
|
2418
|
+
escaped: e
|
|
2419
|
+
};
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
}, J = class e {
|
|
2423
|
+
tokens;
|
|
2424
|
+
options;
|
|
2425
|
+
state;
|
|
2426
|
+
inlineQueue;
|
|
2427
|
+
tokenizer;
|
|
2428
|
+
constructor(e) {
|
|
2429
|
+
this.tokens = [], this.tokens.links = Object.create(null), this.options = e || j, this.options.tokenizer = this.options.tokenizer || new q(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
|
|
2430
|
+
inLink: !1,
|
|
2431
|
+
inRawBlock: !1,
|
|
2432
|
+
linkEmitted: !1,
|
|
2433
|
+
linkParenPossible: !0,
|
|
2434
|
+
top: !0
|
|
2435
|
+
};
|
|
2436
|
+
let t = {
|
|
2437
|
+
other: F,
|
|
2438
|
+
block: H.normal,
|
|
2439
|
+
inline: U.normal
|
|
2440
|
+
};
|
|
2441
|
+
this.options.pedantic ? (t.block = H.pedantic, t.inline = U.pedantic) : this.options.gfm && (t.block = H.gfm, t.inline = this.options.breaks ? U.breaks : U.gfm), this.tokenizer.rules = t;
|
|
2442
|
+
}
|
|
2443
|
+
static get rules() {
|
|
2444
|
+
return {
|
|
2445
|
+
block: H,
|
|
2446
|
+
inline: U
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
static lex(t, n) {
|
|
2450
|
+
return new e(n).lex(t);
|
|
2451
|
+
}
|
|
2452
|
+
static lexInline(t, n) {
|
|
2453
|
+
return new e(n).inlineTokens(t);
|
|
2454
|
+
}
|
|
2455
|
+
lex(e) {
|
|
2456
|
+
e = e.replace(F.carriageReturn, "\n"), this.blockTokens(e, this.tokens);
|
|
2457
|
+
for (let e = 0; e < this.inlineQueue.length; e++) {
|
|
2458
|
+
let t = this.inlineQueue[e];
|
|
2459
|
+
this.inlineTokens(t.src, t.tokens);
|
|
2460
|
+
}
|
|
2461
|
+
return this.inlineQueue = [], this.tokens;
|
|
2462
|
+
}
|
|
2463
|
+
blockTokens(e, t = [], n = !1) {
|
|
2464
|
+
this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(F.tabCharGlobal, " ").replace(F.spaceLine, ""));
|
|
2465
|
+
let r = 1 / 0;
|
|
2466
|
+
for (; e;) {
|
|
2467
|
+
if (e.length < r) r = e.length;
|
|
2468
|
+
else {
|
|
2469
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
2470
|
+
break;
|
|
2471
|
+
}
|
|
2472
|
+
let i;
|
|
2473
|
+
if (this.options.extensions?.block?.some((n) => (i = n.call({ lexer: this }, e, t)) ? (e = e.substring(i.raw.length), t.push(i), !0) : !1)) continue;
|
|
2474
|
+
if (i = this.tokenizer.space(e)) {
|
|
2475
|
+
e = e.substring(i.raw.length);
|
|
2476
|
+
let n = t.at(-1);
|
|
2477
|
+
i.raw.length === 1 && n !== void 0 ? n.raw += "\n" : t.push(i);
|
|
2478
|
+
continue;
|
|
2479
|
+
}
|
|
2480
|
+
if (i = this.tokenizer.code(e)) {
|
|
2481
|
+
e = e.substring(i.raw.length);
|
|
2482
|
+
let n = t.at(-1);
|
|
2483
|
+
n?.type === "paragraph" || n?.type === "text" ? (n.raw += (n.raw.endsWith("\n") ? "" : "\n") + i.raw, n.text += "\n" + i.text, this.inlineQueue.at(-1).src = n.text) : t.push(i);
|
|
2484
|
+
continue;
|
|
2485
|
+
}
|
|
2486
|
+
if ((i = this.tokenizer.fences(e)) || (i = this.tokenizer.heading(e)) || (i = this.tokenizer.hr(e)) || (i = this.tokenizer.blockquote(e)) || (i = this.tokenizer.list(e)) || (i = this.tokenizer.html(e))) {
|
|
2487
|
+
e = e.substring(i.raw.length), t.push(i);
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
if (i = this.tokenizer.def(e)) {
|
|
2491
|
+
e = e.substring(i.raw.length);
|
|
2492
|
+
let n = t.at(-1);
|
|
2493
|
+
n?.type === "paragraph" || n?.type === "text" ? (n.raw += (n.raw.endsWith("\n") ? "" : "\n") + i.raw, n.text += "\n" + i.raw, this.inlineQueue.at(-1).src = n.text) : this.tokens.links[i.tag] || (this.tokens.links[i.tag] = {
|
|
2494
|
+
href: i.href,
|
|
2495
|
+
title: i.title
|
|
2496
|
+
}, t.push(i));
|
|
2497
|
+
continue;
|
|
2498
|
+
}
|
|
2499
|
+
if ((i = this.tokenizer.table(e)) || (i = this.tokenizer.lheading(e))) {
|
|
2500
|
+
e = e.substring(i.raw.length), t.push(i);
|
|
2501
|
+
continue;
|
|
2502
|
+
}
|
|
2503
|
+
let a = e;
|
|
2504
|
+
if (this.options.extensions?.startBlock) {
|
|
2505
|
+
let t = 1 / 0, n = e.slice(1), r;
|
|
2506
|
+
this.options.extensions.startBlock.forEach((e) => {
|
|
2507
|
+
r = e.call({ lexer: this }, n), typeof r == "number" && r >= 0 && (t = Math.min(t, r));
|
|
2508
|
+
}), t < 1 / 0 && t >= 0 && (a = e.substring(0, t + 1));
|
|
2509
|
+
}
|
|
2510
|
+
if (this.state.top && (i = this.tokenizer.paragraph(a))) {
|
|
2511
|
+
let r = t.at(-1);
|
|
2512
|
+
n && r?.type === "paragraph" ? (r.raw += (r.raw.endsWith("\n") ? "" : "\n") + i.raw, r.text += "\n" + i.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = r.text) : t.push(i), n = a.length !== e.length, e = e.substring(i.raw.length);
|
|
2513
|
+
} else if (i = this.tokenizer.text(e)) {
|
|
2514
|
+
e = e.substring(i.raw.length);
|
|
2515
|
+
let n = t.at(-1);
|
|
2516
|
+
n?.type === "text" ? (n.raw += (n.raw.endsWith("\n") ? "" : "\n") + i.raw, n.text += "\n" + i.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = n.text) : t.push(i);
|
|
2517
|
+
} else if (e) {
|
|
2518
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
2519
|
+
break;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
return this.state.top = !0, t;
|
|
2523
|
+
}
|
|
2524
|
+
inline(e, t = []) {
|
|
2525
|
+
return this.inlineQueue.push({
|
|
2526
|
+
src: e,
|
|
2527
|
+
tokens: t
|
|
2528
|
+
}), t;
|
|
2529
|
+
}
|
|
2530
|
+
linkInText(e) {
|
|
2531
|
+
if (!e.includes("[")) return !1;
|
|
2532
|
+
let t = this.tokenizer.rules.inline.link;
|
|
2533
|
+
for (let n of e.matchAll(this.tokenizer.rules.inline.blockSkip)) if (t.test(n[0]) && e.charAt(n.index - 1) !== "!") return !0;
|
|
2534
|
+
for (let t of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)) {
|
|
2535
|
+
let e = t[0], n = e.lastIndexOf("[");
|
|
2536
|
+
if (e.charAt(0) !== "!" && Object.hasOwn(this.tokens.links, K(e.slice(n + 1, -1))) && !(n > 1 && this.linkInText(e.slice(1, n - 1)))) return !0;
|
|
2537
|
+
}
|
|
2538
|
+
return !1;
|
|
2539
|
+
}
|
|
2540
|
+
inlineTokens(e, t = []) {
|
|
2541
|
+
this.tokenizer.lexer = this;
|
|
2542
|
+
let n = this.state.linkParenPossible;
|
|
2543
|
+
this.state.linkParenPossible = n && e.includes(")");
|
|
2544
|
+
try {
|
|
2545
|
+
return this.#e(e, t);
|
|
2546
|
+
} finally {
|
|
2547
|
+
this.state.linkParenPossible = n;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
#e(e, t) {
|
|
2551
|
+
let n = e;
|
|
2552
|
+
if (this.tokens.links && e.includes("[")) {
|
|
2553
|
+
let e = this.tokenizer.rules.inline.reflinkSearch, t = (n) => {
|
|
2554
|
+
let r = n.lastIndexOf("[");
|
|
2555
|
+
if (!Object.hasOwn(this.tokens.links, K(n.slice(r + 1, -1)))) return n;
|
|
2556
|
+
if (r > 1 && n.charAt(0) !== "!") {
|
|
2557
|
+
let i = n.slice(1, r - 1);
|
|
2558
|
+
if (this.linkInText(i)) return "[" + i.replace(e, t) + "][" + "a".repeat(n.length - r - 2) + "]";
|
|
2559
|
+
}
|
|
2560
|
+
return "[" + "a".repeat(n.length - 2) + "]";
|
|
2561
|
+
};
|
|
2562
|
+
n = n.replace(e, t);
|
|
2563
|
+
}
|
|
2564
|
+
n = n.replace(this.tokenizer.rules.inline.anyPunctuation, (e) => "+".repeat(e.length)), n = n.replace(this.tokenizer.rules.inline.blockSkip, (e, t, n) => {
|
|
2565
|
+
let r = n ? n.length : 0;
|
|
2566
|
+
return e.slice(0, r) + "[" + "a".repeat(e.length - r - 2) + "]";
|
|
2567
|
+
}), n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
2568
|
+
let r = !1, i = "", a = 1 / 0;
|
|
2569
|
+
for (; e;) {
|
|
2570
|
+
if (e.length < a) a = e.length;
|
|
2571
|
+
else {
|
|
2572
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
2573
|
+
break;
|
|
2574
|
+
}
|
|
2575
|
+
r || (i = ""), r = !1;
|
|
2576
|
+
let o;
|
|
2577
|
+
if (this.options.extensions?.inline?.some((n) => (o = n.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), !0) : !1)) continue;
|
|
2578
|
+
if ((o = this.tokenizer.escape(e)) || (o = this.tokenizer.tag(e)) || (o = this.tokenizer.link(e))) {
|
|
2579
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
2580
|
+
continue;
|
|
2581
|
+
}
|
|
2582
|
+
if (o = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
2583
|
+
e = e.substring(o.raw.length);
|
|
2584
|
+
let n = t.at(-1);
|
|
2585
|
+
o.type === "text" && n?.type === "text" ? (n.raw += o.raw, n.text += o.text) : t.push(o);
|
|
2586
|
+
continue;
|
|
2587
|
+
}
|
|
2588
|
+
if ((o = this.tokenizer.emStrong(e, n, i)) || (o = this.tokenizer.codespan(e)) || (o = this.tokenizer.br(e)) || (o = this.tokenizer.del(e, n, i)) || (o = this.tokenizer.autolink(e)) || !this.state.inLink && (o = this.tokenizer.url(e))) {
|
|
2589
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
2590
|
+
continue;
|
|
2591
|
+
}
|
|
2592
|
+
let s = e;
|
|
2593
|
+
if (this.options.extensions?.startInline) {
|
|
2594
|
+
let t = 1 / 0, n = e.slice(1), r;
|
|
2595
|
+
this.options.extensions.startInline.forEach((e) => {
|
|
2596
|
+
r = e.call({ lexer: this }, n), typeof r == "number" && r >= 0 && (t = Math.min(t, r));
|
|
2597
|
+
}), t < 1 / 0 && t >= 0 && (s = e.substring(0, t + 1));
|
|
2598
|
+
}
|
|
2599
|
+
if (o = this.tokenizer.inlineText(s)) {
|
|
2600
|
+
e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (i = o.raw.slice(-1)), r = !0;
|
|
2601
|
+
let n = t.at(-1);
|
|
2602
|
+
n?.type === "text" ? (n.raw += o.raw, n.text += o.text) : t.push(o);
|
|
2603
|
+
} else if (e) {
|
|
2604
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
2605
|
+
break;
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
return t;
|
|
2609
|
+
}
|
|
2610
|
+
infiniteLoopError(e) {
|
|
2611
|
+
let t = "Infinite loop on byte: " + e;
|
|
2612
|
+
if (this.options.silent) console.error(t);
|
|
2613
|
+
else throw Error(t);
|
|
2614
|
+
}
|
|
2615
|
+
}, Y = class {
|
|
2616
|
+
options;
|
|
2617
|
+
parser;
|
|
2618
|
+
constructor(e) {
|
|
2619
|
+
this.options = e || j;
|
|
2620
|
+
}
|
|
2621
|
+
space(e) {
|
|
2622
|
+
return "";
|
|
2623
|
+
}
|
|
2624
|
+
code({ text: e, lang: t, escaped: n }) {
|
|
2625
|
+
let r = (t || "").match(F.notSpaceStart)?.[0], i = e ? e.replace(F.endingNewline, "") + "\n" : "";
|
|
2626
|
+
return r ? "<pre><code class=\"language-" + W(r) + "\">" + (n ? i : W(i, !0)) + "</code></pre>\n" : "<pre><code>" + (n ? i : W(i, !0)) + "</code></pre>\n";
|
|
2627
|
+
}
|
|
2628
|
+
blockquote({ tokens: e }) {
|
|
2629
|
+
return `<blockquote>
|
|
2630
|
+
${this.parser.parse(e)}</blockquote>
|
|
2631
|
+
`;
|
|
2632
|
+
}
|
|
2633
|
+
html({ text: e }) {
|
|
2634
|
+
return e;
|
|
2635
|
+
}
|
|
2636
|
+
def(e) {
|
|
2637
|
+
return "";
|
|
2638
|
+
}
|
|
2639
|
+
heading({ tokens: e, depth: t }) {
|
|
2640
|
+
return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
2641
|
+
`;
|
|
2642
|
+
}
|
|
2643
|
+
hr(e) {
|
|
2644
|
+
return "<hr>\n";
|
|
2645
|
+
}
|
|
2646
|
+
list(e) {
|
|
2647
|
+
let t = e.ordered, n = e.start, r = "";
|
|
2648
|
+
for (let t = 0; t < e.items.length; t++) {
|
|
2649
|
+
let n = e.items[t];
|
|
2650
|
+
r += this.listitem(n);
|
|
2651
|
+
}
|
|
2652
|
+
let i = t ? "ol" : "ul", a = t && n !== 1 ? " start=\"" + n + "\"" : "";
|
|
2653
|
+
return "<" + i + a + ">\n" + r + "</" + i + ">\n";
|
|
2654
|
+
}
|
|
2655
|
+
listitem(e) {
|
|
2656
|
+
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
2657
|
+
`;
|
|
2658
|
+
}
|
|
2659
|
+
checkbox({ checked: e }) {
|
|
2660
|
+
return "<input " + (e ? "checked=\"\" " : "") + "disabled=\"\" type=\"checkbox\"> ";
|
|
2661
|
+
}
|
|
2662
|
+
paragraph({ tokens: e }) {
|
|
2663
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
2664
|
+
`;
|
|
2665
|
+
}
|
|
2666
|
+
table(e) {
|
|
2667
|
+
let t = "", n = "";
|
|
2668
|
+
for (let t = 0; t < e.header.length; t++) n += this.tablecell(e.header[t]);
|
|
2669
|
+
t += this.tablerow({ text: n });
|
|
2670
|
+
let r = "";
|
|
2671
|
+
for (let t = 0; t < e.rows.length; t++) {
|
|
2672
|
+
let i = e.rows[t];
|
|
2673
|
+
n = "";
|
|
2674
|
+
for (let e = 0; e < i.length; e++) n += this.tablecell(i[e]);
|
|
2675
|
+
r += this.tablerow({ text: n });
|
|
2676
|
+
}
|
|
2677
|
+
return r &&= `<tbody>${r}</tbody>`, "<table>\n<thead>\n" + t + "</thead>\n" + r + "</table>\n";
|
|
2678
|
+
}
|
|
2679
|
+
tablerow({ text: e }) {
|
|
2680
|
+
return `<tr>
|
|
2681
|
+
${e}</tr>
|
|
2682
|
+
`;
|
|
2683
|
+
}
|
|
2684
|
+
tablecell(e) {
|
|
2685
|
+
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
2686
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
2687
|
+
`;
|
|
2688
|
+
}
|
|
2689
|
+
strong({ tokens: e }) {
|
|
2690
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
2691
|
+
}
|
|
2692
|
+
em({ tokens: e }) {
|
|
2693
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
2694
|
+
}
|
|
2695
|
+
codespan({ text: e }) {
|
|
2696
|
+
return `<code>${W(e, !0)}</code>`;
|
|
2697
|
+
}
|
|
2698
|
+
br(e) {
|
|
2699
|
+
return "<br>";
|
|
2700
|
+
}
|
|
2701
|
+
del({ tokens: e }) {
|
|
2702
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
2703
|
+
}
|
|
2704
|
+
link({ href: e, title: t, text: n, tokens: r, autolink: i }) {
|
|
2705
|
+
let a = i ? W(n, !0) : this.parser.parseInline(r), o = ti(e);
|
|
2706
|
+
if (o === null) return a;
|
|
2707
|
+
e = W(o, i);
|
|
2708
|
+
let s = "<a href=\"" + e + "\"";
|
|
2709
|
+
return t && (s += " title=\"" + W(t) + "\""), s += ">" + a + "</a>", s;
|
|
2710
|
+
}
|
|
2711
|
+
image({ href: e, title: t, text: n, tokens: r }) {
|
|
2712
|
+
r && (n = this.parser.parseInline(r, this.parser.textRenderer));
|
|
2713
|
+
let i = ti(e);
|
|
2714
|
+
if (i === null) return W(n);
|
|
2715
|
+
e = i;
|
|
2716
|
+
let a = `<img src="${W(e)}" alt="${W(n)}"`;
|
|
2717
|
+
return t && (a += ` title="${W(t)}"`), a += ">", a;
|
|
2718
|
+
}
|
|
2719
|
+
text(e) {
|
|
2720
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : W(e.text);
|
|
2721
|
+
}
|
|
2722
|
+
}, li = class {
|
|
2723
|
+
strong({ text: e }) {
|
|
2724
|
+
return e;
|
|
2725
|
+
}
|
|
2726
|
+
em({ text: e }) {
|
|
2727
|
+
return e;
|
|
2728
|
+
}
|
|
2729
|
+
codespan({ text: e }) {
|
|
2730
|
+
return e;
|
|
2731
|
+
}
|
|
2732
|
+
del({ text: e }) {
|
|
2733
|
+
return e;
|
|
2734
|
+
}
|
|
2735
|
+
html({ text: e }) {
|
|
2736
|
+
return e;
|
|
2737
|
+
}
|
|
2738
|
+
text({ text: e }) {
|
|
2739
|
+
return e;
|
|
2740
|
+
}
|
|
2741
|
+
link({ text: e }) {
|
|
2742
|
+
return "" + e;
|
|
2743
|
+
}
|
|
2744
|
+
image({ text: e }) {
|
|
2745
|
+
return "" + e;
|
|
2746
|
+
}
|
|
2747
|
+
br() {
|
|
2748
|
+
return "";
|
|
2749
|
+
}
|
|
2750
|
+
checkbox({ raw: e }) {
|
|
2751
|
+
return e;
|
|
2752
|
+
}
|
|
2753
|
+
}, X = class e {
|
|
2754
|
+
options;
|
|
2755
|
+
renderer;
|
|
2756
|
+
textRenderer;
|
|
2757
|
+
constructor(e) {
|
|
2758
|
+
this.options = e || j, this.options.renderer = this.options.renderer || new Y(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new li();
|
|
2759
|
+
}
|
|
2760
|
+
static parse(t, n) {
|
|
2761
|
+
return new e(n).parse(t);
|
|
2762
|
+
}
|
|
2763
|
+
static parseInline(t, n) {
|
|
2764
|
+
return new e(n).parseInline(t);
|
|
2765
|
+
}
|
|
2766
|
+
parse(e) {
|
|
2767
|
+
this.renderer.parser = this;
|
|
2768
|
+
let t = "";
|
|
2769
|
+
for (let n = 0; n < e.length; n++) {
|
|
2770
|
+
let r = e[n];
|
|
2771
|
+
if (this.options.extensions?.renderers?.[r.type]) {
|
|
2772
|
+
let e = r, n = this.options.extensions.renderers[e.type].call({ parser: this }, e);
|
|
2773
|
+
if (n !== !1 || ![
|
|
2774
|
+
"space",
|
|
2775
|
+
"hr",
|
|
2776
|
+
"heading",
|
|
2777
|
+
"code",
|
|
2778
|
+
"table",
|
|
2779
|
+
"blockquote",
|
|
2780
|
+
"list",
|
|
2781
|
+
"checkbox",
|
|
2782
|
+
"html",
|
|
2783
|
+
"def",
|
|
2784
|
+
"paragraph",
|
|
2785
|
+
"text"
|
|
2786
|
+
].includes(e.type)) {
|
|
2787
|
+
t += n || "";
|
|
2788
|
+
continue;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
let i = r;
|
|
2792
|
+
switch (i.type) {
|
|
2793
|
+
case "space":
|
|
2794
|
+
t += this.renderer.space(i);
|
|
2795
|
+
break;
|
|
2796
|
+
case "hr":
|
|
2797
|
+
t += this.renderer.hr(i);
|
|
2798
|
+
break;
|
|
2799
|
+
case "heading":
|
|
2800
|
+
t += this.renderer.heading(i);
|
|
2801
|
+
break;
|
|
2802
|
+
case "code":
|
|
2803
|
+
t += this.renderer.code(i);
|
|
2804
|
+
break;
|
|
2805
|
+
case "table":
|
|
2806
|
+
t += this.renderer.table(i);
|
|
2807
|
+
break;
|
|
2808
|
+
case "blockquote":
|
|
2809
|
+
t += this.renderer.blockquote(i);
|
|
2810
|
+
break;
|
|
2811
|
+
case "list":
|
|
2812
|
+
t += this.renderer.list(i);
|
|
2813
|
+
break;
|
|
2814
|
+
case "checkbox":
|
|
2815
|
+
t += this.renderer.checkbox(i);
|
|
2816
|
+
break;
|
|
2817
|
+
case "html":
|
|
2818
|
+
t += this.renderer.html(i);
|
|
2819
|
+
break;
|
|
2820
|
+
case "def":
|
|
2821
|
+
t += this.renderer.def(i);
|
|
2822
|
+
break;
|
|
2823
|
+
case "paragraph":
|
|
2824
|
+
t += this.renderer.paragraph(i);
|
|
2825
|
+
break;
|
|
2826
|
+
case "text":
|
|
2827
|
+
t += this.renderer.text(i);
|
|
2828
|
+
break;
|
|
2829
|
+
default: {
|
|
2830
|
+
let e = "Token with \"" + i.type + "\" type was not found.";
|
|
2831
|
+
if (this.options.silent) return console.error(e), "";
|
|
2832
|
+
throw Error(e);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
return t;
|
|
2837
|
+
}
|
|
2838
|
+
parseInline(e, t = this.renderer) {
|
|
2839
|
+
this.renderer.parser = this;
|
|
2840
|
+
let n = "";
|
|
2841
|
+
for (let r = 0; r < e.length; r++) {
|
|
2842
|
+
let i = e[r];
|
|
2843
|
+
if (this.options.extensions?.renderers?.[i.type]) {
|
|
2844
|
+
let e = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
2845
|
+
if (e !== !1 || ![
|
|
2846
|
+
"escape",
|
|
2847
|
+
"html",
|
|
2848
|
+
"link",
|
|
2849
|
+
"image",
|
|
2850
|
+
"checkbox",
|
|
2851
|
+
"strong",
|
|
2852
|
+
"em",
|
|
2853
|
+
"codespan",
|
|
2854
|
+
"br",
|
|
2855
|
+
"del",
|
|
2856
|
+
"text"
|
|
2857
|
+
].includes(i.type)) {
|
|
2858
|
+
n += e || "";
|
|
2859
|
+
continue;
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
let a = i;
|
|
2863
|
+
switch (a.type) {
|
|
2864
|
+
case "escape":
|
|
2865
|
+
n += t.text(a);
|
|
2866
|
+
break;
|
|
2867
|
+
case "html":
|
|
2868
|
+
n += t.html(a);
|
|
2869
|
+
break;
|
|
2870
|
+
case "link":
|
|
2871
|
+
n += t.link(a);
|
|
2872
|
+
break;
|
|
2873
|
+
case "image":
|
|
2874
|
+
n += t.image(a);
|
|
2875
|
+
break;
|
|
2876
|
+
case "checkbox":
|
|
2877
|
+
n += t.checkbox(a);
|
|
2878
|
+
break;
|
|
2879
|
+
case "strong":
|
|
2880
|
+
n += t.strong(a);
|
|
2881
|
+
break;
|
|
2882
|
+
case "em":
|
|
2883
|
+
n += t.em(a);
|
|
2884
|
+
break;
|
|
2885
|
+
case "codespan":
|
|
2886
|
+
n += t.codespan(a);
|
|
2887
|
+
break;
|
|
2888
|
+
case "br":
|
|
2889
|
+
n += t.br(a);
|
|
2890
|
+
break;
|
|
2891
|
+
case "del":
|
|
2892
|
+
n += t.del(a);
|
|
2893
|
+
break;
|
|
2894
|
+
case "text":
|
|
2895
|
+
n += t.text(a);
|
|
2896
|
+
break;
|
|
2897
|
+
default: {
|
|
2898
|
+
let e = "Token with \"" + a.type + "\" type was not found.";
|
|
2899
|
+
if (this.options.silent) return console.error(e), "";
|
|
2900
|
+
throw Error(e);
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
return n;
|
|
2905
|
+
}
|
|
2906
|
+
}, Z = class {
|
|
2907
|
+
options;
|
|
2908
|
+
block;
|
|
2909
|
+
constructor(e) {
|
|
2910
|
+
this.options = e || j;
|
|
2911
|
+
}
|
|
2912
|
+
static passThroughHooks = /* @__PURE__ */ new Set([
|
|
2913
|
+
"preprocess",
|
|
2914
|
+
"postprocess",
|
|
2915
|
+
"processAllTokens",
|
|
2916
|
+
"emStrongMask"
|
|
2917
|
+
]);
|
|
2918
|
+
static passThroughHooksRespectAsync = /* @__PURE__ */ new Set([
|
|
2919
|
+
"preprocess",
|
|
2920
|
+
"postprocess",
|
|
2921
|
+
"processAllTokens"
|
|
2922
|
+
]);
|
|
2923
|
+
preprocess(e) {
|
|
2924
|
+
return e;
|
|
2925
|
+
}
|
|
2926
|
+
postprocess(e) {
|
|
2927
|
+
return e;
|
|
2928
|
+
}
|
|
2929
|
+
processAllTokens(e) {
|
|
2930
|
+
return e;
|
|
2931
|
+
}
|
|
2932
|
+
emStrongMask(e) {
|
|
2933
|
+
return e;
|
|
2934
|
+
}
|
|
2935
|
+
provideLexer(e = this.block) {
|
|
2936
|
+
return e ? J.lex : J.lexInline;
|
|
2937
|
+
}
|
|
2938
|
+
provideParser(e = this.block) {
|
|
2939
|
+
return e ? X.parse : X.parseInline;
|
|
2940
|
+
}
|
|
2941
|
+
}, ui = class {
|
|
2942
|
+
defaults = Hn();
|
|
2943
|
+
options = this.setOptions;
|
|
2944
|
+
parse = this.parseMarkdown(!0);
|
|
2945
|
+
parseInline = this.parseMarkdown(!1);
|
|
2946
|
+
Parser = X;
|
|
2947
|
+
Renderer = Y;
|
|
2948
|
+
TextRenderer = li;
|
|
2949
|
+
Lexer = J;
|
|
2950
|
+
Tokenizer = q;
|
|
2951
|
+
Hooks = Z;
|
|
2952
|
+
constructor(...e) {
|
|
2953
|
+
this.use(...e);
|
|
2954
|
+
}
|
|
2955
|
+
walkTokens(e, t) {
|
|
2956
|
+
let n = [];
|
|
2957
|
+
for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
|
|
2958
|
+
case "table": {
|
|
2959
|
+
let e = r;
|
|
2960
|
+
for (let r of e.header) n = n.concat(this.walkTokens(r.tokens, t));
|
|
2961
|
+
for (let r of e.rows) for (let e of r) n = n.concat(this.walkTokens(e.tokens, t));
|
|
2962
|
+
break;
|
|
2963
|
+
}
|
|
2964
|
+
case "list": {
|
|
2965
|
+
let e = r;
|
|
2966
|
+
n = n.concat(this.walkTokens(e.items, t));
|
|
2967
|
+
break;
|
|
2968
|
+
}
|
|
2969
|
+
default: {
|
|
2970
|
+
let e = r;
|
|
2971
|
+
this.defaults.extensions?.childTokens?.[e.type] ? this.defaults.extensions.childTokens[e.type].forEach((r) => {
|
|
2972
|
+
let i = e[r].flat(1 / 0);
|
|
2973
|
+
n = n.concat(this.walkTokens(i, t));
|
|
2974
|
+
}) : e.tokens && (n = n.concat(this.walkTokens(e.tokens, t)));
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
return n;
|
|
2978
|
+
}
|
|
2979
|
+
use(...e) {
|
|
2980
|
+
let t = this.defaults.extensions || {
|
|
2981
|
+
renderers: {},
|
|
2982
|
+
childTokens: {}
|
|
2983
|
+
};
|
|
2984
|
+
return e.forEach((e) => {
|
|
2985
|
+
let n = { ...e };
|
|
2986
|
+
if (n.async = this.defaults.async || n.async || !1, e.extensions && (e.extensions.forEach((e) => {
|
|
2987
|
+
if (!e.name) throw Error("extension name required");
|
|
2988
|
+
if ("renderer" in e) {
|
|
2989
|
+
let n = t.renderers[e.name];
|
|
2990
|
+
n ? t.renderers[e.name] = function(...t) {
|
|
2991
|
+
let r = e.renderer.apply(this, t);
|
|
2992
|
+
return r === !1 && (r = n.apply(this, t)), r;
|
|
2993
|
+
} : t.renderers[e.name] = e.renderer;
|
|
2994
|
+
}
|
|
2995
|
+
if ("tokenizer" in e) {
|
|
2996
|
+
if (!e.level || e.level !== "block" && e.level !== "inline") throw Error("extension level must be 'block' or 'inline'");
|
|
2997
|
+
let n = t[e.level];
|
|
2998
|
+
n ? n.unshift(e.tokenizer) : t[e.level] = [e.tokenizer], e.start && (e.level === "block" ? t.startBlock ? t.startBlock.push(e.start) : t.startBlock = [e.start] : e.level === "inline" && (t.startInline ? t.startInline.push(e.start) : t.startInline = [e.start]));
|
|
2999
|
+
}
|
|
3000
|
+
"childTokens" in e && e.childTokens && (t.childTokens[e.name] = e.childTokens);
|
|
3001
|
+
}), n.extensions = t), e.renderer) {
|
|
3002
|
+
let t = this.defaults.renderer || new Y(this.defaults);
|
|
3003
|
+
for (let n in e.renderer) {
|
|
3004
|
+
if (!(n in t)) throw Error(`renderer '${n}' does not exist`);
|
|
3005
|
+
if (["options", "parser"].includes(n)) continue;
|
|
3006
|
+
let r = n, i = e.renderer[r], a = t[r];
|
|
3007
|
+
t[r] = (...e) => {
|
|
3008
|
+
let n = i.apply(t, e);
|
|
3009
|
+
return n === !1 && (n = a.apply(t, e)), n || "";
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
n.renderer = t;
|
|
3013
|
+
}
|
|
3014
|
+
if (e.tokenizer) {
|
|
3015
|
+
let t = this.defaults.tokenizer || new q(this.defaults);
|
|
3016
|
+
for (let n in e.tokenizer) {
|
|
3017
|
+
if (!(n in t)) throw Error(`tokenizer '${n}' does not exist`);
|
|
3018
|
+
if ([
|
|
3019
|
+
"options",
|
|
3020
|
+
"rules",
|
|
3021
|
+
"lexer"
|
|
3022
|
+
].includes(n)) continue;
|
|
3023
|
+
let r = n, i = e.tokenizer[r], a = t[r];
|
|
3024
|
+
t[r] = (...e) => {
|
|
3025
|
+
let n = i.apply(t, e);
|
|
3026
|
+
return n === !1 && (n = a.apply(t, e)), n;
|
|
3027
|
+
};
|
|
3028
|
+
}
|
|
3029
|
+
n.tokenizer = t;
|
|
3030
|
+
}
|
|
3031
|
+
if (e.hooks) {
|
|
3032
|
+
let t = this.defaults.hooks || new Z();
|
|
3033
|
+
for (let n in e.hooks) {
|
|
3034
|
+
if (!(n in t)) throw Error(`hook '${n}' does not exist`);
|
|
3035
|
+
if (["options", "block"].includes(n)) continue;
|
|
3036
|
+
let r = n, i = e.hooks[r], a = t[r];
|
|
3037
|
+
t[r] = Z.passThroughHooks.has(n) ? (e) => {
|
|
3038
|
+
if (this.defaults.async && Z.passThroughHooksRespectAsync.has(n)) return (async () => {
|
|
3039
|
+
let n = await i.call(t, e);
|
|
3040
|
+
return a.call(t, n);
|
|
3041
|
+
})();
|
|
3042
|
+
let r = i.call(t, e);
|
|
3043
|
+
return a.call(t, r);
|
|
3044
|
+
} : (...e) => {
|
|
3045
|
+
if (this.defaults.async) return (async () => {
|
|
3046
|
+
let n = await i.apply(t, e);
|
|
3047
|
+
return n === !1 && (n = await a.apply(t, e)), n;
|
|
3048
|
+
})();
|
|
3049
|
+
let n = i.apply(t, e);
|
|
3050
|
+
return n === !1 && (n = a.apply(t, e)), n;
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
n.hooks = t;
|
|
3054
|
+
}
|
|
3055
|
+
if (e.walkTokens) {
|
|
3056
|
+
let t = this.defaults.walkTokens, r = e.walkTokens;
|
|
3057
|
+
n.walkTokens = function(e) {
|
|
3058
|
+
let n = [];
|
|
3059
|
+
return n.push(r.call(this, e)), t && (n = n.concat(t.call(this, e))), n;
|
|
3060
|
+
};
|
|
3061
|
+
}
|
|
3062
|
+
this.defaults = {
|
|
3063
|
+
...this.defaults,
|
|
3064
|
+
...n
|
|
3065
|
+
};
|
|
3066
|
+
}), this;
|
|
3067
|
+
}
|
|
3068
|
+
setOptions(e) {
|
|
3069
|
+
return this.defaults = {
|
|
3070
|
+
...this.defaults,
|
|
3071
|
+
...e
|
|
3072
|
+
}, this;
|
|
3073
|
+
}
|
|
3074
|
+
lexer(e, t) {
|
|
3075
|
+
return J.lex(e, t ?? this.defaults);
|
|
3076
|
+
}
|
|
3077
|
+
parser(e, t) {
|
|
3078
|
+
return X.parse(e, t ?? this.defaults);
|
|
3079
|
+
}
|
|
3080
|
+
parseMarkdown(e) {
|
|
3081
|
+
return (t, n) => {
|
|
3082
|
+
let r = { ...n }, i = {
|
|
3083
|
+
...this.defaults,
|
|
3084
|
+
...r
|
|
3085
|
+
}, a = this.onError(!!i.silent, !!i.async);
|
|
3086
|
+
if (this.defaults.async === !0 && r.async === !1) return a(/* @__PURE__ */ Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
3087
|
+
if (typeof t > "u" || t === null) return a(/* @__PURE__ */ Error("marked(): input parameter is undefined or null"));
|
|
3088
|
+
if (typeof t != "string") return a(/* @__PURE__ */ Error("marked(): input parameter is of type " + Object.prototype.toString.call(t) + ", string expected"));
|
|
3089
|
+
if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async) return (async () => {
|
|
3090
|
+
let n = i.hooks ? await i.hooks.preprocess(t) : t, r = await (i.hooks ? await i.hooks.provideLexer(e) : e ? J.lex : J.lexInline)(n, i), a = i.hooks ? await i.hooks.processAllTokens(r) : r;
|
|
3091
|
+
i.walkTokens && await Promise.all(this.walkTokens(a, i.walkTokens));
|
|
3092
|
+
let o = await (i.hooks ? await i.hooks.provideParser(e) : e ? X.parse : X.parseInline)(a, i);
|
|
3093
|
+
return i.hooks ? await i.hooks.postprocess(o) : o;
|
|
3094
|
+
})().catch(a);
|
|
3095
|
+
try {
|
|
3096
|
+
i.hooks && (t = i.hooks.preprocess(t));
|
|
3097
|
+
let n = (i.hooks ? i.hooks.provideLexer(e) : e ? J.lex : J.lexInline)(t, i);
|
|
3098
|
+
i.hooks && (n = i.hooks.processAllTokens(n)), i.walkTokens && this.walkTokens(n, i.walkTokens);
|
|
3099
|
+
let r = (i.hooks ? i.hooks.provideParser(e) : e ? X.parse : X.parseInline)(n, i);
|
|
3100
|
+
return i.hooks && (r = i.hooks.postprocess(r)), r;
|
|
3101
|
+
} catch (e) {
|
|
3102
|
+
return a(e);
|
|
3103
|
+
}
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
onError(e, t) {
|
|
3107
|
+
return (n) => {
|
|
3108
|
+
if (n.message += "\nPlease report this to https://github.com/markedjs/marked.", e) {
|
|
3109
|
+
let e = "<p>An error occurred:</p><pre>" + W(n.message + "", !0) + "</pre>";
|
|
3110
|
+
return t ? Promise.resolve(e) : e;
|
|
3111
|
+
}
|
|
3112
|
+
if (t) return Promise.reject(n);
|
|
3113
|
+
throw n;
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
}, Q = new ui();
|
|
3117
|
+
function $(e, t) {
|
|
3118
|
+
return Q.parse(e, t);
|
|
3119
|
+
}
|
|
3120
|
+
$.options = $.setOptions = function(e) {
|
|
3121
|
+
return Q.setOptions(e), $.defaults = Q.defaults, Un($.defaults), $;
|
|
3122
|
+
}, $.getDefaults = Hn, $.defaults = j;
|
|
3123
|
+
function di(...e) {
|
|
3124
|
+
return Q.use(...e), $.defaults = Q.defaults, Un($.defaults), $;
|
|
3125
|
+
}
|
|
3126
|
+
$.use = di, $.walkTokens = function(e, t) {
|
|
3127
|
+
return Q.walkTokens(e, t);
|
|
3128
|
+
}, $.parseInline = Q.parseInline, $.Parser = X, $.parser = X.parse, $.Renderer = Y, $.TextRenderer = li, $.Lexer = J, $.lexer = J.lex, $.Tokenizer = q, $.Hooks = Z, $.parse = $, $.options, $.setOptions, $.walkTokens, $.parseInline, X.parse, J.lex;
|
|
3129
|
+
//#endregion
|
|
3130
|
+
//#region src/utils/html.ts
|
|
3131
|
+
function fi(e) {
|
|
3132
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3133
|
+
}
|
|
3134
|
+
function pi() {
|
|
3135
|
+
return globalThis.katex ?? null;
|
|
3136
|
+
}
|
|
3137
|
+
function mi(e, t, n) {
|
|
3138
|
+
let r = pi();
|
|
3139
|
+
return r ? r.renderToString(e, {
|
|
3140
|
+
displayMode: t,
|
|
3141
|
+
throwOnError: !1
|
|
3142
|
+
}) : fi(n);
|
|
3143
|
+
}
|
|
3144
|
+
var hi = { extensions: [{
|
|
3145
|
+
name: "blockMath",
|
|
3146
|
+
level: "block",
|
|
3147
|
+
start(e) {
|
|
3148
|
+
return e.indexOf("$$");
|
|
3149
|
+
},
|
|
3150
|
+
tokenizer(e) {
|
|
3151
|
+
let t = /^\$\$([\s\S]+?)\$\$/.exec(e);
|
|
3152
|
+
if (t && t[1]) return {
|
|
3153
|
+
type: "blockMath",
|
|
3154
|
+
raw: t[0],
|
|
3155
|
+
text: t[1].trim()
|
|
3156
|
+
};
|
|
3157
|
+
},
|
|
3158
|
+
renderer(e) {
|
|
3159
|
+
let t = e;
|
|
3160
|
+
return mi(t.text, !0, t.raw);
|
|
3161
|
+
}
|
|
3162
|
+
}, {
|
|
3163
|
+
name: "inlineMath",
|
|
3164
|
+
level: "inline",
|
|
3165
|
+
start(e) {
|
|
3166
|
+
return e.indexOf("$");
|
|
3167
|
+
},
|
|
3168
|
+
tokenizer(e) {
|
|
3169
|
+
let t = /^\$(?! )((?:[^$\n]|\\\$)*?[^ $\n])\$/.exec(e);
|
|
3170
|
+
if (t && t[1]) return {
|
|
3171
|
+
type: "inlineMath",
|
|
3172
|
+
raw: t[0],
|
|
3173
|
+
text: t[1]
|
|
3174
|
+
};
|
|
3175
|
+
},
|
|
3176
|
+
renderer(e) {
|
|
3177
|
+
let t = e;
|
|
3178
|
+
return mi(t.text, !1, t.raw);
|
|
3179
|
+
}
|
|
3180
|
+
}] };
|
|
3181
|
+
//#endregion
|
|
3182
|
+
//#region src/markdown/sanitize.ts
|
|
3183
|
+
function gi(e) {
|
|
3184
|
+
return e.replace(/<a\b(?![^>]*\btarget=)([^>]*)>/gi, "<a target=\"_blank\" rel=\"noopener noreferrer\"$1>");
|
|
3185
|
+
}
|
|
3186
|
+
//#endregion
|
|
3187
|
+
//#region src/markdown/parse.ts
|
|
3188
|
+
function _i(e) {
|
|
3189
|
+
return {
|
|
3190
|
+
singleLineBreaks: e.renderingConfig?.singleLineBreaks,
|
|
3191
|
+
previewRender: e.previewRender
|
|
3192
|
+
};
|
|
3193
|
+
}
|
|
3194
|
+
function vi(e, t = {}) {
|
|
3195
|
+
if (t.previewRender) return t.previewRender(e);
|
|
3196
|
+
let n = new ui({
|
|
3197
|
+
gfm: !0,
|
|
3198
|
+
breaks: t.singleLineBreaks ?? !0
|
|
3199
|
+
});
|
|
3200
|
+
return n.use(hi), gi(n.parse(e, { async: !1 }));
|
|
3201
|
+
}
|
|
3202
|
+
//#endregion
|
|
3203
|
+
//#region src/features/storage.ts
|
|
3204
|
+
var yi = "supamde:";
|
|
3205
|
+
function bi(e = yi) {
|
|
3206
|
+
let t = (t) => `${e}${t}`;
|
|
3207
|
+
return {
|
|
3208
|
+
load: (e) => localStorage.getItem(t(e)),
|
|
3209
|
+
save: (e, n) => {
|
|
3210
|
+
localStorage.setItem(t(e), n);
|
|
3211
|
+
},
|
|
3212
|
+
clear: (e) => {
|
|
3213
|
+
localStorage.removeItem(t(e));
|
|
3214
|
+
}
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3217
|
+
async function xi(e) {
|
|
3218
|
+
let t = "__supamde_probe__";
|
|
3219
|
+
try {
|
|
3220
|
+
await e.save(t, "1");
|
|
3221
|
+
let n = await e.load(t);
|
|
3222
|
+
return await e.clear(t), n === "1";
|
|
3223
|
+
} catch {
|
|
3224
|
+
return !1;
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
function Si(e, t) {
|
|
3228
|
+
let n = e.enabled ?? !1, r = e.delay ?? 1e3, i = e.storage ?? bi(), a = e.key, o = t.getValue(), s = !1, c = null, l = !1, u = (e) => {
|
|
3229
|
+
l || (l = !0, console.warn(`SupaMDE: ${e}`));
|
|
3230
|
+
}, d = () => {
|
|
3231
|
+
c !== null && (clearTimeout(c), c = null);
|
|
3232
|
+
}, f = async () => {
|
|
3233
|
+
if (!s) return;
|
|
3234
|
+
let e = t.getValue();
|
|
3235
|
+
try {
|
|
3236
|
+
e.trim() === "" ? await i.clear(a) : await i.save(a, e), t.onSaved(/* @__PURE__ */ new Date());
|
|
3237
|
+
} catch {
|
|
3238
|
+
s = !1, d(), u("autosave storage is not writable — autosave is disabled.");
|
|
3239
|
+
}
|
|
3240
|
+
};
|
|
3241
|
+
return {
|
|
3242
|
+
start: async () => {
|
|
3243
|
+
if (!n) return;
|
|
3244
|
+
if (!a) {
|
|
3245
|
+
u("autosave.key is required — autosave stays off.");
|
|
3246
|
+
return;
|
|
3247
|
+
}
|
|
3248
|
+
if (!await xi(i)) {
|
|
3249
|
+
u("autosave storage is not available — autosave is disabled.");
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
s = !0;
|
|
3253
|
+
let r;
|
|
3254
|
+
try {
|
|
3255
|
+
r = await i.load(a);
|
|
3256
|
+
} catch {
|
|
3257
|
+
s = !1, u("autosave storage is not readable — autosave is disabled.");
|
|
3258
|
+
return;
|
|
3259
|
+
}
|
|
3260
|
+
let c = t.getValue();
|
|
3261
|
+
c === o && r && r.trim() !== "" && r !== c && (t.setValue(r), e.onRestore?.(r));
|
|
3262
|
+
},
|
|
3263
|
+
schedule: () => {
|
|
3264
|
+
s && (d(), c = setTimeout(() => {
|
|
3265
|
+
c = null, f();
|
|
3266
|
+
}, r));
|
|
3267
|
+
},
|
|
3268
|
+
clear: async () => {
|
|
3269
|
+
d();
|
|
3270
|
+
try {
|
|
3271
|
+
await i.clear(a);
|
|
3272
|
+
} catch {
|
|
3273
|
+
u("autosave entry could not be deleted.");
|
|
3274
|
+
}
|
|
3275
|
+
},
|
|
3276
|
+
stop: d,
|
|
3277
|
+
isActive: () => s
|
|
3278
|
+
};
|
|
3279
|
+
}
|
|
3280
|
+
//#endregion
|
|
3281
|
+
//#region src/features/upload-placeholder.ts
|
|
3282
|
+
var Ci = l.define(), wi = l.define(), Ti = u.define({
|
|
3283
|
+
create() {
|
|
3284
|
+
return /* @__PURE__ */ new Map();
|
|
3285
|
+
},
|
|
3286
|
+
update(e, t) {
|
|
3287
|
+
let n = e;
|
|
3288
|
+
if (t.docChanged && n.size > 0) {
|
|
3289
|
+
let e = /* @__PURE__ */ new Map();
|
|
3290
|
+
for (let [r, i] of n) {
|
|
3291
|
+
let n = t.changes.mapPos(i.from, 1), a = t.changes.mapPos(i.to, -1);
|
|
3292
|
+
a > n && e.set(r, {
|
|
3293
|
+
from: n,
|
|
3294
|
+
to: a
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
n = e;
|
|
3298
|
+
}
|
|
3299
|
+
for (let e of t.effects) if (e.is(Ci)) {
|
|
3300
|
+
let t = new Map(n);
|
|
3301
|
+
t.set(e.value.id, {
|
|
3302
|
+
from: e.value.from,
|
|
3303
|
+
to: e.value.to
|
|
3304
|
+
}), n = t;
|
|
3305
|
+
} else if (e.is(wi) && n.has(e.value)) {
|
|
3306
|
+
let t = new Map(n);
|
|
3307
|
+
t.delete(e.value), n = t;
|
|
3308
|
+
}
|
|
3309
|
+
return n;
|
|
3310
|
+
}
|
|
3311
|
+
});
|
|
3312
|
+
function Ei(e, t) {
|
|
3313
|
+
return e.field(Ti, !1)?.get(t) ?? null;
|
|
3314
|
+
}
|
|
3315
|
+
function Di() {
|
|
3316
|
+
let e = 0;
|
|
3317
|
+
return () => (e += 1, e);
|
|
3318
|
+
}
|
|
3319
|
+
var Oi = [
|
|
3320
|
+
"image/png",
|
|
3321
|
+
"image/jpeg",
|
|
3322
|
+
"image/gif",
|
|
3323
|
+
"image/webp",
|
|
3324
|
+
"image/avif",
|
|
3325
|
+
"image/svg+xml"
|
|
3326
|
+
], ki = 2e3, Ai = 6e3, ji = {
|
|
3327
|
+
"too-large": "upload.errorTooLarge",
|
|
3328
|
+
"type-not-allowed": "upload.errorType",
|
|
3329
|
+
"upload-failed": "upload.errorFailed"
|
|
3330
|
+
};
|
|
3331
|
+
function Mi(e, t) {
|
|
3332
|
+
return `![${e.replace(/([[\]\\])/g, "\\$1")}](${/[\s()<>]/.test(t) ? `<${t.replace(/([<>\\])/g, "\\$1")}>` : t})`;
|
|
3333
|
+
}
|
|
3334
|
+
function Ni(e, t) {
|
|
3335
|
+
return e.size > t.maxSize ? "too-large" : t.accept.includes(e.type) ? null : "type-not-allowed";
|
|
3336
|
+
}
|
|
3337
|
+
function Pi(e, t, n, r = D()) {
|
|
3338
|
+
let i = t.enabled ?? !1, a = t.maxSize ?? 2097152, o = t.accept ?? Oi, s = Di(), c = 0, l = null, u = (e, t) => {
|
|
3339
|
+
n.setStatus(e), l !== null && (clearTimeout(l), l = null), t !== void 0 && (l = setTimeout(() => {
|
|
3340
|
+
l = null, c === 0 && n.setStatus(r.t("upload.statusInit"));
|
|
3341
|
+
}, t));
|
|
3342
|
+
}, d = (e, n, i) => {
|
|
3343
|
+
let o = {
|
|
3344
|
+
name: n.name,
|
|
3345
|
+
maxSize: Ht(a)
|
|
3346
|
+
};
|
|
3347
|
+
u(r.t(ji[e], o), Ai), t.onError?.({
|
|
3348
|
+
kind: e,
|
|
3349
|
+
file: n,
|
|
3350
|
+
cause: i
|
|
3351
|
+
});
|
|
3352
|
+
}, f = (n) => {
|
|
3353
|
+
let i = Ni(n, {
|
|
3354
|
+
maxSize: a,
|
|
3355
|
+
accept: o
|
|
3356
|
+
});
|
|
3357
|
+
if (i) {
|
|
3358
|
+
d(i, n);
|
|
3359
|
+
return;
|
|
3360
|
+
}
|
|
3361
|
+
let l = s(), f = r.t("upload.placeholder", { name: n.name }), p = e.state.selection.main;
|
|
3362
|
+
e.dispatch({
|
|
3363
|
+
changes: {
|
|
3364
|
+
from: p.from,
|
|
3365
|
+
to: p.to,
|
|
3366
|
+
insert: f
|
|
3367
|
+
},
|
|
3368
|
+
effects: Ci.of({
|
|
3369
|
+
id: l,
|
|
3370
|
+
from: p.from,
|
|
3371
|
+
to: p.from + f.length
|
|
3372
|
+
}),
|
|
3373
|
+
selection: { anchor: p.from + f.length }
|
|
3374
|
+
}), c += 1, u(r.t("upload.statusUploading", { name: n.name })), Promise.resolve().then(() => t.upload(n)).then((t) => {
|
|
3375
|
+
--c;
|
|
3376
|
+
let i = Ei(e.state, l);
|
|
3377
|
+
i && (e.dispatch({
|
|
3378
|
+
changes: {
|
|
3379
|
+
from: i.from,
|
|
3380
|
+
to: i.to,
|
|
3381
|
+
insert: Mi(n.name, t)
|
|
3382
|
+
},
|
|
3383
|
+
effects: wi.of(l)
|
|
3384
|
+
}), u(r.t("upload.statusDone", { name: n.name }), ki));
|
|
3385
|
+
}, (t) => {
|
|
3386
|
+
--c;
|
|
3387
|
+
let r = Ei(e.state, l);
|
|
3388
|
+
r && e.dispatch({
|
|
3389
|
+
changes: {
|
|
3390
|
+
from: r.from,
|
|
3391
|
+
to: r.to,
|
|
3392
|
+
insert: ""
|
|
3393
|
+
},
|
|
3394
|
+
effects: wi.of(l)
|
|
3395
|
+
}), d("upload-failed", n, t);
|
|
3396
|
+
});
|
|
3397
|
+
};
|
|
3398
|
+
return {
|
|
3399
|
+
uploadFiles: (e) => {
|
|
3400
|
+
if (i) for (let t of Array.from(e)) f(t);
|
|
3401
|
+
},
|
|
3402
|
+
accept: () => o,
|
|
3403
|
+
isActive: () => i,
|
|
3404
|
+
destroy: () => {
|
|
3405
|
+
l !== null && (clearTimeout(l), l = null);
|
|
3406
|
+
}
|
|
3407
|
+
};
|
|
3408
|
+
}
|
|
3409
|
+
//#endregion
|
|
3410
|
+
//#region src/features/upload-dom.ts
|
|
3411
|
+
function Fi(e) {
|
|
3412
|
+
if (!e) return [];
|
|
3413
|
+
let t = e.files;
|
|
3414
|
+
return !t || t.length === 0 ? [] : Array.from(t).filter((e) => e.type.startsWith("image/"));
|
|
3415
|
+
}
|
|
3416
|
+
function Ii(e) {
|
|
3417
|
+
return t.domEventHandlers({
|
|
3418
|
+
drop(t) {
|
|
3419
|
+
let n = Fi(t.dataTransfer);
|
|
3420
|
+
return n.length !== 0 && (t.preventDefault(), e(n), !0);
|
|
3421
|
+
},
|
|
3422
|
+
paste(t) {
|
|
3423
|
+
let n = Fi(t.clipboardData);
|
|
3424
|
+
return n.length !== 0 && (t.preventDefault(), e(n), !0);
|
|
3425
|
+
}
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3428
|
+
function Li(e, t) {
|
|
3429
|
+
let n = document.createElement("input");
|
|
3430
|
+
n.type = "file", n.multiple = !0, n.accept = e.join(","), n.style.display = "none";
|
|
3431
|
+
let r = () => {
|
|
3432
|
+
n.remove();
|
|
3433
|
+
};
|
|
3434
|
+
n.addEventListener("change", () => {
|
|
3435
|
+
let e = n.files ? Array.from(n.files) : [];
|
|
3436
|
+
r(), e.length > 0 && t(e);
|
|
3437
|
+
}), n.addEventListener("cancel", r), document.body.appendChild(n), n.click();
|
|
3438
|
+
}
|
|
3439
|
+
//#endregion
|
|
3440
|
+
//#region src/i18n/de.ts
|
|
3441
|
+
var Ri = {
|
|
3442
|
+
code: "de",
|
|
3443
|
+
texts: {
|
|
3444
|
+
"toolbar.bold": "Fett",
|
|
3445
|
+
"toolbar.italic": "Kursiv",
|
|
3446
|
+
"toolbar.strikethrough": "Durchgestrichen",
|
|
3447
|
+
"toolbar.code": "Inline-Code",
|
|
3448
|
+
"toolbar.heading-smaller": "Überschrift kleiner",
|
|
3449
|
+
"toolbar.heading-bigger": "Überschrift größer",
|
|
3450
|
+
"toolbar.heading-1": "Überschrift 1",
|
|
3451
|
+
"toolbar.heading-2": "Überschrift 2",
|
|
3452
|
+
"toolbar.heading-3": "Überschrift 3",
|
|
3453
|
+
"toolbar.heading-4": "Überschrift 4",
|
|
3454
|
+
"toolbar.heading-5": "Überschrift 5",
|
|
3455
|
+
"toolbar.heading-6": "Überschrift 6",
|
|
3456
|
+
"toolbar.quote": "Blockzitat",
|
|
3457
|
+
"toolbar.code-block": "Codeblock",
|
|
3458
|
+
"toolbar.horizontal-rule": "Trennlinie",
|
|
3459
|
+
"toolbar.clean-block": "Formatierung entfernen",
|
|
3460
|
+
"toolbar.unordered-list": "Liste",
|
|
3461
|
+
"toolbar.ordered-list": "Nummerierte Liste",
|
|
3462
|
+
"toolbar.check-list": "Checkliste",
|
|
3463
|
+
"toolbar.link": "Link",
|
|
3464
|
+
"toolbar.image": "Bild",
|
|
3465
|
+
"toolbar.table": "Tabelle",
|
|
3466
|
+
"toolbar.undo": "Rückgängig",
|
|
3467
|
+
"toolbar.redo": "Wiederholen",
|
|
3468
|
+
"toolbar.side-by-side": "Nebeneinander-Vorschau",
|
|
3469
|
+
"toolbar.fullscreen": "Vollbild",
|
|
3470
|
+
"toolbar.preview-fullscreen": "Vorschau im Vollbild",
|
|
3471
|
+
"toolbar.editor-mode": "Live-Vorschau",
|
|
3472
|
+
"toolbar.upload-image": "Bild hochladen",
|
|
3473
|
+
"status.lines": {
|
|
3474
|
+
one: "{count} Zeile",
|
|
3475
|
+
other: "{count} Zeilen"
|
|
3476
|
+
},
|
|
3477
|
+
"status.words": {
|
|
3478
|
+
one: "{count} Wort",
|
|
3479
|
+
other: "{count} Wörter"
|
|
3480
|
+
},
|
|
3481
|
+
"status.autosaved": "Gespeichert: {time}",
|
|
3482
|
+
"upload.placeholder": "![Uploading {name}…]()",
|
|
3483
|
+
"upload.statusInit": "Bild hierher ziehen oder einfügen",
|
|
3484
|
+
"upload.statusUploading": "Lade {name} hoch…",
|
|
3485
|
+
"upload.statusDone": "{name} hochgeladen",
|
|
3486
|
+
"upload.errorTooLarge": "{name} ist zu groß (max. {maxSize}).",
|
|
3487
|
+
"upload.errorType": "{name} ist kein unterstütztes Bildformat.",
|
|
3488
|
+
"upload.errorFailed": "Upload von {name} fehlgeschlagen.",
|
|
3489
|
+
"prompt.linkUrl": "Link-URL:",
|
|
3490
|
+
"prompt.imageUrl": "Bild-URL:",
|
|
3491
|
+
"table.column": "Spalte {n}"
|
|
3492
|
+
}
|
|
3493
|
+
}, zi = class {
|
|
3494
|
+
static version = me;
|
|
3495
|
+
options;
|
|
3496
|
+
codemirror;
|
|
3497
|
+
handle;
|
|
3498
|
+
container;
|
|
3499
|
+
editorRow;
|
|
3500
|
+
toolbar;
|
|
3501
|
+
statusbar;
|
|
3502
|
+
preview;
|
|
3503
|
+
fullscreen;
|
|
3504
|
+
autosave;
|
|
3505
|
+
uploader = null;
|
|
3506
|
+
onViewShortcuts;
|
|
3507
|
+
renderOpts;
|
|
3508
|
+
editorMode;
|
|
3509
|
+
translator;
|
|
3510
|
+
constructor(e = {}) {
|
|
3511
|
+
this.options = e, e.injectStyles !== !1 && Vn(), this.translator = D(e.locale, e.texts);
|
|
3512
|
+
let t = { onUpdate: (e) => {
|
|
3513
|
+
this.toolbar?.update(e.state), this.statusbar?.update(e.state, {
|
|
3514
|
+
docChanged: e.docChanged,
|
|
3515
|
+
selectionSet: e.selectionSet
|
|
3516
|
+
}), this.preview?.update(e.state), e.docChanged && this.autosave.schedule();
|
|
3517
|
+
} }, n = e.uploadImage?.enabled === !0, r = n ? [Ti, Ii((e) => this.uploader?.uploadFiles(e))] : [];
|
|
3518
|
+
this.handle = ln(e, t, [O.of(this.translator), ...r]), this.codemirror = this.handle.view, this.editorMode = this.handle.resolved.editorMode;
|
|
3519
|
+
let i = !n && Array.isArray(e.toolbar) ? e.toolbar.filter((e) => e !== "upload-image") : e.toolbar;
|
|
3520
|
+
this.toolbar = Tn(this.codemirror, i, this, this.translator), this.statusbar = jn(e.status, this.translator), this.autosave = Si(e.autosave ?? {
|
|
3521
|
+
enabled: !1,
|
|
3522
|
+
key: ""
|
|
3523
|
+
}, {
|
|
3524
|
+
getValue: () => this.getValue(),
|
|
3525
|
+
setValue: (e) => this.setValue(e),
|
|
3526
|
+
onSaved: (e) => {
|
|
3527
|
+
this.statusbar?.setItem("autosave", this.translator.t("status.autosaved", { time: this.translator.formatTime(e) }));
|
|
3528
|
+
}
|
|
3529
|
+
}), n && e.uploadImage && (typeof e.uploadImage.upload == "function" ? (this.uploader = Pi(this.codemirror, e.uploadImage, { setStatus: (e) => this.statusbar?.setItem("upload-image", e) }, this.translator), !(Array.isArray(e.status) && e.status.includes("upload-image")) && !e.uploadImage.onError && console.warn("SupaMDE: uploadImage is enabled, but neither the status bar item 'upload-image' (status option) nor uploadImage.onError is set — upload progress and errors stay invisible."), this.statusbar?.setItem("upload-image", this.translator.t("upload.statusInit"))) : console.warn("SupaMDE: uploadImage.enabled is true, but uploadImage.upload is not a function — image upload stays off.")), this.renderOpts = _i(e), this.preview = Mn(this.codemirror, {
|
|
3530
|
+
render: (e) => vi(e, this.renderOpts),
|
|
3531
|
+
previewClass: e.previewClass,
|
|
3532
|
+
syncScroll: e.syncSideBySidePreviewScroll
|
|
3533
|
+
}), this.container = document.createElement("div"), this.container.className = "supamde-container";
|
|
3534
|
+
let a = this.codemirror.dom;
|
|
3535
|
+
a.parentNode?.insertBefore(this.container, a), this.toolbar && this.container.appendChild(this.toolbar.dom), this.editorRow = document.createElement("div"), this.editorRow.className = "supamde-editor-row", this.editorRow.appendChild(a), this.editorRow.appendChild(this.preview.dom), this.container.appendChild(this.editorRow), this.statusbar && this.container.appendChild(this.statusbar.dom), this.fullscreen = Pn(this.container, { onToggleFullScreen: (t) => {
|
|
3536
|
+
this.toolbar?.update(this.codemirror.state), e.onToggleFullScreen?.(t);
|
|
3537
|
+
} }), this.onViewShortcuts = (e) => {
|
|
3538
|
+
e.key === "F8" ? (e.preventDefault(), this.togglePreviewFullScreen()) : e.key === "F9" ? (e.preventDefault(), this.toggleSideBySide()) : e.key === "F10" ? (e.preventDefault(), this.toggleEditorMode()) : (e.key === "F11" || (e.metaKey || e.ctrlKey) && e.shiftKey && !e.altKey && (e.key === "F" || e.key === "f")) && (e.preventDefault(), this.toggleFullScreen());
|
|
3539
|
+
}, this.container.addEventListener("keydown", this.onViewShortcuts);
|
|
3540
|
+
let o = this.codemirror.state;
|
|
3541
|
+
this.toolbar?.update(o), this.statusbar?.update(o, {
|
|
3542
|
+
docChanged: !0,
|
|
3543
|
+
selectionSet: !0
|
|
3544
|
+
}), this.autosave.start();
|
|
3545
|
+
}
|
|
3546
|
+
value(e) {
|
|
3547
|
+
if (e === void 0) return this.getValue();
|
|
3548
|
+
this.setValue(e);
|
|
3549
|
+
}
|
|
3550
|
+
getValue() {
|
|
3551
|
+
return un(this.codemirror);
|
|
3552
|
+
}
|
|
3553
|
+
setValue(e) {
|
|
3554
|
+
dn(this.codemirror, e);
|
|
3555
|
+
}
|
|
3556
|
+
updateStatusBar(e, t) {
|
|
3557
|
+
this.statusbar?.setItem(e, t);
|
|
3558
|
+
}
|
|
3559
|
+
markdown(e) {
|
|
3560
|
+
return vi(e, this.renderOpts);
|
|
3561
|
+
}
|
|
3562
|
+
setSideBySide(e) {
|
|
3563
|
+
this.preview?.set(e), this.container.classList.toggle("supamde-sided", this.isSideBySideActive()), this.toolbar?.update(this.codemirror.state);
|
|
3564
|
+
}
|
|
3565
|
+
toggleSideBySide() {
|
|
3566
|
+
this.setSideBySide(!this.isSideBySideActive());
|
|
3567
|
+
}
|
|
3568
|
+
isSideBySideActive() {
|
|
3569
|
+
return this.preview?.isActive() ?? !1;
|
|
3570
|
+
}
|
|
3571
|
+
setFullScreen(e) {
|
|
3572
|
+
this.fullscreen.set(e), this.toolbar?.update(this.codemirror.state);
|
|
3573
|
+
}
|
|
3574
|
+
toggleFullScreen() {
|
|
3575
|
+
this.setFullScreen(!this.isFullscreenActive());
|
|
3576
|
+
}
|
|
3577
|
+
isFullscreenActive() {
|
|
3578
|
+
return this.fullscreen.isActive();
|
|
3579
|
+
}
|
|
3580
|
+
togglePreviewFullScreen() {
|
|
3581
|
+
let e = !this.isPreviewFullScreenActive();
|
|
3582
|
+
this.setSideBySide(e), this.setFullScreen(e);
|
|
3583
|
+
}
|
|
3584
|
+
isPreviewFullScreenActive() {
|
|
3585
|
+
return this.isSideBySideActive() && this.isFullscreenActive();
|
|
3586
|
+
}
|
|
3587
|
+
getEditorMode() {
|
|
3588
|
+
return this.editorMode;
|
|
3589
|
+
}
|
|
3590
|
+
setEditorMode(e) {
|
|
3591
|
+
e !== this.editorMode && (this.editorMode = e, this.codemirror.dispatch({ effects: Ee.reconfigure(De(e)) }), this.toolbar?.update(this.codemirror.state));
|
|
3592
|
+
}
|
|
3593
|
+
toggleEditorMode() {
|
|
3594
|
+
this.setEditorMode(this.editorMode === "live" ? "source" : "live");
|
|
3595
|
+
}
|
|
3596
|
+
async clearAutosavedValue() {
|
|
3597
|
+
await this.autosave.clear(), this.statusbar?.setItem("autosave", "");
|
|
3598
|
+
}
|
|
3599
|
+
isAutosaveActive() {
|
|
3600
|
+
return this.autosave.isActive();
|
|
3601
|
+
}
|
|
3602
|
+
uploadImages(e) {
|
|
3603
|
+
this.uploader?.uploadFiles(e);
|
|
3604
|
+
}
|
|
3605
|
+
openBrowseFileWindow() {
|
|
3606
|
+
this.uploader && Li(this.uploader.accept(), (e) => this.uploader?.uploadFiles(e));
|
|
3607
|
+
}
|
|
3608
|
+
toTextArea() {
|
|
3609
|
+
this.autosave.stop(), this.uploader?.destroy(), this.container.removeEventListener("keydown", this.onViewShortcuts), this.toolbar?.destroy(), this.statusbar?.destroy(), this.preview?.destroy(), this.fullscreen.destroy();
|
|
3610
|
+
let e = this.handle.toTextArea();
|
|
3611
|
+
return this.container.remove(), e;
|
|
3612
|
+
}
|
|
3613
|
+
};
|
|
3614
|
+
//#endregion
|
|
3615
|
+
export { zi as SupaMDE, zi as default, me as VERSION, Ri as de, T as en };
|
|
3616
|
+
|
|
3617
|
+
//# sourceMappingURL=supamde.mjs.map
|