@pinkpixel/marzipan 1.1.2 → 1.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/README.md +4 -5
- package/dist/index-CEbRSdyd.js +31 -0
- package/dist/index-CEbRSdyd.js.map +1 -0
- package/dist/index-xgEXHeDh.js +31 -0
- package/dist/index-xgEXHeDh.js.map +1 -0
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +710 -620
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts +8 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +63 -6
- package/dist/parser.js.map +1 -1
- package/dist/plugins/accentSwatchPlugin.d.ts.map +1 -1
- package/dist/plugins/accentSwatchPlugin.js +96 -80
- package/dist/plugins/accentSwatchPlugin.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +24 -27
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/tableGenerator.js +1 -1
- package/dist/plugins/tableGridPlugin.d.ts +1 -1
- package/dist/plugins/tableGridPlugin.d.ts.map +1 -1
- package/dist/plugins/tableGridPlugin.js +143 -42
- package/dist/plugins/tableGridPlugin.js.map +1 -1
- package/dist/plugins/tablePlugin.js +1 -1
- package/dist/plugins/utils/table.d.ts +12 -1
- package/dist/plugins/utils/table.d.ts.map +1 -1
- package/dist/plugins/utils/table.js +31 -6
- package/dist/plugins/utils/table.js.map +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +65 -1
- package/dist/styles.js.map +1 -1
- package/dist/table-CJHCBhPo.js +33 -0
- package/dist/table-CJHCBhPo.js.map +1 -0
- package/docs/index.md +2 -3
- package/docs/plugins.md +84 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
const I = class I {
|
|
1
|
+
import { i as st } from "./index-CEbRSdyd.js";
|
|
2
|
+
import { b as ct, r as pt } from "./table-CJHCBhPo.js";
|
|
3
|
+
import { imagePickerPlugin as mt } from "./plugins/imagePicker.js";
|
|
4
|
+
import { imageManagerPlugin as ut, imageManagerStyles as ft } from "./plugins/imageManagerPlugin.js";
|
|
5
|
+
import { imagePickerPlugin as bt } from "./plugins/imagePickerPlugin.js";
|
|
6
|
+
import { mermaidExternalPlugin as wt } from "./plugins/mermaidExternal.js";
|
|
7
|
+
import { mermaidPlugin as yt } from "./plugins/mermaidPlugin.js";
|
|
8
|
+
import { tableGeneratorPlugin as zt } from "./plugins/tableGenerator.js";
|
|
9
|
+
import { tableGridPlugin as St, tableGridStyles as Ct } from "./plugins/tableGridPlugin.js";
|
|
10
|
+
import { tablePlugin as Et } from "./plugins/tablePlugin.js";
|
|
11
|
+
import { tinyHighlightPlugin as $t, tinyHighlightStyles as Mt } from "./plugins/tinyHighlight.js";
|
|
12
|
+
const N = class N {
|
|
14
13
|
/**
|
|
15
14
|
* Reset link index (call before parsing a new document)
|
|
16
15
|
*/
|
|
@@ -148,16 +147,28 @@ const I = class I {
|
|
|
148
147
|
static isTableSeparator(e) {
|
|
149
148
|
return /^\|\s*[-:]+\s*(?:\|\s*[-:]+\s*)*\|$/.test(e);
|
|
150
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Parse column alignments from a table separator row
|
|
152
|
+
* @param {string} separatorText - Raw text of the separator row
|
|
153
|
+
* @returns {string[]} Array of alignment values ('left', 'center', 'right')
|
|
154
|
+
*/
|
|
155
|
+
static parseTableAlignments(e) {
|
|
156
|
+
return e.slice(1, -1).split(/(?<!\\)\|/).map((n) => {
|
|
157
|
+
const r = n.trim(), o = r.startsWith(":"), a = r.endsWith(":");
|
|
158
|
+
return o && a ? "center" : a ? "right" : "left";
|
|
159
|
+
});
|
|
160
|
+
}
|
|
151
161
|
/**
|
|
152
162
|
* Parse a table row into cells
|
|
153
163
|
* @param {string} html - HTML table row
|
|
154
164
|
* @param {string} tag - Tag to use for cells (th or td)
|
|
165
|
+
* @param {string[]} alignments - Optional column alignment array
|
|
155
166
|
* @returns {string} HTML table row
|
|
156
167
|
*/
|
|
157
|
-
static parseTableRow(e, t = "td") {
|
|
158
|
-
return `<tr>${e.slice(1, -1).split(/(?<!\\)\|/).map((
|
|
159
|
-
const
|
|
160
|
-
return `<${t}>${
|
|
168
|
+
static parseTableRow(e, t = "td", n = []) {
|
|
169
|
+
return `<tr>${e.slice(1, -1).split(/(?<!\\)\|/).map((a, s) => {
|
|
170
|
+
const l = a.trim(), c = this.parseInlineElements(l || " "), d = n[s], p = d && d !== "left" ? ` style="text-align: ${d}"` : "";
|
|
171
|
+
return `<${t}${p}>${c}</${t}>`;
|
|
161
172
|
}).join("")}</tr>`;
|
|
162
173
|
}
|
|
163
174
|
/**
|
|
@@ -175,8 +186,8 @@ const I = class I {
|
|
|
175
186
|
*/
|
|
176
187
|
static parseImages(e) {
|
|
177
188
|
return e.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g, (t, n, r, o) => {
|
|
178
|
-
const
|
|
179
|
-
return `<img src="${
|
|
189
|
+
const a = this.sanitizeUrl(r), s = this.escapeHtml(n || ""), l = o ? ` title="${this.escapeHtml(o)}"` : "";
|
|
190
|
+
return `<img src="${a}" alt="${s}"${l} class="marzipan-image" />`;
|
|
180
191
|
});
|
|
181
192
|
}
|
|
182
193
|
/**
|
|
@@ -191,8 +202,8 @@ const I = class I {
|
|
|
191
202
|
"mailto:",
|
|
192
203
|
"ftp://",
|
|
193
204
|
"ftps://"
|
|
194
|
-
].some((
|
|
195
|
-
return o ||
|
|
205
|
+
].some((s) => n.startsWith(s)), a = t.startsWith("/") || t.startsWith("#") || t.startsWith("?") || t.startsWith(".") || !t.includes(":") && !t.includes("//");
|
|
206
|
+
return o || a ? e : "#";
|
|
196
207
|
}
|
|
197
208
|
/**
|
|
198
209
|
* Parse links
|
|
@@ -213,53 +224,53 @@ const I = class I {
|
|
|
213
224
|
static identifyAndProtectSanctuaries(e) {
|
|
214
225
|
const t = /* @__PURE__ */ new Map();
|
|
215
226
|
let n = 0, r = e;
|
|
216
|
-
const o = [],
|
|
217
|
-
let
|
|
218
|
-
for (; (
|
|
219
|
-
const
|
|
220
|
-
o.push({ start:
|
|
227
|
+
const o = [], a = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
228
|
+
let s;
|
|
229
|
+
for (; (s = a.exec(e)) !== null; ) {
|
|
230
|
+
const h = s.index + s[0].indexOf("](") + 2, m = h + s[2].length;
|
|
231
|
+
o.push({ start: h, end: m });
|
|
221
232
|
}
|
|
222
233
|
const l = /(?<!`)(`+)(?!`)((?:(?!\1).)+?)(\1)(?!`)/g;
|
|
223
|
-
let
|
|
234
|
+
let c;
|
|
224
235
|
const d = [];
|
|
225
|
-
for (; (
|
|
226
|
-
const
|
|
236
|
+
for (; (c = l.exec(e)) !== null; ) {
|
|
237
|
+
const p = c.index, h = c.index + c[0].length;
|
|
227
238
|
o.some(
|
|
228
|
-
(
|
|
239
|
+
(u) => p >= u.start && h <= u.end
|
|
229
240
|
) || d.push({
|
|
230
|
-
match:
|
|
231
|
-
index:
|
|
232
|
-
openTicks:
|
|
233
|
-
content:
|
|
234
|
-
closeTicks:
|
|
241
|
+
match: c[0],
|
|
242
|
+
index: c.index,
|
|
243
|
+
openTicks: c[1],
|
|
244
|
+
content: c[2],
|
|
245
|
+
closeTicks: c[3]
|
|
235
246
|
});
|
|
236
247
|
}
|
|
237
|
-
return d.sort((
|
|
238
|
-
const
|
|
239
|
-
t.set(
|
|
248
|
+
return d.sort((p, h) => h.index - p.index), d.forEach((p) => {
|
|
249
|
+
const h = `${n++}`;
|
|
250
|
+
t.set(h, {
|
|
240
251
|
type: "code",
|
|
241
|
-
original:
|
|
242
|
-
openTicks:
|
|
243
|
-
content:
|
|
244
|
-
closeTicks:
|
|
245
|
-
}), r = r.substring(0,
|
|
246
|
-
}), r = r.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g, (
|
|
252
|
+
original: p.match,
|
|
253
|
+
openTicks: p.openTicks,
|
|
254
|
+
content: p.content,
|
|
255
|
+
closeTicks: p.closeTicks
|
|
256
|
+
}), r = r.substring(0, p.index) + h + r.substring(p.index + p.match.length);
|
|
257
|
+
}), r = r.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g, (p, h, m, u) => {
|
|
247
258
|
const f = `${n++}`;
|
|
248
259
|
return t.set(f, {
|
|
249
260
|
type: "image",
|
|
250
|
-
original:
|
|
251
|
-
alt:
|
|
252
|
-
url:
|
|
253
|
-
title:
|
|
261
|
+
original: p,
|
|
262
|
+
alt: h,
|
|
263
|
+
url: m,
|
|
264
|
+
title: u
|
|
254
265
|
}), f;
|
|
255
|
-
}), r = r.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (
|
|
256
|
-
const
|
|
257
|
-
return t.set(
|
|
266
|
+
}), r = r.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (p, h, m) => {
|
|
267
|
+
const u = `${n++}`;
|
|
268
|
+
return t.set(u, {
|
|
258
269
|
type: "link",
|
|
259
|
-
original:
|
|
260
|
-
linkText:
|
|
261
|
-
url:
|
|
262
|
-
}),
|
|
270
|
+
original: p,
|
|
271
|
+
linkText: h,
|
|
272
|
+
url: m
|
|
273
|
+
}), u;
|
|
263
274
|
}), { protectedText: r, sanctuaries: t };
|
|
264
275
|
}
|
|
265
276
|
/**
|
|
@@ -270,28 +281,28 @@ const I = class I {
|
|
|
270
281
|
*/
|
|
271
282
|
static restoreAndTransformSanctuaries(e, t) {
|
|
272
283
|
return Array.from(t.keys()).sort((r, o) => {
|
|
273
|
-
const
|
|
274
|
-
return
|
|
284
|
+
const a = e.indexOf(r), s = e.indexOf(o);
|
|
285
|
+
return a - s;
|
|
275
286
|
}).forEach((r) => {
|
|
276
287
|
const o = t.get(r);
|
|
277
|
-
let
|
|
288
|
+
let a;
|
|
278
289
|
if (o.type === "code")
|
|
279
|
-
|
|
290
|
+
a = `<code><span class="syntax-marker">${o.openTicks}</span>${this.escapeHtml(o.content)}<span class="syntax-marker">${o.closeTicks}</span></code>`;
|
|
280
291
|
else if (o.type === "image") {
|
|
281
|
-
const
|
|
282
|
-
|
|
292
|
+
const s = this.sanitizeUrl(o.url), l = this.escapeHtml(o.alt || ""), c = o.title ? ` title="${this.escapeHtml(o.title)}"` : "";
|
|
293
|
+
a = `<img src="${s}" alt="${l}"${c} class="marzipan-image" />`;
|
|
283
294
|
} else if (o.type === "link") {
|
|
284
|
-
let
|
|
285
|
-
t.forEach((d,
|
|
286
|
-
if (
|
|
287
|
-
const
|
|
288
|
-
|
|
295
|
+
let s = o.linkText;
|
|
296
|
+
t.forEach((d, p) => {
|
|
297
|
+
if (s.includes(p) && d.type === "code") {
|
|
298
|
+
const h = `<code><span class="syntax-marker">${d.openTicks}</span>${this.escapeHtml(d.content)}<span class="syntax-marker">${d.closeTicks}</span></code>`;
|
|
299
|
+
s = s.replace(p, h);
|
|
289
300
|
}
|
|
290
|
-
}),
|
|
301
|
+
}), s = this.parseStrikethrough(s), s = this.parseBold(s), s = this.parseItalic(s);
|
|
291
302
|
const l = `--link-${this.linkIndex++}`;
|
|
292
|
-
|
|
303
|
+
a = `<a href="${this.sanitizeUrl(o.url)}" style="anchor-name: ${l}"><span class="syntax-marker">[</span>${s}<span class="syntax-marker url-part">](${this.escapeHtml(o.url)})</span></a>`;
|
|
293
304
|
}
|
|
294
|
-
e = e.replace(r,
|
|
305
|
+
e = e.replace(r, a);
|
|
295
306
|
}), e;
|
|
296
307
|
}
|
|
297
308
|
/**
|
|
@@ -314,12 +325,12 @@ const I = class I {
|
|
|
314
325
|
let n = this.escapeHtml(e);
|
|
315
326
|
n = this.preserveIndentation(n, e);
|
|
316
327
|
let r = "paragraph", o = "";
|
|
317
|
-
const
|
|
318
|
-
if (s)
|
|
319
|
-
return r = "hr", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, s.replace("<div", `<div${o}`);
|
|
320
|
-
const a = this.parseCodeBlock(n);
|
|
328
|
+
const a = this.parseHorizontalRule(n);
|
|
321
329
|
if (a)
|
|
322
|
-
return r = "
|
|
330
|
+
return r = "hr", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, a.replace("<div", `<div${o}`);
|
|
331
|
+
const s = this.parseCodeBlock(n);
|
|
332
|
+
if (s)
|
|
333
|
+
return r = "code-fence", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, s.replace("<div", `<div${o}`);
|
|
323
334
|
const l = e.trim();
|
|
324
335
|
return /^#{1,6}\s/.test(l) ? r = "heading" : /^>/.test(l) ? r = "quote" : (/^[-*+]\s/.test(l) || /^\d+\.\s/.test(l)) && (r = "list-item"), n = this.parseHeader(n), n = this.parseBlockquote(n), n = this.parseBulletList(n), n = this.parseNumberedList(n), n = this.parseInlineElements(n), o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, n.trim() === "" ? `<div${o}> </div>` : `<div${o}>${n}</div>`;
|
|
325
336
|
}
|
|
@@ -335,25 +346,29 @@ const I = class I {
|
|
|
335
346
|
const r = e.split(`
|
|
336
347
|
`);
|
|
337
348
|
let o = !1;
|
|
338
|
-
const
|
|
339
|
-
if (n &&
|
|
349
|
+
const s = r.map((l, c) => {
|
|
350
|
+
if (n && c === t) {
|
|
340
351
|
const m = this.escapeHtml(l) || " ";
|
|
341
|
-
return `<div class="raw-line" data-block-id="${this.generateBlockId()}" data-block-type="paragraph" data-line-start="${
|
|
352
|
+
return `<div class="raw-line" data-block-id="${this.generateBlockId()}" data-block-type="paragraph" data-line-start="${c}" data-line-end="${c}">${m}</div>`;
|
|
342
353
|
}
|
|
343
354
|
if (/^```[^`]*$/.test(l))
|
|
344
|
-
return o = !o, this.parseLine(l,
|
|
355
|
+
return o = !o, this.parseLine(l, c);
|
|
345
356
|
if (o) {
|
|
346
357
|
const m = this.escapeHtml(l), u = this.preserveIndentation(m, l);
|
|
347
|
-
return `<div data-block-id="${this.generateBlockId()}" data-block-type="code-content" data-line-start="${
|
|
358
|
+
return `<div data-block-id="${this.generateBlockId()}" data-block-type="code-content" data-line-start="${c}" data-line-end="${c}">${u || " "}</div>`;
|
|
359
|
+
}
|
|
360
|
+
const p = this.escapeHtml(l), h = l.match(/^<!--\s*mz-table:\s*(.+?)\s*-->$/);
|
|
361
|
+
if (h) {
|
|
362
|
+
const m = this.generateBlockId();
|
|
363
|
+
return `<div class="mz-table-annotation" data-mz-annotation="${this.escapeHtml(h[1])}" data-block-id="${m}" data-block-type="table-annotation" data-line-start="${c}" data-line-end="${c}" style="display:none">${p}</div>`;
|
|
348
364
|
}
|
|
349
|
-
|
|
350
|
-
if (this.isTableRow(c)) {
|
|
365
|
+
if (this.isTableRow(p)) {
|
|
351
366
|
const m = this.generateBlockId();
|
|
352
|
-
return this.isTableSeparator(
|
|
367
|
+
return this.isTableSeparator(p) ? `<div class="table-separator" data-block-id="${m}" data-block-type="table-separator" data-line-start="${c}" data-line-end="${c}">${p}</div>` : `<div class="table-row" data-block-id="${m}" data-block-type="table-row" data-line-start="${c}" data-line-end="${c}">${p}</div>`;
|
|
353
368
|
}
|
|
354
|
-
return this.parseLine(l,
|
|
369
|
+
return this.parseLine(l, c);
|
|
355
370
|
}).join("");
|
|
356
|
-
return this.postProcessHTML(
|
|
371
|
+
return this.postProcessHTML(s);
|
|
357
372
|
}
|
|
358
373
|
/**
|
|
359
374
|
* Post-process HTML to consolidate lists and code blocks
|
|
@@ -365,69 +380,82 @@ const I = class I {
|
|
|
365
380
|
return this.postProcessHTMLManual(e);
|
|
366
381
|
const t = document.createElement("div");
|
|
367
382
|
t.innerHTML = e;
|
|
368
|
-
let n = null, r = null, o = null,
|
|
383
|
+
let n = null, r = null, o = null, a = !1, s = null, l = !1, c = [], d = null;
|
|
369
384
|
const p = Array.from(t.children);
|
|
370
|
-
for (let
|
|
371
|
-
const
|
|
372
|
-
if (!
|
|
373
|
-
if (
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
385
|
+
for (let h = 0; h < p.length; h++) {
|
|
386
|
+
const m = p[h];
|
|
387
|
+
if (!m.parentNode) continue;
|
|
388
|
+
if (m.classList && m.classList.contains("mz-table-annotation")) {
|
|
389
|
+
d = m.getAttribute("data-mz-annotation") || "", m.remove();
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
if (m.classList && (m.classList.contains("table-row") || m.classList.contains("table-separator"))) {
|
|
393
|
+
if (m.classList.contains("table-separator")) {
|
|
394
|
+
if (!s) {
|
|
395
|
+
m.remove();
|
|
377
396
|
continue;
|
|
378
397
|
}
|
|
379
|
-
|
|
398
|
+
c = this.parseTableAlignments(m.textContent || ""), s.querySelectorAll("thead th").forEach((P, L) => {
|
|
399
|
+
const z = c[L];
|
|
400
|
+
z && z !== "left" && (P.style.textAlign = z);
|
|
401
|
+
}), l = !1, m.remove();
|
|
380
402
|
continue;
|
|
381
403
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
404
|
+
if (!s) {
|
|
405
|
+
if (s = document.createElement("table"), s.className = "marzipan-table", d) {
|
|
406
|
+
const B = d.match(/style=(\S+)/), P = d.match(/border=(\S+)/);
|
|
407
|
+
B && s.classList.add(`mz-table-${B[1]}`), P && s.classList.add(`mz-border-${P[1]}`), d = null;
|
|
408
|
+
}
|
|
409
|
+
t.insertBefore(s, m), l = !0, c = [];
|
|
410
|
+
}
|
|
411
|
+
const b = m.textContent, v = l ? "th" : "td", k = this.parseTableRow(b, v, l ? [] : c);
|
|
412
|
+
let y;
|
|
413
|
+
l ? (y = s.querySelector("thead"), y || (y = document.createElement("thead"), s.appendChild(y))) : (y = s.querySelector("tbody"), y || (y = document.createElement("tbody"), s.appendChild(y))), y.innerHTML += k, m.remove();
|
|
386
414
|
continue;
|
|
387
415
|
} else
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
393
|
-
if (
|
|
394
|
-
|
|
416
|
+
s = null, l = !1, c = [];
|
|
417
|
+
const u = m.querySelector(".code-fence");
|
|
418
|
+
if (u) {
|
|
419
|
+
const g = u.textContent;
|
|
420
|
+
if (g.startsWith("```"))
|
|
421
|
+
if (a) {
|
|
422
|
+
a = !1, o = null;
|
|
395
423
|
continue;
|
|
396
424
|
} else {
|
|
397
|
-
|
|
398
|
-
const
|
|
399
|
-
o.appendChild(
|
|
400
|
-
const
|
|
401
|
-
|
|
425
|
+
a = !0, o = document.createElement("pre");
|
|
426
|
+
const b = document.createElement("code");
|
|
427
|
+
o.appendChild(b), o.className = "code-block";
|
|
428
|
+
const v = g.slice(3).trim();
|
|
429
|
+
v && (b.className = `language-${v}`), t.insertBefore(o, m.nextSibling), o._codeElement = b;
|
|
402
430
|
continue;
|
|
403
431
|
}
|
|
404
432
|
}
|
|
405
|
-
if (
|
|
406
|
-
const
|
|
407
|
-
|
|
433
|
+
if (a && o && m.tagName === "DIV" && !m.querySelector(".code-fence")) {
|
|
434
|
+
const g = o._codeElement || o.querySelector("code");
|
|
435
|
+
g.textContent.length > 0 && (g.textContent += `
|
|
408
436
|
`);
|
|
409
|
-
const
|
|
410
|
-
|
|
437
|
+
const b = m.textContent.replace(/\u00A0/g, " ");
|
|
438
|
+
g.textContent += b, m.remove();
|
|
411
439
|
continue;
|
|
412
440
|
}
|
|
413
|
-
let
|
|
414
|
-
if (
|
|
415
|
-
const
|
|
416
|
-
if (!
|
|
441
|
+
let f = null;
|
|
442
|
+
if (m.tagName === "DIV" && (f = m.querySelector("li")), f) {
|
|
443
|
+
const g = f.classList.contains("bullet-list"), b = f.classList.contains("ordered-list");
|
|
444
|
+
if (!g && !b) {
|
|
417
445
|
n = null, r = null;
|
|
418
446
|
continue;
|
|
419
447
|
}
|
|
420
|
-
const
|
|
421
|
-
(!n || r !==
|
|
422
|
-
const
|
|
423
|
-
for (const
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
else if (
|
|
448
|
+
const v = g ? "ul" : "ol";
|
|
449
|
+
(!n || r !== v) && (n = document.createElement(v), t.insertBefore(n, m), r = v);
|
|
450
|
+
const k = [];
|
|
451
|
+
for (const y of m.childNodes)
|
|
452
|
+
if (y.nodeType === 3 && y.textContent.match(/^\u00A0+$/))
|
|
453
|
+
k.push(y.cloneNode(!0));
|
|
454
|
+
else if (y === f)
|
|
427
455
|
break;
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}), n.appendChild(
|
|
456
|
+
k.forEach((y) => {
|
|
457
|
+
f.insertBefore(y, f.firstChild);
|
|
458
|
+
}), n.appendChild(f), m.remove();
|
|
431
459
|
} else
|
|
432
460
|
n = null, r = null;
|
|
433
461
|
}
|
|
@@ -442,31 +470,31 @@ const I = class I {
|
|
|
442
470
|
let t = e;
|
|
443
471
|
t = t.replace(/((?:<div>(?: )*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs, (r) => {
|
|
444
472
|
const o = r.match(/<div>(?: )*<li class="bullet-list">.*?<\/li><\/div>/gs) || [];
|
|
445
|
-
return o.length > 0 ? "<ul>" + o.map((
|
|
446
|
-
const l =
|
|
447
|
-
if (l &&
|
|
473
|
+
return o.length > 0 ? "<ul>" + o.map((s) => {
|
|
474
|
+
const l = s.match(/<div>((?: )*)<li/), c = s.match(/<li class="bullet-list">.*?<\/li>/);
|
|
475
|
+
if (l && c) {
|
|
448
476
|
const d = l[1];
|
|
449
|
-
return
|
|
477
|
+
return c[0].replace(/<li class="bullet-list">/, `<li class="bullet-list">${d}`);
|
|
450
478
|
}
|
|
451
|
-
return
|
|
479
|
+
return c ? c[0] : "";
|
|
452
480
|
}).filter(Boolean).join("") + "</ul>" : r;
|
|
453
481
|
}), t = t.replace(/((?:<div>(?: )*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs, (r) => {
|
|
454
482
|
const o = r.match(/<div>(?: )*<li class="ordered-list">.*?<\/li><\/div>/gs) || [];
|
|
455
|
-
return o.length > 0 ? "<ol>" + o.map((
|
|
456
|
-
const l =
|
|
457
|
-
if (l &&
|
|
483
|
+
return o.length > 0 ? "<ol>" + o.map((s) => {
|
|
484
|
+
const l = s.match(/<div>((?: )*)<li/), c = s.match(/<li class="ordered-list">.*?<\/li>/);
|
|
485
|
+
if (l && c) {
|
|
458
486
|
const d = l[1];
|
|
459
|
-
return
|
|
487
|
+
return c[0].replace(/<li class="ordered-list">/, `<li class="ordered-list">${d}`);
|
|
460
488
|
}
|
|
461
|
-
return
|
|
489
|
+
return c ? c[0] : "";
|
|
462
490
|
}).filter(Boolean).join("") + "</ol>" : r;
|
|
463
491
|
});
|
|
464
492
|
const n = /<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;
|
|
465
|
-
return t = t.replace(n, (r, o,
|
|
466
|
-
const
|
|
467
|
-
`), d = o.slice(3).trim(),
|
|
468
|
-
let
|
|
469
|
-
return
|
|
493
|
+
return t = t.replace(n, (r, o, a, s) => {
|
|
494
|
+
const c = (a.match(/<div>(.*?)<\/div>/gs) || []).map((m) => m.replace(/<div>(.*?)<\/div>/s, "$1").replace(/ /g, " ")).join(`
|
|
495
|
+
`), d = o.slice(3).trim(), p = d ? ` class="language-${d}"` : "";
|
|
496
|
+
let h = `<div><span class="code-fence">${o}</span></div>`;
|
|
497
|
+
return h += `<pre class="code-block"><code${p}>${c}</code></pre>`, h += `<div><span class="code-fence">${s}</span></div>`, h;
|
|
470
498
|
}), t;
|
|
471
499
|
}
|
|
472
500
|
/**
|
|
@@ -478,30 +506,30 @@ const I = class I {
|
|
|
478
506
|
static getListContext(e, t) {
|
|
479
507
|
const n = e.split(`
|
|
480
508
|
`);
|
|
481
|
-
let r = 0, o = 0,
|
|
482
|
-
for (let
|
|
483
|
-
const
|
|
484
|
-
if (r +
|
|
485
|
-
o =
|
|
509
|
+
let r = 0, o = 0, a = 0;
|
|
510
|
+
for (let h = 0; h < n.length; h++) {
|
|
511
|
+
const m = n[h].length;
|
|
512
|
+
if (r + m >= t) {
|
|
513
|
+
o = h, a = r;
|
|
486
514
|
break;
|
|
487
515
|
}
|
|
488
|
-
r +=
|
|
516
|
+
r += m + 1;
|
|
489
517
|
}
|
|
490
|
-
const
|
|
491
|
-
if (
|
|
518
|
+
const s = n[o], l = a + s.length, c = s.match(this.LIST_PATTERNS.checkbox);
|
|
519
|
+
if (c)
|
|
492
520
|
return {
|
|
493
521
|
inList: !0,
|
|
494
522
|
listType: "checkbox",
|
|
495
|
-
indent:
|
|
523
|
+
indent: c[1],
|
|
496
524
|
marker: "-",
|
|
497
|
-
checked:
|
|
498
|
-
content:
|
|
499
|
-
lineStart:
|
|
525
|
+
checked: c[2] === "x",
|
|
526
|
+
content: c[3],
|
|
527
|
+
lineStart: a,
|
|
500
528
|
lineEnd: l,
|
|
501
|
-
markerEndPos:
|
|
529
|
+
markerEndPos: a + c[1].length + c[2].length + 5
|
|
502
530
|
// indent + "- [ ] "
|
|
503
531
|
};
|
|
504
|
-
const d =
|
|
532
|
+
const d = s.match(this.LIST_PATTERNS.bullet);
|
|
505
533
|
if (d)
|
|
506
534
|
return {
|
|
507
535
|
inList: !0,
|
|
@@ -509,31 +537,31 @@ const I = class I {
|
|
|
509
537
|
indent: d[1],
|
|
510
538
|
marker: d[2],
|
|
511
539
|
content: d[3],
|
|
512
|
-
lineStart:
|
|
540
|
+
lineStart: a,
|
|
513
541
|
lineEnd: l,
|
|
514
|
-
markerEndPos:
|
|
542
|
+
markerEndPos: a + d[1].length + d[2].length + 1
|
|
515
543
|
// indent + marker + space
|
|
516
544
|
};
|
|
517
|
-
const
|
|
518
|
-
return
|
|
545
|
+
const p = s.match(this.LIST_PATTERNS.numbered);
|
|
546
|
+
return p ? {
|
|
519
547
|
inList: !0,
|
|
520
548
|
listType: "numbered",
|
|
521
|
-
indent:
|
|
522
|
-
marker: parseInt(
|
|
523
|
-
content:
|
|
524
|
-
lineStart:
|
|
549
|
+
indent: p[1],
|
|
550
|
+
marker: parseInt(p[2]),
|
|
551
|
+
content: p[3],
|
|
552
|
+
lineStart: a,
|
|
525
553
|
lineEnd: l,
|
|
526
|
-
markerEndPos:
|
|
554
|
+
markerEndPos: a + p[1].length + p[2].length + 2
|
|
527
555
|
// indent + number + ". "
|
|
528
556
|
} : {
|
|
529
557
|
inList: !1,
|
|
530
558
|
listType: null,
|
|
531
559
|
indent: "",
|
|
532
560
|
marker: null,
|
|
533
|
-
content:
|
|
534
|
-
lineStart:
|
|
561
|
+
content: s,
|
|
562
|
+
lineStart: a,
|
|
535
563
|
lineEnd: l,
|
|
536
|
-
markerEndPos:
|
|
564
|
+
markerEndPos: a
|
|
537
565
|
};
|
|
538
566
|
}
|
|
539
567
|
/**
|
|
@@ -562,29 +590,29 @@ const I = class I {
|
|
|
562
590
|
const t = e.split(`
|
|
563
591
|
`), n = /* @__PURE__ */ new Map();
|
|
564
592
|
let r = !1;
|
|
565
|
-
return t.map((
|
|
566
|
-
const
|
|
567
|
-
if (
|
|
568
|
-
const l =
|
|
593
|
+
return t.map((a) => {
|
|
594
|
+
const s = a.match(this.LIST_PATTERNS.numbered);
|
|
595
|
+
if (s) {
|
|
596
|
+
const l = s[1], c = l.length, d = s[3];
|
|
569
597
|
r || n.clear();
|
|
570
|
-
const
|
|
571
|
-
n.set(
|
|
572
|
-
for (const [
|
|
573
|
-
|
|
574
|
-
return r = !0, `${l}${
|
|
598
|
+
const p = (n.get(c) || 0) + 1;
|
|
599
|
+
n.set(c, p);
|
|
600
|
+
for (const [h] of n)
|
|
601
|
+
h > c && n.delete(h);
|
|
602
|
+
return r = !0, `${l}${p}. ${d}`;
|
|
575
603
|
} else
|
|
576
|
-
return (
|
|
604
|
+
return (a.trim() === "" || !a.match(/^\s/)) && (r = !1, n.clear()), a;
|
|
577
605
|
}).join(`
|
|
578
606
|
`);
|
|
579
607
|
}
|
|
580
608
|
};
|
|
581
|
-
|
|
609
|
+
N.linkIndex = 0, N.blockIndex = 0, N.LIST_PATTERNS = {
|
|
582
610
|
bullet: /^(\s*)([-*+])\s+(.*)$/,
|
|
583
611
|
numbered: /^(\s*)(\d+)\.\s+(.*)$/,
|
|
584
612
|
checkbox: /^(\s*)-\s+\[([ x])\]\s+(.*)$/
|
|
585
613
|
};
|
|
586
|
-
let
|
|
587
|
-
const
|
|
614
|
+
let $ = N;
|
|
615
|
+
const C = {
|
|
588
616
|
bold: {
|
|
589
617
|
prefix: "**",
|
|
590
618
|
suffix: "**",
|
|
@@ -662,64 +690,64 @@ function E(i) {
|
|
|
662
690
|
};
|
|
663
691
|
return e.scanFor = i.scanFor ?? null, e;
|
|
664
692
|
}
|
|
665
|
-
let
|
|
666
|
-
function
|
|
667
|
-
|
|
693
|
+
let j = !1;
|
|
694
|
+
function de(i) {
|
|
695
|
+
j = i;
|
|
668
696
|
}
|
|
669
|
-
function
|
|
670
|
-
return
|
|
697
|
+
function D() {
|
|
698
|
+
return j;
|
|
671
699
|
}
|
|
672
|
-
function
|
|
673
|
-
|
|
700
|
+
function x(i, e, t) {
|
|
701
|
+
j && (console.group(`🔍 ${i}`), console.log(e), console.groupEnd());
|
|
674
702
|
}
|
|
675
|
-
function
|
|
676
|
-
if (!
|
|
703
|
+
function F(i, e) {
|
|
704
|
+
if (!j) return;
|
|
677
705
|
const t = i.value.slice(i.selectionStart, i.selectionEnd);
|
|
678
706
|
console.group(`📍 Selection: ${e}`), console.log("Position:", `${i.selectionStart}-${i.selectionEnd}`), console.log("Selected text:", JSON.stringify(t)), console.log("Length:", t.length);
|
|
679
707
|
const n = i.value.slice(Math.max(0, i.selectionStart - 10), i.selectionStart), r = i.value.slice(i.selectionEnd, Math.min(i.value.length, i.selectionEnd + 10));
|
|
680
708
|
console.log("Context:", `${JSON.stringify(n)}[SELECTION]${JSON.stringify(r)}`), console.groupEnd();
|
|
681
709
|
}
|
|
682
|
-
function
|
|
683
|
-
|
|
710
|
+
function q(i) {
|
|
711
|
+
j && (console.group("📝 Result"), console.log("Text to insert:", JSON.stringify(i.text)), console.log("New selection:", `${i.selectionStart}-${i.selectionEnd}`), console.groupEnd());
|
|
684
712
|
}
|
|
685
|
-
let
|
|
686
|
-
function
|
|
687
|
-
const t =
|
|
713
|
+
let S = null;
|
|
714
|
+
function H(i, e) {
|
|
715
|
+
const t = D();
|
|
688
716
|
t && (console.group("🔧 insertText"), console.log("Current selection:", `${i.selectionStart}-${i.selectionEnd}`), console.log("Text to insert:", JSON.stringify(e.text)), console.log("New selection to set:", e.selectionStart, "-", e.selectionEnd)), i.focus();
|
|
689
|
-
const n = i.selectionStart, r = i.selectionEnd, o = i.value.slice(0, n),
|
|
690
|
-
t && (console.log("Before text (last 20):", JSON.stringify(o.slice(-20))), console.log("After text (first 20):", JSON.stringify(
|
|
717
|
+
const n = i.selectionStart, r = i.selectionEnd, o = i.value.slice(0, n), a = i.value.slice(r);
|
|
718
|
+
t && (console.log("Before text (last 20):", JSON.stringify(o.slice(-20))), console.log("After text (first 20):", JSON.stringify(a.slice(0, 20))), console.log(
|
|
691
719
|
"Selected text being replaced:",
|
|
692
720
|
JSON.stringify(i.value.slice(n, r))
|
|
693
721
|
));
|
|
694
|
-
const
|
|
695
|
-
if (
|
|
722
|
+
const s = i.value;
|
|
723
|
+
if (S === null || S === !0) {
|
|
696
724
|
i.contentEditable = "true";
|
|
697
725
|
try {
|
|
698
|
-
|
|
726
|
+
S = document.execCommand("insertText", !1, e.text), t && console.log(
|
|
699
727
|
"execCommand returned:",
|
|
700
|
-
|
|
728
|
+
S,
|
|
701
729
|
"for text with",
|
|
702
730
|
e.text.split(`
|
|
703
731
|
`).length,
|
|
704
732
|
"lines"
|
|
705
733
|
);
|
|
706
734
|
} catch (l) {
|
|
707
|
-
|
|
735
|
+
S = !1, t && console.log("execCommand threw error:", l);
|
|
708
736
|
}
|
|
709
737
|
i.contentEditable = "false";
|
|
710
738
|
}
|
|
711
|
-
if (t && (console.log("canInsertText before:",
|
|
712
|
-
const l = o + e.text +
|
|
713
|
-
t && (console.log("Expected length:", l.length), console.log("Actual length:",
|
|
739
|
+
if (t && (console.log("canInsertText before:", S), console.log("execCommand result:", S)), S) {
|
|
740
|
+
const l = o + e.text + a, c = i.value;
|
|
741
|
+
t && (console.log("Expected length:", l.length), console.log("Actual length:", c.length)), c !== l && t && (console.log("execCommand changed the value but not as expected"), console.log("Expected:", JSON.stringify(l.slice(0, 100))), console.log("Actual:", JSON.stringify(c.slice(0, 100))));
|
|
714
742
|
}
|
|
715
|
-
if (!
|
|
716
|
-
if (t && console.log("Using manual insertion"), i.value ===
|
|
743
|
+
if (!S)
|
|
744
|
+
if (t && console.log("Using manual insertion"), i.value === s) {
|
|
717
745
|
t && console.log("Value unchanged, doing manual replacement");
|
|
718
746
|
try {
|
|
719
747
|
document.execCommand("ms-beginUndoUnit");
|
|
720
748
|
} catch {
|
|
721
749
|
}
|
|
722
|
-
i.value = o + e.text +
|
|
750
|
+
i.value = o + e.text + a;
|
|
723
751
|
try {
|
|
724
752
|
document.execCommand("ms-endUndoUnit");
|
|
725
753
|
} catch {
|
|
@@ -728,27 +756,27 @@ function T(i, e) {
|
|
|
728
756
|
} else t && console.log("Value was changed by execCommand, skipping manual insertion");
|
|
729
757
|
t && console.log("Setting selection range:", e.selectionStart, e.selectionEnd), e.selectionStart != null && e.selectionEnd != null ? i.setSelectionRange(e.selectionStart, e.selectionEnd) : i.setSelectionRange(n, i.selectionEnd), t && (console.log("Final value length:", i.value.length), console.groupEnd());
|
|
730
758
|
}
|
|
731
|
-
function
|
|
759
|
+
function me(i) {
|
|
732
760
|
switch (i) {
|
|
733
761
|
case "native":
|
|
734
|
-
|
|
762
|
+
S = !0;
|
|
735
763
|
break;
|
|
736
764
|
case "manual":
|
|
737
|
-
|
|
765
|
+
S = !1;
|
|
738
766
|
break;
|
|
739
767
|
default:
|
|
740
|
-
|
|
768
|
+
S = null;
|
|
741
769
|
break;
|
|
742
770
|
}
|
|
743
771
|
}
|
|
744
|
-
function
|
|
745
|
-
return
|
|
772
|
+
function Te() {
|
|
773
|
+
return S === !0 ? "native" : S === !1 ? "manual" : "auto";
|
|
746
774
|
}
|
|
747
|
-
function
|
|
775
|
+
function U(i) {
|
|
748
776
|
return i.trim().split(`
|
|
749
777
|
`).length > 1;
|
|
750
778
|
}
|
|
751
|
-
function
|
|
779
|
+
function Ee(i, e) {
|
|
752
780
|
let t = e;
|
|
753
781
|
for (; i[t] && i[t - 1] != null && !/\s/.test(i[t - 1]); )
|
|
754
782
|
t -= 1;
|
|
@@ -761,7 +789,7 @@ function He(i, e, t) {
|
|
|
761
789
|
n += 1;
|
|
762
790
|
return n;
|
|
763
791
|
}
|
|
764
|
-
function
|
|
792
|
+
function he(i) {
|
|
765
793
|
const e = i.value.split(`
|
|
766
794
|
`);
|
|
767
795
|
let t = 0;
|
|
@@ -772,134 +800,134 @@ function de(i) {
|
|
|
772
800
|
}
|
|
773
801
|
function $e(i, e, t, n = !1) {
|
|
774
802
|
if (i.selectionStart === i.selectionEnd)
|
|
775
|
-
i.selectionStart =
|
|
803
|
+
i.selectionStart = Ee(i.value, i.selectionStart), i.selectionEnd = He(i.value, i.selectionEnd, n);
|
|
776
804
|
else {
|
|
777
|
-
const r = i.selectionStart - e.length, o = i.selectionEnd + t.length,
|
|
778
|
-
|
|
805
|
+
const r = i.selectionStart - e.length, o = i.selectionEnd + t.length, a = i.value.slice(r, i.selectionStart) === e, s = i.value.slice(i.selectionEnd, o) === t;
|
|
806
|
+
a && s && (i.selectionStart = r, i.selectionEnd = o);
|
|
779
807
|
}
|
|
780
808
|
return i.value.slice(i.selectionStart, i.selectionEnd);
|
|
781
809
|
}
|
|
782
|
-
function
|
|
783
|
-
const e = i.value.slice(0, i.selectionStart), t = i.value.slice(i.selectionEnd), n = e.match(/\n*$/), r = t.match(/^\n*/), o = n ? n[0].length : 0,
|
|
784
|
-
let
|
|
785
|
-
return /\S/.test(e) && o < 2 && (
|
|
786
|
-
`.repeat(2 - o)), /\S/.test(t) &&
|
|
787
|
-
`.repeat(2 -
|
|
810
|
+
function W(i) {
|
|
811
|
+
const e = i.value.slice(0, i.selectionStart), t = i.value.slice(i.selectionEnd), n = e.match(/\n*$/), r = t.match(/^\n*/), o = n ? n[0].length : 0, a = r ? r[0].length : 0;
|
|
812
|
+
let s = "", l = "";
|
|
813
|
+
return /\S/.test(e) && o < 2 && (s = `
|
|
814
|
+
`.repeat(2 - o)), /\S/.test(t) && a < 2 && (l = `
|
|
815
|
+
`.repeat(2 - a)), { newlinesToAppend: s, newlinesToPrepend: l };
|
|
788
816
|
}
|
|
789
|
-
function
|
|
817
|
+
function ue(i, e) {
|
|
790
818
|
const t = i.selectionStart, n = i.selectionEnd, r = i.scrollTop;
|
|
791
819
|
e(), i.selectionStart = t, i.selectionEnd = n, i.scrollTop = r;
|
|
792
820
|
}
|
|
793
|
-
function
|
|
794
|
-
const n = i.selectionStart, r = i.selectionEnd, o = n === r,
|
|
795
|
-
let
|
|
796
|
-
for (;
|
|
821
|
+
function V(i, e, t = {}) {
|
|
822
|
+
const n = i.selectionStart, r = i.selectionEnd, o = n === r, a = i.value;
|
|
823
|
+
let s = n;
|
|
824
|
+
for (; s > 0 && a[s - 1] !== `
|
|
797
825
|
`; )
|
|
798
|
-
|
|
826
|
+
s -= 1;
|
|
799
827
|
if (o) {
|
|
800
|
-
let
|
|
801
|
-
for (;
|
|
828
|
+
let c = n;
|
|
829
|
+
for (; c < a.length && a[c] !== `
|
|
802
830
|
`; )
|
|
803
|
-
|
|
804
|
-
i.selectionStart =
|
|
831
|
+
c += 1;
|
|
832
|
+
i.selectionStart = s, i.selectionEnd = c;
|
|
805
833
|
} else
|
|
806
|
-
|
|
834
|
+
he(i);
|
|
807
835
|
const l = e(i);
|
|
808
836
|
if (t.adjustSelection) {
|
|
809
|
-
const
|
|
810
|
-
|
|
837
|
+
const c = i.value.slice(i.selectionStart, i.selectionEnd), d = t.prefix ?? "", p = d.length > 0 && c.startsWith(d), h = t.adjustSelection(
|
|
838
|
+
p,
|
|
811
839
|
n,
|
|
812
840
|
r,
|
|
813
|
-
|
|
841
|
+
s
|
|
814
842
|
);
|
|
815
|
-
return l.selectionStart =
|
|
843
|
+
return l.selectionStart = h.start, l.selectionEnd = h.end, l;
|
|
816
844
|
}
|
|
817
845
|
if (t.prefix) {
|
|
818
846
|
const d = i.value.slice(i.selectionStart, i.selectionEnd).startsWith(t.prefix);
|
|
819
847
|
if (o)
|
|
820
848
|
if (d) {
|
|
821
|
-
const
|
|
822
|
-
l.selectionStart =
|
|
849
|
+
const p = Math.max(n - t.prefix.length, s);
|
|
850
|
+
l.selectionStart = p, l.selectionEnd = p;
|
|
823
851
|
} else {
|
|
824
|
-
const
|
|
825
|
-
l.selectionStart =
|
|
852
|
+
const p = n + t.prefix.length;
|
|
853
|
+
l.selectionStart = p, l.selectionEnd = p;
|
|
826
854
|
}
|
|
827
|
-
else d ? (l.selectionStart = Math.max(n - t.prefix.length,
|
|
855
|
+
else d ? (l.selectionStart = Math.max(n - t.prefix.length, s), l.selectionEnd = Math.max(r - t.prefix.length, s)) : (l.selectionStart = n + t.prefix.length, l.selectionEnd = r + t.prefix.length);
|
|
828
856
|
}
|
|
829
857
|
return l;
|
|
830
858
|
}
|
|
831
|
-
function
|
|
859
|
+
function A(i, e) {
|
|
832
860
|
const {
|
|
833
861
|
prefix: t,
|
|
834
862
|
suffix: n,
|
|
835
863
|
blockPrefix: r,
|
|
836
864
|
blockSuffix: o,
|
|
837
|
-
replaceNext:
|
|
838
|
-
prefixSpace:
|
|
865
|
+
replaceNext: a,
|
|
866
|
+
prefixSpace: s,
|
|
839
867
|
scanFor: l,
|
|
840
|
-
surroundWithNewlines:
|
|
868
|
+
surroundWithNewlines: c,
|
|
841
869
|
trimFirst: d
|
|
842
|
-
} = e,
|
|
843
|
-
let
|
|
844
|
-
` : t, f =
|
|
870
|
+
} = e, p = i.selectionStart, h = i.selectionEnd;
|
|
871
|
+
let m = i.value.slice(i.selectionStart, i.selectionEnd), u = U(m) && r && r.length > 0 ? `${r}
|
|
872
|
+
` : t, f = U(m) && o && o.length > 0 ? `
|
|
845
873
|
${o}` : n;
|
|
846
|
-
if (
|
|
847
|
-
const
|
|
848
|
-
i.selectionStart !== 0 &&
|
|
874
|
+
if (s) {
|
|
875
|
+
const L = i.value[i.selectionStart - 1];
|
|
876
|
+
i.selectionStart !== 0 && L != null && !/\s/.test(L) && (u = ` ${u}`);
|
|
849
877
|
}
|
|
850
|
-
|
|
878
|
+
m = $e(i, u, f, e.multiline);
|
|
851
879
|
let g = i.selectionStart, b = i.selectionEnd;
|
|
852
|
-
const v = !!
|
|
853
|
-
let
|
|
854
|
-
if (
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
if (
|
|
859
|
-
const
|
|
860
|
-
if (
|
|
861
|
-
let
|
|
862
|
-
|
|
880
|
+
const v = !!a && a.length > 0 && f.includes(a) && m.length > 0;
|
|
881
|
+
let k = "", y = "";
|
|
882
|
+
if (c) {
|
|
883
|
+
const L = W(i);
|
|
884
|
+
k = L.newlinesToAppend, y = L.newlinesToPrepend, u = k + t, f += y;
|
|
885
|
+
}
|
|
886
|
+
if (m.startsWith(u) && m.endsWith(f)) {
|
|
887
|
+
const L = m.slice(u.length, m.length - f.length);
|
|
888
|
+
if (p === h) {
|
|
889
|
+
let z = p - u.length;
|
|
890
|
+
z = Math.max(z, g), z = Math.min(z, g + L.length), g = z, b = z;
|
|
863
891
|
} else
|
|
864
|
-
b = g +
|
|
865
|
-
return { text:
|
|
892
|
+
b = g + L.length;
|
|
893
|
+
return { text: L, selectionStart: g, selectionEnd: b };
|
|
866
894
|
}
|
|
867
895
|
if (!v) {
|
|
868
|
-
let
|
|
869
|
-
g =
|
|
870
|
-
const
|
|
871
|
-
if (d &&
|
|
872
|
-
const
|
|
873
|
-
|
|
896
|
+
let L = u + m + f;
|
|
897
|
+
g = p + u.length, b = h + u.length;
|
|
898
|
+
const z = m.match(/^\s*|\s*$/g);
|
|
899
|
+
if (d && z) {
|
|
900
|
+
const ne = z[0] ?? "", ie = z[1] ?? "";
|
|
901
|
+
L = ne + u + m.trim() + f + ie, g += ne.length, b -= ie.length;
|
|
874
902
|
}
|
|
875
|
-
return { text:
|
|
903
|
+
return { text: L, selectionStart: g, selectionEnd: b };
|
|
876
904
|
}
|
|
877
|
-
if (l && (typeof l == "string" ? new RegExp(l) : l).test(
|
|
878
|
-
const
|
|
879
|
-
return g = g +
|
|
905
|
+
if (l && (typeof l == "string" ? new RegExp(l) : l).test(m)) {
|
|
906
|
+
const z = u + f.replace(a, m);
|
|
907
|
+
return g = g + u.length, b = g, { text: z, selectionStart: g, selectionEnd: b };
|
|
880
908
|
}
|
|
881
|
-
const
|
|
882
|
-
return g = g +
|
|
909
|
+
const B = u + m + f, P = f.indexOf(a);
|
|
910
|
+
return g = g + u.length + m.length + P, b = g + a.length, { text: B, selectionStart: g, selectionEnd: b };
|
|
883
911
|
}
|
|
884
|
-
function
|
|
912
|
+
function K(i, e) {
|
|
885
913
|
const { prefix: t, suffix: n, surroundWithNewlines: r } = e;
|
|
886
|
-
let o = i.value.slice(i.selectionStart, i.selectionEnd),
|
|
914
|
+
let o = i.value.slice(i.selectionStart, i.selectionEnd), a = i.selectionStart, s = i.selectionEnd;
|
|
887
915
|
const l = o.split(`
|
|
888
916
|
`);
|
|
889
917
|
if (l.every((d) => d.startsWith(t) && (!n || d.endsWith(n))))
|
|
890
918
|
o = l.map((d) => {
|
|
891
|
-
let
|
|
892
|
-
return n && (
|
|
919
|
+
let p = d.slice(t.length);
|
|
920
|
+
return n && (p = p.slice(0, p.length - n.length)), p;
|
|
893
921
|
}).join(`
|
|
894
|
-
`),
|
|
922
|
+
`), s = a + o.length;
|
|
895
923
|
else if (o = l.map((d) => t + d + (n ?? "")).join(`
|
|
896
924
|
`), r) {
|
|
897
|
-
const { newlinesToAppend: d, newlinesToPrepend:
|
|
898
|
-
|
|
925
|
+
const { newlinesToAppend: d, newlinesToPrepend: p } = W(i);
|
|
926
|
+
a += d.length, s = a + o.length, o = d + o + p;
|
|
899
927
|
}
|
|
900
|
-
return { text: o, selectionStart:
|
|
928
|
+
return { text: o, selectionStart: a, selectionEnd: s };
|
|
901
929
|
}
|
|
902
|
-
function
|
|
930
|
+
function re(i) {
|
|
903
931
|
const e = i.split(`
|
|
904
932
|
`), t = /^\d+\.\s+/, n = e.every((o) => t.test(o));
|
|
905
933
|
return {
|
|
@@ -908,7 +936,7 @@ function ne(i) {
|
|
|
908
936
|
processed: n
|
|
909
937
|
};
|
|
910
938
|
}
|
|
911
|
-
function
|
|
939
|
+
function oe(i) {
|
|
912
940
|
const e = i.split(`
|
|
913
941
|
`), t = "- ", n = e.every((o) => o.startsWith(t));
|
|
914
942
|
return {
|
|
@@ -917,176 +945,176 @@ function ie(i) {
|
|
|
917
945
|
processed: n
|
|
918
946
|
};
|
|
919
947
|
}
|
|
920
|
-
function
|
|
948
|
+
function R(i, e) {
|
|
921
949
|
return e ? "- " : `${i + 1}. `;
|
|
922
950
|
}
|
|
923
951
|
function Me(i, e) {
|
|
924
952
|
let t, n, r;
|
|
925
|
-
return i.orderedList ? (t =
|
|
953
|
+
return i.orderedList ? (t = re(e), n = oe(t.text), r = n.text) : (t = oe(e), n = re(t.text), r = n.text), [t, n, r];
|
|
926
954
|
}
|
|
927
955
|
function Ae(i, e) {
|
|
928
956
|
const t = i.selectionStart === i.selectionEnd;
|
|
929
957
|
let n = i.selectionStart, r = i.selectionEnd;
|
|
930
|
-
|
|
931
|
-
const o = i.value.slice(i.selectionStart, i.selectionEnd), [
|
|
932
|
-
`).map((f, g) => `${
|
|
933
|
-
if (
|
|
934
|
-
return t ? (n = Math.max(n -
|
|
935
|
-
const { newlinesToAppend:
|
|
936
|
-
`) +
|
|
958
|
+
he(i);
|
|
959
|
+
const o = i.value.slice(i.selectionStart, i.selectionEnd), [a, s, l] = Me(e, o), c = l.split(`
|
|
960
|
+
`).map((f, g) => `${R(g, e.unorderedList)}${f}`), d = c.reduce((f, g, b) => f + R(b, e.unorderedList).length, 0), p = c.reduce((f, g, b) => f + R(b, !e.unorderedList).length, 0);
|
|
961
|
+
if (a.processed)
|
|
962
|
+
return t ? (n = Math.max(n - R(0, e.unorderedList).length, 0), r = n) : (n = i.selectionStart, r = i.selectionEnd - d), { text: l, selectionStart: n, selectionEnd: r };
|
|
963
|
+
const { newlinesToAppend: h, newlinesToPrepend: m } = W(i), u = h + c.join(`
|
|
964
|
+
`) + m;
|
|
937
965
|
return t ? (n = Math.max(
|
|
938
|
-
n +
|
|
966
|
+
n + R(0, e.unorderedList).length + h.length,
|
|
939
967
|
0
|
|
940
|
-
), r = n) :
|
|
968
|
+
), r = n) : s.processed ? (n = Math.max(i.selectionStart + h.length, 0), r = i.selectionEnd + h.length + d - p) : (n = Math.max(i.selectionStart + h.length, 0), r = i.selectionEnd + h.length + d), { text: u, selectionStart: n, selectionEnd: r };
|
|
941
969
|
}
|
|
942
|
-
function
|
|
943
|
-
const t =
|
|
970
|
+
function fe(i, e) {
|
|
971
|
+
const t = V(
|
|
944
972
|
i,
|
|
945
973
|
(n) => Ae(n, e),
|
|
946
974
|
{
|
|
947
|
-
adjustSelection: (n, r, o,
|
|
948
|
-
const
|
|
975
|
+
adjustSelection: (n, r, o, a) => {
|
|
976
|
+
const s = i.value.slice(a, i.selectionEnd), l = /^\d+\.\s+/, c = /^- /, d = l.test(s), p = c.test(s), h = e.orderedList && d || e.unorderedList && p;
|
|
949
977
|
if (r === o) {
|
|
950
|
-
if (
|
|
951
|
-
const f =
|
|
978
|
+
if (h) {
|
|
979
|
+
const f = s.match(e.orderedList ? l : c), g = f ? f[0].length : 0;
|
|
952
980
|
return {
|
|
953
|
-
start: Math.max(r - g,
|
|
954
|
-
end: Math.max(r - g,
|
|
981
|
+
start: Math.max(r - g, a),
|
|
982
|
+
end: Math.max(r - g, a)
|
|
955
983
|
};
|
|
956
984
|
}
|
|
957
|
-
if (d ||
|
|
958
|
-
const f =
|
|
985
|
+
if (d || p) {
|
|
986
|
+
const f = s.match(d ? l : c), g = f ? f[0].length : 0, v = (e.unorderedList ? 2 : 3) - g;
|
|
959
987
|
return {
|
|
960
988
|
start: r + v,
|
|
961
989
|
end: r + v
|
|
962
990
|
};
|
|
963
991
|
}
|
|
964
|
-
const
|
|
992
|
+
const u = e.unorderedList ? 2 : 3;
|
|
965
993
|
return {
|
|
966
|
-
start: r +
|
|
967
|
-
end: r +
|
|
994
|
+
start: r + u,
|
|
995
|
+
end: r + u
|
|
968
996
|
};
|
|
969
997
|
}
|
|
970
|
-
if (
|
|
971
|
-
const
|
|
998
|
+
if (h) {
|
|
999
|
+
const u = s.match(e.orderedList ? l : c), f = u ? u[0].length : 0;
|
|
972
1000
|
return {
|
|
973
|
-
start: Math.max(r - f,
|
|
974
|
-
end: Math.max(o - f,
|
|
1001
|
+
start: Math.max(r - f, a),
|
|
1002
|
+
end: Math.max(o - f, a)
|
|
975
1003
|
};
|
|
976
1004
|
}
|
|
977
|
-
if (d ||
|
|
978
|
-
const
|
|
1005
|
+
if (d || p) {
|
|
1006
|
+
const u = s.match(d ? l : c), f = u ? u[0].length : 0, b = (e.unorderedList ? 2 : 3) - f;
|
|
979
1007
|
return {
|
|
980
1008
|
start: r + b,
|
|
981
1009
|
end: o + b
|
|
982
1010
|
};
|
|
983
1011
|
}
|
|
984
|
-
const
|
|
1012
|
+
const m = e.unorderedList ? 2 : 3;
|
|
985
1013
|
return {
|
|
986
|
-
start: r +
|
|
987
|
-
end: o +
|
|
1014
|
+
start: r + m,
|
|
1015
|
+
end: o + m
|
|
988
1016
|
};
|
|
989
1017
|
},
|
|
990
1018
|
prefix: e.unorderedList ? "- " : "1. "
|
|
991
1019
|
}
|
|
992
1020
|
);
|
|
993
|
-
|
|
1021
|
+
H(i, t);
|
|
994
1022
|
}
|
|
995
1023
|
function _e(i, e) {
|
|
996
|
-
const t =
|
|
1024
|
+
const t = C[e];
|
|
997
1025
|
if (!t) return !1;
|
|
998
1026
|
const n = t.prefix ?? "", r = t.suffix ?? "";
|
|
999
1027
|
return n ? r ? i.startsWith(n) && i.endsWith(r) : i.startsWith(n) : !1;
|
|
1000
1028
|
}
|
|
1001
|
-
function
|
|
1029
|
+
function Z(i) {
|
|
1002
1030
|
if (!i) return [];
|
|
1003
1031
|
const e = [], { selectionStart: t, selectionEnd: n, value: r } = i, o = r.split(`
|
|
1004
1032
|
`);
|
|
1005
|
-
let
|
|
1006
|
-
for (const
|
|
1007
|
-
if (t >=
|
|
1008
|
-
|
|
1033
|
+
let a = 0, s = "";
|
|
1034
|
+
for (const p of o) {
|
|
1035
|
+
if (t >= a && t <= a + p.length) {
|
|
1036
|
+
s = p;
|
|
1009
1037
|
break;
|
|
1010
1038
|
}
|
|
1011
|
-
|
|
1039
|
+
a += p.length + 1;
|
|
1012
1040
|
}
|
|
1013
|
-
|
|
1014
|
-
const l = Math.max(0, t - 10),
|
|
1041
|
+
s.startsWith("- ") && (s.startsWith("- [ ] ") || s.startsWith("- [x] ") ? e.push("task-list") : e.push("bullet-list")), /^\d+\.\s/.test(s) && e.push("numbered-list"), s.startsWith("> ") && e.push("quote"), s.startsWith("### ") ? e.push("header-3") : s.startsWith("## ") ? e.push("header-2") : s.startsWith("# ") && e.push("header");
|
|
1042
|
+
const l = Math.max(0, t - 10), c = Math.min(r.length, n + 10), d = r.slice(l, c);
|
|
1015
1043
|
if (d.includes("**")) {
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1044
|
+
const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100)), m = p.lastIndexOf("**"), u = h.indexOf("**");
|
|
1045
|
+
m !== -1 && u !== -1 && e.push("bold");
|
|
1018
1046
|
}
|
|
1019
1047
|
if (d.includes("_")) {
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1048
|
+
const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100)), m = p.lastIndexOf("_"), u = h.indexOf("_");
|
|
1049
|
+
m !== -1 && u !== -1 && e.push("italic");
|
|
1022
1050
|
}
|
|
1023
1051
|
if (d.includes("`")) {
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1052
|
+
const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100));
|
|
1053
|
+
p.includes("`") && h.includes("`") && e.push("code");
|
|
1026
1054
|
}
|
|
1027
1055
|
if (d.includes("[") && d.includes("]")) {
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1056
|
+
const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100)), m = p.lastIndexOf("["), u = h.indexOf("]");
|
|
1057
|
+
m !== -1 && u !== -1 && r.slice(n + u + 1, n + u + 10).startsWith("(") && e.push("link");
|
|
1030
1058
|
}
|
|
1031
1059
|
return e;
|
|
1032
1060
|
}
|
|
1033
|
-
function
|
|
1034
|
-
return
|
|
1061
|
+
function ge(i, e) {
|
|
1062
|
+
return Z(i).includes(e);
|
|
1035
1063
|
}
|
|
1036
|
-
function
|
|
1064
|
+
function be(i, e = {}) {
|
|
1037
1065
|
if (!i) return;
|
|
1038
|
-
const { toWord: t, toLine: n, toFormat: r } = e, { selectionStart: o, selectionEnd:
|
|
1066
|
+
const { toWord: t, toLine: n, toFormat: r } = e, { selectionStart: o, selectionEnd: a, value: s } = i;
|
|
1039
1067
|
if (n) {
|
|
1040
|
-
const l =
|
|
1068
|
+
const l = s.split(`
|
|
1041
1069
|
`);
|
|
1042
|
-
let
|
|
1043
|
-
for (const
|
|
1044
|
-
if (o >=
|
|
1045
|
-
|
|
1070
|
+
let c = 0, d = 0, p = 0;
|
|
1071
|
+
for (const h of l) {
|
|
1072
|
+
if (o >= p && o <= p + h.length) {
|
|
1073
|
+
c = p, d = p + h.length;
|
|
1046
1074
|
break;
|
|
1047
1075
|
}
|
|
1048
|
-
|
|
1076
|
+
p += h.length + 1;
|
|
1049
1077
|
}
|
|
1050
|
-
i.selectionStart =
|
|
1078
|
+
i.selectionStart = c, i.selectionEnd = d;
|
|
1051
1079
|
return;
|
|
1052
1080
|
}
|
|
1053
|
-
if (r && _e(
|
|
1054
|
-
const l =
|
|
1055
|
-
i.selectionStart = Math.max(0, o -
|
|
1081
|
+
if (r && _e(s.slice(o, a), r)) {
|
|
1082
|
+
const l = C[r], c = (l.prefix ?? "").length, d = (l.suffix ?? "").length;
|
|
1083
|
+
i.selectionStart = Math.max(0, o - c), i.selectionEnd = Math.min(s.length, a + d);
|
|
1056
1084
|
return;
|
|
1057
1085
|
}
|
|
1058
|
-
if (t && o ===
|
|
1059
|
-
let l = o,
|
|
1060
|
-
for (; l > 0 && !/\s/.test(
|
|
1086
|
+
if (t && o === a) {
|
|
1087
|
+
let l = o, c = a;
|
|
1088
|
+
for (; l > 0 && !/\s/.test(s[l - 1]); )
|
|
1061
1089
|
l -= 1;
|
|
1062
|
-
for (;
|
|
1063
|
-
|
|
1064
|
-
i.selectionStart = l, i.selectionEnd =
|
|
1090
|
+
for (; c < s.length && !/\s/.test(s[c]); )
|
|
1091
|
+
c += 1;
|
|
1092
|
+
i.selectionStart = l, i.selectionEnd = c;
|
|
1065
1093
|
}
|
|
1066
1094
|
}
|
|
1067
|
-
function
|
|
1095
|
+
function T(i) {
|
|
1068
1096
|
return !!i && !i.disabled && !i.readOnly;
|
|
1069
1097
|
}
|
|
1070
|
-
function
|
|
1071
|
-
if (!
|
|
1072
|
-
|
|
1073
|
-
const e = E(
|
|
1074
|
-
|
|
1098
|
+
function J(i) {
|
|
1099
|
+
if (!T(i)) return;
|
|
1100
|
+
x("toggleBold", "Starting"), F(i, "Before");
|
|
1101
|
+
const e = E(C.bold), t = A(i, e);
|
|
1102
|
+
q(t), H(i, t), F(i, "After");
|
|
1075
1103
|
}
|
|
1076
|
-
function
|
|
1077
|
-
if (!
|
|
1078
|
-
const e = E(
|
|
1079
|
-
|
|
1104
|
+
function G(i) {
|
|
1105
|
+
if (!T(i)) return;
|
|
1106
|
+
const e = E(C.italic), t = A(i, e);
|
|
1107
|
+
H(i, t);
|
|
1080
1108
|
}
|
|
1081
|
-
function
|
|
1082
|
-
if (!
|
|
1083
|
-
const e = E(
|
|
1084
|
-
|
|
1109
|
+
function ve(i) {
|
|
1110
|
+
if (!T(i)) return;
|
|
1111
|
+
const e = E(C.code), t = A(i, e);
|
|
1112
|
+
H(i, t);
|
|
1085
1113
|
}
|
|
1086
|
-
function
|
|
1087
|
-
if (!
|
|
1114
|
+
function Q(i, e = {}) {
|
|
1115
|
+
if (!T(i)) return;
|
|
1088
1116
|
const t = i.value.slice(i.selectionStart, i.selectionEnd);
|
|
1089
|
-
let n = E(
|
|
1117
|
+
let n = E(C.link);
|
|
1090
1118
|
if (t && /^https?:\/\//.test(t) && !e.url ? n = {
|
|
1091
1119
|
...n,
|
|
1092
1120
|
suffix: `](${t})`,
|
|
@@ -1096,48 +1124,48 @@ function Z(i, e = {}) {
|
|
|
1096
1124
|
suffix: `](${e.url})`,
|
|
1097
1125
|
replaceNext: ""
|
|
1098
1126
|
}), e.text && !t) {
|
|
1099
|
-
const
|
|
1100
|
-
i.value = i.value.slice(0,
|
|
1127
|
+
const a = i.selectionStart;
|
|
1128
|
+
i.value = i.value.slice(0, a) + e.text + i.value.slice(a), i.selectionStart = a, i.selectionEnd = a + e.text.length;
|
|
1101
1129
|
}
|
|
1102
|
-
const o =
|
|
1103
|
-
|
|
1130
|
+
const o = A(i, n);
|
|
1131
|
+
H(i, o);
|
|
1104
1132
|
}
|
|
1105
|
-
function
|
|
1106
|
-
if (!
|
|
1107
|
-
const e = E(
|
|
1108
|
-
|
|
1133
|
+
function X(i) {
|
|
1134
|
+
if (!T(i)) return;
|
|
1135
|
+
const e = E(C.bulletList);
|
|
1136
|
+
fe(i, e);
|
|
1109
1137
|
}
|
|
1110
|
-
function
|
|
1111
|
-
if (!
|
|
1112
|
-
const e = E(
|
|
1113
|
-
|
|
1138
|
+
function Y(i) {
|
|
1139
|
+
if (!T(i)) return;
|
|
1140
|
+
const e = E(C.numberedList);
|
|
1141
|
+
fe(i, e);
|
|
1114
1142
|
}
|
|
1115
|
-
function
|
|
1116
|
-
if (!
|
|
1117
|
-
|
|
1118
|
-
const e = E(
|
|
1143
|
+
function ee(i) {
|
|
1144
|
+
if (!T(i)) return;
|
|
1145
|
+
x("toggleQuote", "Starting"), F(i, "Initial");
|
|
1146
|
+
const e = E(C.quote), t = V(
|
|
1119
1147
|
i,
|
|
1120
|
-
(n) =>
|
|
1148
|
+
(n) => K(n, e),
|
|
1121
1149
|
{ prefix: e.prefix }
|
|
1122
1150
|
);
|
|
1123
|
-
|
|
1151
|
+
q(t), H(i, t), F(i, "Final");
|
|
1124
1152
|
}
|
|
1125
|
-
function
|
|
1126
|
-
if (!
|
|
1127
|
-
const e = E(
|
|
1153
|
+
function te(i) {
|
|
1154
|
+
if (!T(i)) return;
|
|
1155
|
+
const e = E(C.taskList), t = V(
|
|
1128
1156
|
i,
|
|
1129
|
-
(n) =>
|
|
1157
|
+
(n) => K(n, e),
|
|
1130
1158
|
{ prefix: e.prefix }
|
|
1131
1159
|
);
|
|
1132
|
-
|
|
1160
|
+
H(i, t);
|
|
1133
1161
|
}
|
|
1134
|
-
function
|
|
1135
|
-
if (!
|
|
1136
|
-
const e = E(
|
|
1137
|
-
|
|
1162
|
+
function we(i) {
|
|
1163
|
+
if (!T(i)) return;
|
|
1164
|
+
const e = E(C.strikethrough), t = A(i, e);
|
|
1165
|
+
H(i, t);
|
|
1138
1166
|
}
|
|
1139
|
-
function
|
|
1140
|
-
if (!
|
|
1167
|
+
function ke(i) {
|
|
1168
|
+
if (!T(i)) return;
|
|
1141
1169
|
const e = i.selectionStart, n = i.value.slice(0, e), o = (n.length > 0 && !n.endsWith(`
|
|
1142
1170
|
`) ? `
|
|
1143
1171
|
` : "") + `
|
|
@@ -1157,27 +1185,27 @@ function Pe(i, e, t) {
|
|
|
1157
1185
|
r += 1;
|
|
1158
1186
|
return { lineStart: n, lineEnd: r };
|
|
1159
1187
|
}
|
|
1160
|
-
function
|
|
1161
|
-
if (!
|
|
1162
|
-
(e < 1 || e > 6) && (e = 1),
|
|
1163
|
-
const n = `header${e === 1 ? "1" : e}`, r = E(
|
|
1164
|
-
|
|
1165
|
-
const o = i.value,
|
|
1166
|
-
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
const f =
|
|
1188
|
+
function O(i, e = 1, t = !1) {
|
|
1189
|
+
if (!T(i)) return;
|
|
1190
|
+
(e < 1 || e > 6) && (e = 1), x("insertHeader", "============ START ============"), x("insertHeader", `Level: ${e}, Toggle: ${t}`), x("insertHeader", `Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);
|
|
1191
|
+
const n = `header${e === 1 ? "1" : e}`, r = E(C[n] || C.header1);
|
|
1192
|
+
x("insertHeader", `Style prefix: "${r.prefix}"`);
|
|
1193
|
+
const o = i.value, a = i.selectionStart, s = i.selectionEnd, { lineStart: l, lineEnd: c } = Pe(o, a, s), d = o.slice(l, c);
|
|
1194
|
+
x("insertHeader", `Current line (before): "${d}"`);
|
|
1195
|
+
const p = d.match(/^(#{1,6})\s*/), h = p ? p[1].length : 0, m = p ? p[0].length : 0;
|
|
1196
|
+
x("insertHeader", `Existing header match: ${p ? p[0] : "none"}`), x("insertHeader", `Existing level: ${h}`), x("insertHeader", `Target level: ${e}`);
|
|
1197
|
+
const u = t && h === e;
|
|
1198
|
+
x("insertHeader", `Should toggle OFF: ${u}`);
|
|
1199
|
+
const f = V(
|
|
1172
1200
|
i,
|
|
1173
1201
|
(g) => {
|
|
1174
1202
|
const b = g.value.slice(g.selectionStart, g.selectionEnd);
|
|
1175
|
-
|
|
1203
|
+
x("insertHeader", `Line in operation: "${b}"`);
|
|
1176
1204
|
const v = b.replace(/^#{1,6}\s*/, "");
|
|
1177
|
-
|
|
1178
|
-
let
|
|
1179
|
-
return
|
|
1180
|
-
text:
|
|
1205
|
+
x("insertHeader", `Cleaned line: "${v}"`);
|
|
1206
|
+
let k;
|
|
1207
|
+
return u ? (x("insertHeader", "ACTION: Toggling OFF - removing header"), k = v) : h > 0 ? (x("insertHeader", `ACTION: Replacing H${h} with H${e}`), k = r.prefix + v) : (x("insertHeader", "ACTION: Adding new header"), k = r.prefix + v), x("insertHeader", `New line: "${k}"`), {
|
|
1208
|
+
text: k,
|
|
1181
1209
|
selectionStart: g.selectionStart,
|
|
1182
1210
|
selectionEnd: g.selectionEnd
|
|
1183
1211
|
};
|
|
@@ -1185,18 +1213,18 @@ function R(i, e = 1, t = !1) {
|
|
|
1185
1213
|
{
|
|
1186
1214
|
prefix: r.prefix,
|
|
1187
1215
|
adjustSelection: (g, b, v) => {
|
|
1188
|
-
if (
|
|
1189
|
-
const
|
|
1216
|
+
if (x("insertHeader", `Adjusting selection with existing prefix length ${m}`), u) {
|
|
1217
|
+
const k = Math.max(b - m, l);
|
|
1190
1218
|
return {
|
|
1191
|
-
start:
|
|
1192
|
-
end: b === v ?
|
|
1219
|
+
start: k,
|
|
1220
|
+
end: b === v ? k : Math.max(v - m, l)
|
|
1193
1221
|
};
|
|
1194
1222
|
}
|
|
1195
|
-
if (
|
|
1196
|
-
const
|
|
1223
|
+
if (m > 0) {
|
|
1224
|
+
const k = r.prefix.length - m;
|
|
1197
1225
|
return {
|
|
1198
|
-
start: b +
|
|
1199
|
-
end: v +
|
|
1226
|
+
start: b + k,
|
|
1227
|
+
end: v + k
|
|
1200
1228
|
};
|
|
1201
1229
|
}
|
|
1202
1230
|
return {
|
|
@@ -1206,78 +1234,78 @@ function R(i, e = 1, t = !1) {
|
|
|
1206
1234
|
}
|
|
1207
1235
|
}
|
|
1208
1236
|
);
|
|
1209
|
-
|
|
1237
|
+
q(f), x("insertHeader", "============ END ============"), H(i, f);
|
|
1210
1238
|
}
|
|
1211
|
-
function
|
|
1212
|
-
|
|
1239
|
+
function ye(i) {
|
|
1240
|
+
O(i, 1, !0);
|
|
1213
1241
|
}
|
|
1214
|
-
function
|
|
1215
|
-
|
|
1242
|
+
function xe(i) {
|
|
1243
|
+
O(i, 2, !0);
|
|
1216
1244
|
}
|
|
1217
|
-
function
|
|
1218
|
-
|
|
1245
|
+
function ze(i) {
|
|
1246
|
+
O(i, 3, !0);
|
|
1219
1247
|
}
|
|
1220
|
-
function
|
|
1221
|
-
if (!
|
|
1248
|
+
function Le(i, e) {
|
|
1249
|
+
if (!T(i)) return;
|
|
1222
1250
|
const t = E(e);
|
|
1223
1251
|
let n;
|
|
1224
1252
|
if (t.multiline) {
|
|
1225
1253
|
const r = i.value.slice(i.selectionStart, i.selectionEnd);
|
|
1226
|
-
|
|
1254
|
+
U(r) ? n = K(i, t) : n = A(i, t);
|
|
1227
1255
|
} else
|
|
1228
|
-
n =
|
|
1229
|
-
|
|
1256
|
+
n = A(i, t);
|
|
1257
|
+
H(i, n);
|
|
1230
1258
|
}
|
|
1231
|
-
const
|
|
1232
|
-
toggleBold:
|
|
1233
|
-
toggleItalic:
|
|
1234
|
-
toggleCode:
|
|
1235
|
-
toggleStrikethrough:
|
|
1236
|
-
insertLink:
|
|
1237
|
-
insertHorizontalRule:
|
|
1238
|
-
toggleBulletList:
|
|
1239
|
-
toggleNumberedList:
|
|
1240
|
-
toggleQuote:
|
|
1241
|
-
toggleTaskList:
|
|
1242
|
-
insertHeader:
|
|
1243
|
-
toggleH1:
|
|
1244
|
-
toggleH2:
|
|
1245
|
-
toggleH3:
|
|
1246
|
-
getActiveFormats:
|
|
1247
|
-
hasFormat:
|
|
1248
|
-
expandSelection:
|
|
1249
|
-
applyCustomFormat:
|
|
1250
|
-
preserveSelection:
|
|
1251
|
-
setUndoMethod:
|
|
1252
|
-
setDebugMode:
|
|
1253
|
-
getDebugMode:
|
|
1259
|
+
const ae = {
|
|
1260
|
+
toggleBold: J,
|
|
1261
|
+
toggleItalic: G,
|
|
1262
|
+
toggleCode: ve,
|
|
1263
|
+
toggleStrikethrough: we,
|
|
1264
|
+
insertLink: Q,
|
|
1265
|
+
insertHorizontalRule: ke,
|
|
1266
|
+
toggleBulletList: X,
|
|
1267
|
+
toggleNumberedList: Y,
|
|
1268
|
+
toggleQuote: ee,
|
|
1269
|
+
toggleTaskList: te,
|
|
1270
|
+
insertHeader: O,
|
|
1271
|
+
toggleH1: ye,
|
|
1272
|
+
toggleH2: xe,
|
|
1273
|
+
toggleH3: ze,
|
|
1274
|
+
getActiveFormats: Z,
|
|
1275
|
+
hasFormat: ge,
|
|
1276
|
+
expandSelection: be,
|
|
1277
|
+
applyCustomFormat: Le,
|
|
1278
|
+
preserveSelection: ue,
|
|
1279
|
+
setUndoMethod: me,
|
|
1280
|
+
setDebugMode: de,
|
|
1281
|
+
getDebugMode: D
|
|
1254
1282
|
}, Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1255
1283
|
__proto__: null,
|
|
1256
|
-
actions:
|
|
1257
|
-
applyCustomFormat:
|
|
1258
|
-
default:
|
|
1259
|
-
expandSelection:
|
|
1260
|
-
getActiveFormats:
|
|
1261
|
-
getDebugMode:
|
|
1262
|
-
getUndoMethod:
|
|
1263
|
-
hasFormat:
|
|
1264
|
-
insertHeader:
|
|
1265
|
-
insertHorizontalRule:
|
|
1266
|
-
insertLink:
|
|
1267
|
-
preserveSelection:
|
|
1268
|
-
setDebugMode:
|
|
1269
|
-
setUndoMethod:
|
|
1270
|
-
toggleBold:
|
|
1271
|
-
toggleBulletList:
|
|
1272
|
-
toggleCode:
|
|
1273
|
-
toggleH1:
|
|
1274
|
-
toggleH2:
|
|
1275
|
-
toggleH3:
|
|
1276
|
-
toggleItalic:
|
|
1277
|
-
toggleNumberedList:
|
|
1278
|
-
toggleQuote:
|
|
1279
|
-
toggleStrikethrough:
|
|
1280
|
-
toggleTaskList:
|
|
1284
|
+
actions: ae,
|
|
1285
|
+
applyCustomFormat: Le,
|
|
1286
|
+
default: ae,
|
|
1287
|
+
expandSelection: be,
|
|
1288
|
+
getActiveFormats: Z,
|
|
1289
|
+
getDebugMode: D,
|
|
1290
|
+
getUndoMethod: Te,
|
|
1291
|
+
hasFormat: ge,
|
|
1292
|
+
insertHeader: O,
|
|
1293
|
+
insertHorizontalRule: ke,
|
|
1294
|
+
insertLink: Q,
|
|
1295
|
+
preserveSelection: ue,
|
|
1296
|
+
setDebugMode: de,
|
|
1297
|
+
setUndoMethod: me,
|
|
1298
|
+
toggleBold: J,
|
|
1299
|
+
toggleBulletList: X,
|
|
1300
|
+
toggleCode: ve,
|
|
1301
|
+
toggleH1: ye,
|
|
1302
|
+
toggleH2: xe,
|
|
1303
|
+
toggleH3: ze,
|
|
1304
|
+
toggleItalic: G,
|
|
1305
|
+
toggleNumberedList: Y,
|
|
1306
|
+
toggleQuote: ee,
|
|
1307
|
+
toggleStrikethrough: we,
|
|
1308
|
+
toggleTaskList: te
|
|
1281
1309
|
}, Symbol.toStringTag, { value: "Module" })), Be = {
|
|
1282
1310
|
b: "toggleBold",
|
|
1283
1311
|
i: "toggleItalic",
|
|
@@ -1286,39 +1314,39 @@ const re = {
|
|
|
1286
1314
|
Digit7: "toggleNumberedList",
|
|
1287
1315
|
Digit8: "toggleBulletList"
|
|
1288
1316
|
};
|
|
1289
|
-
class
|
|
1317
|
+
class Se {
|
|
1290
1318
|
constructor(e) {
|
|
1291
1319
|
this.editor = e, this.textarea = e.textarea;
|
|
1292
1320
|
}
|
|
1293
1321
|
handleKeydown(e) {
|
|
1294
1322
|
if (!(navigator.platform.toLowerCase().includes("mac") ? e.metaKey : e.ctrlKey)) return !1;
|
|
1295
|
-
const o = e.key.toLowerCase(),
|
|
1296
|
-
return !
|
|
1323
|
+
const o = e.key.toLowerCase(), a = Re[e.code], s = a ?? Be[o];
|
|
1324
|
+
return !s || a && !e.shiftKey || !a && (o === "b" || o === "i" || o === "k") && e.shiftKey ? !1 : (e.preventDefault(), this.editor.toolbar ? this.editor.toolbar.handleAction(s) : this.handleAction(s), !0);
|
|
1297
1325
|
}
|
|
1298
1326
|
handleAction(e) {
|
|
1299
1327
|
const t = this.textarea;
|
|
1300
1328
|
if (t) {
|
|
1301
1329
|
switch (t.focus(), e) {
|
|
1302
1330
|
case "toggleBold":
|
|
1303
|
-
|
|
1331
|
+
J(t);
|
|
1304
1332
|
break;
|
|
1305
1333
|
case "toggleItalic":
|
|
1306
|
-
|
|
1334
|
+
G(t);
|
|
1307
1335
|
break;
|
|
1308
1336
|
case "insertLink":
|
|
1309
|
-
|
|
1337
|
+
Q(t);
|
|
1310
1338
|
break;
|
|
1311
1339
|
case "toggleBulletList":
|
|
1312
|
-
|
|
1340
|
+
X(t);
|
|
1313
1341
|
break;
|
|
1314
1342
|
case "toggleNumberedList":
|
|
1315
|
-
|
|
1343
|
+
Y(t);
|
|
1316
1344
|
break;
|
|
1317
1345
|
case "toggleQuote":
|
|
1318
|
-
|
|
1346
|
+
ee(t);
|
|
1319
1347
|
break;
|
|
1320
1348
|
case "toggleTaskList":
|
|
1321
|
-
|
|
1349
|
+
te(t);
|
|
1322
1350
|
break;
|
|
1323
1351
|
}
|
|
1324
1352
|
t.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
@@ -1327,7 +1355,7 @@ class ze {
|
|
|
1327
1355
|
destroy() {
|
|
1328
1356
|
}
|
|
1329
1357
|
}
|
|
1330
|
-
const
|
|
1358
|
+
const I = {
|
|
1331
1359
|
name: "solar",
|
|
1332
1360
|
colors: {
|
|
1333
1361
|
bgPrimary: "#faf0ca",
|
|
@@ -1378,7 +1406,7 @@ const _ = {
|
|
|
1378
1406
|
border: "rgba(13, 59, 102, 0.25)"
|
|
1379
1407
|
// Table/element borders
|
|
1380
1408
|
}
|
|
1381
|
-
},
|
|
1409
|
+
}, se = {
|
|
1382
1410
|
name: "cave",
|
|
1383
1411
|
colors: {
|
|
1384
1412
|
bgPrimary: "#141E26",
|
|
@@ -1429,15 +1457,15 @@ const _ = {
|
|
|
1429
1457
|
border: "rgba(197, 221, 232, 0.2)"
|
|
1430
1458
|
// Table/element borders
|
|
1431
1459
|
}
|
|
1432
|
-
},
|
|
1433
|
-
solar:
|
|
1434
|
-
cave:
|
|
1460
|
+
}, le = {
|
|
1461
|
+
solar: I,
|
|
1462
|
+
cave: se,
|
|
1435
1463
|
// Aliases for backward compatibility
|
|
1436
|
-
light:
|
|
1437
|
-
dark:
|
|
1464
|
+
light: I,
|
|
1465
|
+
dark: se
|
|
1438
1466
|
};
|
|
1439
|
-
function
|
|
1440
|
-
return typeof i == "string" ? { ...
|
|
1467
|
+
function M(i) {
|
|
1468
|
+
return typeof i == "string" ? { ...le[i] || le.solar, name: i } : i;
|
|
1441
1469
|
}
|
|
1442
1470
|
function Ne(i) {
|
|
1443
1471
|
const e = [];
|
|
@@ -1448,7 +1476,7 @@ function Ne(i) {
|
|
|
1448
1476
|
return e.join(`
|
|
1449
1477
|
`);
|
|
1450
1478
|
}
|
|
1451
|
-
function
|
|
1479
|
+
function ce(i, e = {}) {
|
|
1452
1480
|
return {
|
|
1453
1481
|
...i,
|
|
1454
1482
|
colors: {
|
|
@@ -1465,12 +1493,12 @@ function je(i = {}) {
|
|
|
1465
1493
|
fontFamily: n = '"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',
|
|
1466
1494
|
padding: r = "20px",
|
|
1467
1495
|
theme: o = null,
|
|
1468
|
-
mobile:
|
|
1469
|
-
} = i,
|
|
1496
|
+
mobile: a = {}
|
|
1497
|
+
} = i, s = Object.keys(a).length > 0 ? `
|
|
1470
1498
|
@media (max-width: 640px) {
|
|
1471
1499
|
.marzipan-wrapper .marzipan-input,
|
|
1472
1500
|
.marzipan-wrapper .marzipan-preview {
|
|
1473
|
-
${Object.entries(
|
|
1501
|
+
${Object.entries(a).map(([c, d]) => `${c.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${d} !important;`).join(`
|
|
1474
1502
|
`)}
|
|
1475
1503
|
}
|
|
1476
1504
|
}
|
|
@@ -2246,7 +2274,7 @@ function je(i = {}) {
|
|
|
2246
2274
|
.marzipan-preview .marzipan-table {
|
|
2247
2275
|
border-collapse: collapse !important;
|
|
2248
2276
|
margin: 1em 0 !important;
|
|
2249
|
-
width:
|
|
2277
|
+
width: auto !important;
|
|
2250
2278
|
overflow: auto !important;
|
|
2251
2279
|
display: table !important;
|
|
2252
2280
|
}
|
|
@@ -2276,6 +2304,70 @@ function je(i = {}) {
|
|
|
2276
2304
|
.marzipan-preview .marzipan-table tr {
|
|
2277
2305
|
display: table-row !important;
|
|
2278
2306
|
}
|
|
2307
|
+
|
|
2308
|
+
/* Table alignment (parsed from GFM :--- :---: ---: markers) */
|
|
2309
|
+
.marzipan-preview .marzipan-table th[style*="text-align: center"],
|
|
2310
|
+
.marzipan-preview .marzipan-table td[style*="text-align: center"] {
|
|
2311
|
+
text-align: center !important;
|
|
2312
|
+
}
|
|
2313
|
+
.marzipan-preview .marzipan-table th[style*="text-align: right"],
|
|
2314
|
+
.marzipan-preview .marzipan-table td[style*="text-align: right"] {
|
|
2315
|
+
text-align: right !important;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
/* Table style presets */
|
|
2319
|
+
.marzipan-preview .marzipan-table.mz-table-striped tr:nth-child(odd) td {
|
|
2320
|
+
background: transparent !important;
|
|
2321
|
+
}
|
|
2322
|
+
.marzipan-preview .marzipan-table.mz-table-striped tr:nth-child(even) td {
|
|
2323
|
+
background: var(--bg-secondary, rgba(128,128,128,0.08)) !important;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tr:nth-child(even) td { background: transparent !important; }
|
|
2327
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+1) td { background: rgba(236,72,153,0.10) !important; }
|
|
2328
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+2) td { background: rgba(139,92,246,0.10) !important; }
|
|
2329
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+3) td { background: rgba(6,182,212,0.10) !important; }
|
|
2330
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+4) td { background: rgba(16,185,129,0.10) !important; }
|
|
2331
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+5) td { background: rgba(245,158,11,0.10) !important; }
|
|
2332
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+6) td { background: rgba(59,130,246,0.10) !important; }
|
|
2333
|
+
.marzipan-preview .marzipan-table.mz-table-rainbow th {
|
|
2334
|
+
background: rgba(236,72,153,0.18) !important;
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
.marzipan-preview .marzipan-table.mz-table-minimal {
|
|
2338
|
+
border: none !important;
|
|
2339
|
+
}
|
|
2340
|
+
.marzipan-preview .marzipan-table.mz-table-minimal th,
|
|
2341
|
+
.marzipan-preview .marzipan-table.mz-table-minimal td {
|
|
2342
|
+
border: none !important;
|
|
2343
|
+
border-bottom: 1px solid var(--border, rgba(128,128,128,0.25)) !important;
|
|
2344
|
+
}
|
|
2345
|
+
.marzipan-preview .marzipan-table.mz-table-minimal th {
|
|
2346
|
+
border-bottom: 2px solid var(--border, rgba(128,128,128,0.5)) !important;
|
|
2347
|
+
background: transparent !important;
|
|
2348
|
+
}
|
|
2349
|
+
.marzipan-preview .marzipan-table.mz-table-minimal tr:nth-child(even) td {
|
|
2350
|
+
background: transparent !important;
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
/* Table border style presets */
|
|
2354
|
+
.marzipan-preview .marzipan-table.mz-border-dashed th,
|
|
2355
|
+
.marzipan-preview .marzipan-table.mz-border-dashed td {
|
|
2356
|
+
border-style: dashed !important;
|
|
2357
|
+
}
|
|
2358
|
+
.marzipan-preview .marzipan-table.mz-border-dotted th,
|
|
2359
|
+
.marzipan-preview .marzipan-table.mz-border-dotted td {
|
|
2360
|
+
border-style: dotted !important;
|
|
2361
|
+
}
|
|
2362
|
+
.marzipan-preview .marzipan-table.mz-border-double th,
|
|
2363
|
+
.marzipan-preview .marzipan-table.mz-border-double td {
|
|
2364
|
+
border-style: double !important;
|
|
2365
|
+
border-width: 3px !important;
|
|
2366
|
+
}
|
|
2367
|
+
.marzipan-preview .marzipan-table.mz-border-none th,
|
|
2368
|
+
.marzipan-preview .marzipan-table.mz-border-none td {
|
|
2369
|
+
border-color: transparent !important;
|
|
2370
|
+
}
|
|
2279
2371
|
|
|
2280
2372
|
/* In preview mode - hide table syntax markers */
|
|
2281
2373
|
.marzipan-container.preview-mode .marzipan-wrapper .marzipan-preview .table-row,
|
|
@@ -2298,7 +2390,7 @@ function je(i = {}) {
|
|
|
2298
2390
|
margin: 1em auto;
|
|
2299
2391
|
}
|
|
2300
2392
|
|
|
2301
|
-
${
|
|
2393
|
+
${s}
|
|
2302
2394
|
`;
|
|
2303
2395
|
}
|
|
2304
2396
|
const Oe = `<svg viewBox="0 0 18 18">
|
|
@@ -2548,15 +2640,15 @@ class nt {
|
|
|
2548
2640
|
{ id: "normal", label: "Normal Edit", icon: "✓" },
|
|
2549
2641
|
{ id: "plain", label: "Plain Textarea", icon: "✓" },
|
|
2550
2642
|
{ id: "preview", label: "Preview Mode", icon: "✓" }
|
|
2551
|
-
].forEach((
|
|
2552
|
-
const
|
|
2553
|
-
|
|
2643
|
+
].forEach((a) => {
|
|
2644
|
+
const s = document.createElement("button");
|
|
2645
|
+
s.className = "marzipan-dropdown-item", s.type = "button";
|
|
2554
2646
|
const l = document.createElement("span");
|
|
2555
|
-
l.className = "marzipan-dropdown-check", l.textContent = r ===
|
|
2556
|
-
const
|
|
2557
|
-
|
|
2558
|
-
d.stopPropagation(), this.setViewMode(
|
|
2559
|
-
}), e.appendChild(
|
|
2647
|
+
l.className = "marzipan-dropdown-check", l.textContent = r === a.id ? a.icon : "";
|
|
2648
|
+
const c = document.createElement("span");
|
|
2649
|
+
c.textContent = a.label, s.appendChild(l), s.appendChild(c), r === a.id && s.classList.add("active"), s.addEventListener("click", (d) => {
|
|
2650
|
+
d.stopPropagation(), this.setViewMode(a.id), e.remove(), this.viewModeButton?.classList.remove("dropdown-active"), this.handleDocumentClick && document.removeEventListener("click", this.handleDocumentClick);
|
|
2651
|
+
}), e.appendChild(s);
|
|
2560
2652
|
}), e;
|
|
2561
2653
|
}
|
|
2562
2654
|
setViewMode(e) {
|
|
@@ -2576,9 +2668,9 @@ class nt {
|
|
|
2576
2668
|
this.container && (this.handleDocumentClick && document.removeEventListener("click", this.handleDocumentClick), this.container.remove(), this.container = null, this.buttons = {}, this.viewModeButton = void 0, this.handleDocumentClick = void 0);
|
|
2577
2669
|
}
|
|
2578
2670
|
}
|
|
2579
|
-
let
|
|
2671
|
+
let pe = !1;
|
|
2580
2672
|
function it() {
|
|
2581
|
-
if (
|
|
2673
|
+
if (pe || typeof document > "u") return;
|
|
2582
2674
|
const i = document.createElement("style");
|
|
2583
2675
|
i.className = "marzipan-link-tooltip-styles", i.textContent = `
|
|
2584
2676
|
@supports (position-anchor: --x) and (position-area: center) {
|
|
@@ -2609,7 +2701,7 @@ function it() {
|
|
|
2609
2701
|
display: flex !important;
|
|
2610
2702
|
}
|
|
2611
2703
|
}
|
|
2612
|
-
`, document.head.appendChild(i),
|
|
2704
|
+
`, document.head.appendChild(i), pe = !0;
|
|
2613
2705
|
}
|
|
2614
2706
|
class rt {
|
|
2615
2707
|
constructor(e) {
|
|
@@ -2654,14 +2746,14 @@ class rt {
|
|
|
2654
2746
|
const n = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
2655
2747
|
let r, o = 0;
|
|
2656
2748
|
for (; (r = n.exec(e)) !== null; ) {
|
|
2657
|
-
const
|
|
2658
|
-
if (t >=
|
|
2749
|
+
const a = r.index, s = r.index + r[0].length;
|
|
2750
|
+
if (t >= a && t <= s)
|
|
2659
2751
|
return {
|
|
2660
2752
|
text: r[1],
|
|
2661
2753
|
url: r[2],
|
|
2662
2754
|
index: o,
|
|
2663
|
-
start:
|
|
2664
|
-
end:
|
|
2755
|
+
start: a,
|
|
2756
|
+
end: s
|
|
2665
2757
|
};
|
|
2666
2758
|
o++;
|
|
2667
2759
|
}
|
|
@@ -2710,8 +2802,8 @@ const w = class w {
|
|
|
2710
2802
|
return n.map((o) => {
|
|
2711
2803
|
if (o.MarzipanInstance)
|
|
2712
2804
|
return o.MarzipanInstance.reinit(t), o.MarzipanInstance;
|
|
2713
|
-
const
|
|
2714
|
-
return
|
|
2805
|
+
const a = Object.create(w.prototype);
|
|
2806
|
+
return a._init(o, t), o.MarzipanInstance = a, w.instances.set(o, a), a;
|
|
2715
2807
|
});
|
|
2716
2808
|
}
|
|
2717
2809
|
/**
|
|
@@ -2721,9 +2813,9 @@ const w = class w {
|
|
|
2721
2813
|
_init(e, t = {}) {
|
|
2722
2814
|
this.element = e, this.options = this._mergeOptions(t), this.instanceTheme = this.options.theme ?? null, this.instanceColors = this.options.colors ? { ...this.options.colors } : null, this._appliedThemeColorKeys = /* @__PURE__ */ new Set(), this.instanceId = ++w.instanceCount, this.initialized = !1, this._autoResizeInputHandler = null, this._autoResizeResizeHandler = null, this._minAutoHeight = null, this._maxAutoHeight = null, w.injectStyles(), w.initGlobalListeners();
|
|
2723
2815
|
const n = e.querySelector(".marzipan-container"), r = e.querySelector(".marzipan-wrapper");
|
|
2724
|
-
if (n || r ? this._recoverFromDOM(n, r) : this._buildFromScratch(), this.shortcuts = new
|
|
2725
|
-
const
|
|
2726
|
-
this.toolbar = new nt(this,
|
|
2816
|
+
if (n || r ? this._recoverFromDOM(n, r) : this._buildFromScratch(), this.shortcuts = new Se(this), this.linkTooltip = new rt(this), this.options.toolbar) {
|
|
2817
|
+
const a = typeof this.options.toolbar == "object" ? this.options.toolbar.buttons : null;
|
|
2818
|
+
this.toolbar = new nt(this, a), this.toolbar.create(), this.textarea.addEventListener("selectionchange", () => {
|
|
2727
2819
|
this.toolbar?.updateButtonStates?.();
|
|
2728
2820
|
}), this.textarea.addEventListener("input", () => {
|
|
2729
2821
|
this.toolbar?.updateButtonStates?.();
|
|
@@ -2775,11 +2867,11 @@ const w = class w {
|
|
|
2775
2867
|
// Theme overrides
|
|
2776
2868
|
theme: null,
|
|
2777
2869
|
colors: void 0
|
|
2778
|
-
}, { hooks: n, plugins: r, ...o } = e,
|
|
2870
|
+
}, { hooks: n, plugins: r, ...o } = e, a = {
|
|
2779
2871
|
...t,
|
|
2780
2872
|
...o
|
|
2781
2873
|
};
|
|
2782
|
-
return n && (
|
|
2874
|
+
return n && (a.hooks = { ...n }), Array.isArray(r) && (a.plugins = [...r]), a.theme && typeof a.theme == "object" && (a.theme = { ...a.theme }), a.colors && (a.colors = { ...a.colors }), a;
|
|
2783
2875
|
}
|
|
2784
2876
|
/**
|
|
2785
2877
|
* Apply plugins attached to this editor instance
|
|
@@ -2804,7 +2896,7 @@ const w = class w {
|
|
|
2804
2896
|
}
|
|
2805
2897
|
_resolveTheme() {
|
|
2806
2898
|
let e = this.instanceTheme;
|
|
2807
|
-
return typeof e == "string" && (e =
|
|
2899
|
+
return typeof e == "string" && (e = M(e)), e || (e = w.currentTheme || I), typeof e == "string" && (e = M(e)), this.instanceColors ? ce(e, this.instanceColors) : e;
|
|
2808
2900
|
}
|
|
2809
2901
|
_applyTheme(e) {
|
|
2810
2902
|
if (!e) return;
|
|
@@ -2815,10 +2907,10 @@ const w = class w {
|
|
|
2815
2907
|
this._appliedThemeColorKeys.clear();
|
|
2816
2908
|
const r = t?.colors;
|
|
2817
2909
|
if (r)
|
|
2818
|
-
for (const [o,
|
|
2819
|
-
if (
|
|
2820
|
-
const
|
|
2821
|
-
e.style.setProperty(
|
|
2910
|
+
for (const [o, a] of Object.entries(r)) {
|
|
2911
|
+
if (a == null) continue;
|
|
2912
|
+
const s = `--${o.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
|
|
2913
|
+
e.style.setProperty(s, String(a)), this._appliedThemeColorKeys.add(s);
|
|
2822
2914
|
}
|
|
2823
2915
|
}
|
|
2824
2916
|
/**
|
|
@@ -2879,7 +2971,7 @@ const w = class w {
|
|
|
2879
2971
|
* Update preview with parsed markdown
|
|
2880
2972
|
*/
|
|
2881
2973
|
updatePreview() {
|
|
2882
|
-
const e = this.textarea.value, t = this.textarea.selectionStart, n = this._getCurrentLine(e, t), r =
|
|
2974
|
+
const e = this.textarea.value, t = this.textarea.selectionStart, n = this._getCurrentLine(e, t), r = $.parse(e, n, this.options.showActiveLineRaw);
|
|
2883
2975
|
if (this.preview.innerHTML = r || '<span style="color: #808080;">Start typing...</span>', this.options?.hooks?.afterPreviewRender)
|
|
2884
2976
|
try {
|
|
2885
2977
|
this.options.hooks.afterPreviewRender(this.preview, this);
|
|
@@ -2895,8 +2987,8 @@ const w = class w {
|
|
|
2895
2987
|
_applyCodeBlockBackgrounds() {
|
|
2896
2988
|
const e = this.preview.querySelectorAll(".code-fence");
|
|
2897
2989
|
for (let t = 0; t < e.length - 1; t += 2) {
|
|
2898
|
-
const n = e[t], r = e[t + 1], o = n.parentElement,
|
|
2899
|
-
!o || !
|
|
2990
|
+
const n = e[t], r = e[t + 1], o = n.parentElement, a = r.parentElement;
|
|
2991
|
+
!o || !a || (n.style.display = "block", r.style.display = "block", o.classList.add("code-block-line"), a.classList.add("code-block-line"));
|
|
2900
2992
|
}
|
|
2901
2993
|
}
|
|
2902
2994
|
/**
|
|
@@ -2923,15 +3015,15 @@ const w = class w {
|
|
|
2923
3015
|
e.preventDefault();
|
|
2924
3016
|
const n = this.textarea.selectionStart, r = this.textarea.selectionEnd, o = this.textarea.value;
|
|
2925
3017
|
if (n !== r && e.shiftKey) {
|
|
2926
|
-
const
|
|
2927
|
-
`).map((
|
|
3018
|
+
const a = o.substring(0, n), s = o.substring(n, r), l = o.substring(r), d = s.split(`
|
|
3019
|
+
`).map((p) => p.replace(/^ {2}/, "")).join(`
|
|
2928
3020
|
`);
|
|
2929
|
-
document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value =
|
|
3021
|
+
document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value = a + d + l, this.textarea.selectionStart = n, this.textarea.selectionEnd = n + d.length);
|
|
2930
3022
|
} else if (n !== r) {
|
|
2931
|
-
const
|
|
2932
|
-
`).map((
|
|
3023
|
+
const a = o.substring(0, n), s = o.substring(n, r), l = o.substring(r), d = s.split(`
|
|
3024
|
+
`).map((p) => " " + p).join(`
|
|
2933
3025
|
`);
|
|
2934
|
-
document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value =
|
|
3026
|
+
document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value = a + d + l, this.textarea.selectionStart = n, this.textarea.selectionEnd = n + d.length);
|
|
2935
3027
|
} else
|
|
2936
3028
|
document.execCommand ? document.execCommand("insertText", !1, " ") : (this.textarea.value = o.substring(0, n) + " " + o.substring(r), this.textarea.selectionStart = this.textarea.selectionEnd = n + 2);
|
|
2937
3029
|
this.textarea.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
@@ -2948,7 +3040,7 @@ const w = class w {
|
|
|
2948
3040
|
* @returns {boolean} Whether the event was handled
|
|
2949
3041
|
*/
|
|
2950
3042
|
handleSmartListContinuation() {
|
|
2951
|
-
const e = this.textarea, t = e.selectionStart, n =
|
|
3043
|
+
const e = this.textarea, t = e.selectionStart, n = $.getListContext(e.value, t);
|
|
2952
3044
|
return !n || !n.inList ? !1 : n.content.trim() === "" && t >= n.markerEndPos ? (this.deleteListMarker(n), !0) : (t > n.markerEndPos && t < n.lineEnd ? this.splitListItem(n, t) : this.insertNewListItem(n), n.listType === "numbered" && this.scheduleNumberedListUpdate(), !0);
|
|
2953
3045
|
}
|
|
2954
3046
|
/**
|
|
@@ -2963,7 +3055,7 @@ const w = class w {
|
|
|
2963
3055
|
* @private
|
|
2964
3056
|
*/
|
|
2965
3057
|
insertNewListItem(e) {
|
|
2966
|
-
const t =
|
|
3058
|
+
const t = $.createNewListItem(e);
|
|
2967
3059
|
document.execCommand("insertText", !1, `
|
|
2968
3060
|
` + t), this.textarea.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
2969
3061
|
}
|
|
@@ -2974,7 +3066,7 @@ const w = class w {
|
|
|
2974
3066
|
splitListItem(e, t) {
|
|
2975
3067
|
const n = e.content.substring(t - e.markerEndPos);
|
|
2976
3068
|
this.textarea.setSelectionRange(t, e.lineEnd), document.execCommand("delete");
|
|
2977
|
-
const r =
|
|
3069
|
+
const r = $.createNewListItem(e);
|
|
2978
3070
|
document.execCommand("insertText", !1, `
|
|
2979
3071
|
` + r + n);
|
|
2980
3072
|
const o = this.textarea.selectionStart - n.length;
|
|
@@ -2994,19 +3086,19 @@ const w = class w {
|
|
|
2994
3086
|
* @private
|
|
2995
3087
|
*/
|
|
2996
3088
|
updateNumberedLists() {
|
|
2997
|
-
const e = this.textarea.value, t = this.textarea.selectionStart, n =
|
|
3089
|
+
const e = this.textarea.value, t = this.textarea.selectionStart, n = $.renumberLists(e);
|
|
2998
3090
|
if (n !== e) {
|
|
2999
3091
|
let r = 0;
|
|
3000
3092
|
const o = e.split(`
|
|
3001
|
-
`),
|
|
3093
|
+
`), a = n.split(`
|
|
3002
3094
|
`);
|
|
3003
|
-
let
|
|
3004
|
-
for (let
|
|
3005
|
-
if (o[
|
|
3006
|
-
const d =
|
|
3007
|
-
|
|
3095
|
+
let s = 0;
|
|
3096
|
+
for (let c = 0; c < o.length && s < t; c++) {
|
|
3097
|
+
if (o[c] !== a[c]) {
|
|
3098
|
+
const d = a[c].length - o[c].length;
|
|
3099
|
+
s + o[c].length < t && (r += d);
|
|
3008
3100
|
}
|
|
3009
|
-
|
|
3101
|
+
s += o[c].length + 1;
|
|
3010
3102
|
}
|
|
3011
3103
|
this.textarea.value = n;
|
|
3012
3104
|
const l = t + r;
|
|
@@ -3056,7 +3148,7 @@ const w = class w {
|
|
|
3056
3148
|
*/
|
|
3057
3149
|
getRenderedHTML(e = {}) {
|
|
3058
3150
|
const t = this.getValue();
|
|
3059
|
-
let n =
|
|
3151
|
+
let n = $.parse(t);
|
|
3060
3152
|
return e.cleanHTML && (n = n.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g, ""), n = n.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g, ""), n = n.replace(/\sclass=""/g, "")), n;
|
|
3061
3153
|
}
|
|
3062
3154
|
/**
|
|
@@ -3115,14 +3207,14 @@ const w = class w {
|
|
|
3115
3207
|
column: 0
|
|
3116
3208
|
};
|
|
3117
3209
|
const e = this.textarea.value, t = e.split(`
|
|
3118
|
-
`), n = e.length, r = e.split(/\s+/).filter((d) => d.length > 0).length, o = this.textarea.selectionStart,
|
|
3119
|
-
`), l =
|
|
3210
|
+
`), n = e.length, r = e.split(/\s+/).filter((d) => d.length > 0).length, o = this.textarea.selectionStart, s = e.substring(0, o).split(`
|
|
3211
|
+
`), l = s.length, c = s[s.length - 1].length + 1;
|
|
3120
3212
|
return {
|
|
3121
3213
|
chars: n,
|
|
3122
3214
|
words: r,
|
|
3123
3215
|
lines: t.length,
|
|
3124
3216
|
line: l,
|
|
3125
|
-
column:
|
|
3217
|
+
column: c
|
|
3126
3218
|
};
|
|
3127
3219
|
}
|
|
3128
3220
|
_updateStats() {
|
|
@@ -3154,13 +3246,13 @@ const w = class w {
|
|
|
3154
3246
|
if (!this.options.autoResize) return;
|
|
3155
3247
|
const e = this.textarea, t = this.preview, n = this.wrapper, r = e.scrollTop;
|
|
3156
3248
|
e.style.setProperty("height", "auto", "important");
|
|
3157
|
-
let o = e.scrollHeight,
|
|
3158
|
-
const
|
|
3159
|
-
typeof
|
|
3249
|
+
let o = e.scrollHeight, a = "hidden";
|
|
3250
|
+
const s = this._minAutoHeight;
|
|
3251
|
+
typeof s == "number" && s > 0 && (o = Math.max(o, s));
|
|
3160
3252
|
const l = this._maxAutoHeight;
|
|
3161
|
-
typeof l == "number" && l > 0 && o > l && (o = l,
|
|
3162
|
-
const
|
|
3163
|
-
e.style.setProperty("height",
|
|
3253
|
+
typeof l == "number" && l > 0 && o > l && (o = l, a = "auto");
|
|
3254
|
+
const c = o + "px";
|
|
3255
|
+
e.style.setProperty("height", c, "important"), e.style.setProperty("overflow-y", a, "important"), t.style.setProperty("height", c, "important"), t.style.setProperty("overflow-y", a, "important"), n.style.setProperty("height", c, "important"), e.scrollTop = r, t.scrollTop = r, this.previousHeight !== o && (this.previousHeight = o);
|
|
3164
3256
|
}
|
|
3165
3257
|
_refreshAutoResizeConstraints() {
|
|
3166
3258
|
this._minAutoHeight = this._resolveSizeToPixels(this.options.minHeight), this._maxAutoHeight = this._resolveSizeToPixels(this.options.maxHeight);
|
|
@@ -3262,7 +3354,7 @@ const w = class w {
|
|
|
3262
3354
|
if (w.stylesInjected && !e) return;
|
|
3263
3355
|
const t = document.querySelector("style.marzipan-styles");
|
|
3264
3356
|
t && t.remove();
|
|
3265
|
-
const n = w.currentTheme ||
|
|
3357
|
+
const n = w.currentTheme || I, r = je({ theme: n }), o = document.createElement("style");
|
|
3266
3358
|
o.className = "marzipan-styles", o.textContent = r, document.head.appendChild(o), w.stylesInjected = !0;
|
|
3267
3359
|
}
|
|
3268
3360
|
/**
|
|
@@ -3271,16 +3363,16 @@ const w = class w {
|
|
|
3271
3363
|
* @param {Object} customColors - Optional color overrides
|
|
3272
3364
|
*/
|
|
3273
3365
|
static setTheme(e, t = null) {
|
|
3274
|
-
let n = typeof e == "string" ?
|
|
3275
|
-
t && (n =
|
|
3366
|
+
let n = typeof e == "string" ? M(e) : e;
|
|
3367
|
+
t && (n = ce(n, t)), w.currentTheme = n, w.injectStyles(!0);
|
|
3276
3368
|
const r = typeof e == "string" ? e : n?.name;
|
|
3277
3369
|
document.querySelectorAll(".marzipan-container").forEach((o) => {
|
|
3278
|
-
const
|
|
3279
|
-
|
|
3370
|
+
const s = o.querySelector(".marzipan-wrapper")?._instance;
|
|
3371
|
+
s ? (s._applyTheme(o), s.updatePreview()) : r && o.setAttribute("data-theme", r);
|
|
3280
3372
|
}), document.querySelectorAll(".marzipan-wrapper").forEach((o) => {
|
|
3281
3373
|
if (!o.closest(".marzipan-container")) {
|
|
3282
|
-
const
|
|
3283
|
-
|
|
3374
|
+
const a = o._instance;
|
|
3375
|
+
a ? (a._applyTheme(o), a.updatePreview()) : r && o.setAttribute("data-theme", r);
|
|
3284
3376
|
}
|
|
3285
3377
|
});
|
|
3286
3378
|
}
|
|
@@ -3315,48 +3407,46 @@ const w = class w {
|
|
|
3315
3407
|
}
|
|
3316
3408
|
};
|
|
3317
3409
|
w.instances = /* @__PURE__ */ new WeakMap(), w.stylesInjected = !1, w.globalListenersInitialized = !1, w.instanceCount = 0;
|
|
3318
|
-
let
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
solar:
|
|
3323
|
-
cave:
|
|
3324
|
-
light:
|
|
3325
|
-
dark:
|
|
3410
|
+
let _ = w;
|
|
3411
|
+
_.MarkdownParser = $;
|
|
3412
|
+
_.ShortcutsManager = Se;
|
|
3413
|
+
_.themes = {
|
|
3414
|
+
solar: I,
|
|
3415
|
+
cave: M("cave"),
|
|
3416
|
+
light: M("light"),
|
|
3417
|
+
dark: M("dark")
|
|
3326
3418
|
};
|
|
3327
|
-
|
|
3328
|
-
|
|
3419
|
+
_.getTheme = M;
|
|
3420
|
+
_.currentTheme = I;
|
|
3329
3421
|
export {
|
|
3330
3422
|
rt as LinkTooltip,
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3423
|
+
$ as MarkdownParser,
|
|
3424
|
+
_ as Marzipan,
|
|
3425
|
+
Se as ShortcutsManager,
|
|
3334
3426
|
nt as Toolbar,
|
|
3335
|
-
ct as accentSwatchPlugin,
|
|
3336
|
-
pt as accentSwatchStyles,
|
|
3337
3427
|
Ie as actions,
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3428
|
+
ct as buildTableMarkdown,
|
|
3429
|
+
se as cave,
|
|
3430
|
+
mt as coreImagePickerPlugin,
|
|
3431
|
+
_ as default,
|
|
3342
3432
|
je as generateStyles,
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3433
|
+
M as getTheme,
|
|
3434
|
+
ut as imageManagerPlugin,
|
|
3435
|
+
ft as imageManagerStyles,
|
|
3436
|
+
bt as imagePickerPlugin,
|
|
3437
|
+
ce as mergeTheme,
|
|
3438
|
+
wt as mermaidExternalPlugin,
|
|
3439
|
+
yt as mermaidPlugin,
|
|
3440
|
+
st as plugins,
|
|
3441
|
+
pt as resolvePositiveInteger,
|
|
3442
|
+
I as solar,
|
|
3443
|
+
zt as tableGeneratorPlugin,
|
|
3444
|
+
St as tableGridPlugin,
|
|
3445
|
+
Ct as tableGridStyles,
|
|
3446
|
+
Et as tablePlugin,
|
|
3357
3447
|
Ne as themeToCSSVars,
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3448
|
+
le as themes,
|
|
3449
|
+
$t as tinyHighlightPlugin,
|
|
3450
|
+
Mt as tinyHighlightStyles
|
|
3361
3451
|
};
|
|
3362
3452
|
//# sourceMappingURL=index.js.map
|