@meowdown/core 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +239 -201
- package/dist/index.js +14 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { Editor, Extension, ExtractMarkBuilders, ExtractNodeBuilders, PlainExtension, Priority, Union, withPriority } from "@prosekit/core";
|
|
2
|
+
import { PlaceholderOptions, definePlaceholder } from "@prosekit/extensions/placeholder";
|
|
3
|
+
import { defineReadonly } from "@prosekit/extensions/readonly";
|
|
2
4
|
import { CodeBlockAttrs } from "@prosekit/extensions/code-block";
|
|
3
5
|
import { HorizontalRuleExtension } from "@prosekit/extensions/horizontal-rule";
|
|
4
6
|
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
//#region src/converters/check-roundtrip.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* How faithfully markdown survives a parse-then-serialize round trip:
|
|
10
|
+
* - `exact`: byte-identical (modulo the trailing newline).
|
|
11
|
+
* - `normalizing`: same non-blank lines ignoring trailing whitespace; only
|
|
12
|
+
* blank-line layout (including empty `>` lines inside a blockquote) or
|
|
13
|
+
* insignificant trailing whitespace differs.
|
|
14
|
+
* - `lossy`: a non-blank line changed, so content would be lost or altered.
|
|
15
|
+
*/
|
|
16
|
+
type RoundTripFidelity = 'exact' | 'normalizing' | 'lossy';
|
|
17
|
+
/** Options for {@link checkRoundTrip}. */
|
|
18
|
+
interface CheckRoundTripOptions {
|
|
19
|
+
/** Whether to handle a leading `---` frontmatter block. Off by default. */
|
|
20
|
+
frontmatter?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Classify how `markdown` survives the editor's parse-then-serialize round trip. */
|
|
23
|
+
declare function checkRoundTrip(markdown: string, options?: CheckRoundTripOptions): RoundTripFidelity;
|
|
24
|
+
//#endregion
|
|
8
25
|
//#region src/extensions/frontmatter.d.ts
|
|
9
26
|
/**
|
|
10
27
|
* The raw YAML frontmatter body, stored verbatim (the text between the opening
|
|
@@ -50,6 +67,41 @@ type HorizontalRuleMarkerExtension = Extension<{
|
|
|
50
67
|
}>;
|
|
51
68
|
type MeowdownHorizontalRuleExtension = Union<[HorizontalRuleExtension, HorizontalRuleMarkerExtension]>;
|
|
52
69
|
//#endregion
|
|
70
|
+
//#region src/extensions/html-comment.d.ts
|
|
71
|
+
interface MeowdownHTMLCommentAttrs {
|
|
72
|
+
/**
|
|
73
|
+
* The literal markdown comment, including its delimiters, e.g.
|
|
74
|
+
* `<!-- reflect-capture-page-text:start -->`. A multi-line comment keeps its
|
|
75
|
+
* embedded newlines verbatim so the round-trip is lossless.
|
|
76
|
+
*/
|
|
77
|
+
content: string;
|
|
78
|
+
}
|
|
79
|
+
type HTMLCommentExtension = Extension<{
|
|
80
|
+
Nodes: {
|
|
81
|
+
htmlComment: MeowdownHTMLCommentAttrs;
|
|
82
|
+
};
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* A block-level HTML comment (`<!-- ... -->`) as an invisible, atomic node.
|
|
86
|
+
*
|
|
87
|
+
* Markdown is the source of truth, so a comment must survive a round-trip — but
|
|
88
|
+
* a comment is, by definition, not rendered output. Rather than spilling the raw
|
|
89
|
+
* `<!-- ... -->` into a paragraph (where it reads as body text), the parser maps
|
|
90
|
+
* a `CommentBlock` onto this node: the text rides on the `content` attribute and
|
|
91
|
+
* `toDOM` hides it with `display: none`, so it stays in the document and
|
|
92
|
+
* serializes back verbatim while never showing in the editor. Useful for
|
|
93
|
+
* sentinel markers that tools embed around a region of a note.
|
|
94
|
+
*
|
|
95
|
+
* Only block-level comments (a `<!-- ... -->` that owns its line) become this
|
|
96
|
+
* node. An inline comment in the middle of a paragraph is left as literal text,
|
|
97
|
+
* and raw HTML blocks (`<div>…`) stay visible paragraphs — they can carry
|
|
98
|
+
* content a reader expects to see.
|
|
99
|
+
*
|
|
100
|
+
* The node is `atom` (no editable content) and not selectable: it is an opaque,
|
|
101
|
+
* invisible marker the cursor steps over rather than a block the user edits.
|
|
102
|
+
*/
|
|
103
|
+
declare function defineHTMLComment(): HTMLCommentExtension;
|
|
104
|
+
//#endregion
|
|
53
105
|
//#region src/extensions/inline-marks.d.ts
|
|
54
106
|
interface MdImageViewAttrs {
|
|
55
107
|
src: string;
|
|
@@ -128,7 +180,11 @@ declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<rea
|
|
|
128
180
|
setextUnderline?: number | null;
|
|
129
181
|
};
|
|
130
182
|
};
|
|
131
|
-
}>, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/heading").HeadingCommandsExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/core").Union<readonly [import("@prosekit/extensions/table").TableSpecExtension, import("@prosekit/extensions/table").TableRowSpecExtension, import("@prosekit/extensions/table").TableCellSpecExtension, import("@prosekit/extensions/table").TableHeaderCellSpecExtension, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/table").TableCommandsExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/extensions/code-block").CodeBlockExtension, MeowdownHorizontalRuleExtension, import("@prosekit/core").
|
|
183
|
+
}>, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/heading").HeadingCommandsExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/core").Union<readonly [import("@prosekit/extensions/table").TableSpecExtension, import("@prosekit/extensions/table").TableRowSpecExtension, import("@prosekit/extensions/table").TableCellSpecExtension, import("@prosekit/extensions/table").TableHeaderCellSpecExtension, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/table").TableCommandsExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/extensions/code-block").CodeBlockExtension, MeowdownHorizontalRuleExtension, import("@prosekit/core").Extension<{
|
|
184
|
+
Nodes: {
|
|
185
|
+
htmlComment: MeowdownHTMLCommentAttrs;
|
|
186
|
+
};
|
|
187
|
+
}>, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
|
|
132
188
|
Marks: {
|
|
133
189
|
mdMark: import("@prosekit/pm/model").Attrs;
|
|
134
190
|
};
|
|
@@ -197,63 +253,102 @@ type EditorExtension = ReturnType<typeof defineEditorExtensionImpl>;
|
|
|
197
253
|
declare function defineEditorExtension(): EditorExtension;
|
|
198
254
|
type TypedEditor = Editor<EditorExtension>;
|
|
199
255
|
//#endregion
|
|
200
|
-
//#region src/extensions/
|
|
256
|
+
//#region src/extensions/schema.d.ts
|
|
257
|
+
type TypedNodeBuilders = ExtractNodeBuilders<EditorExtension>;
|
|
258
|
+
type TypedMarkBuilders = ExtractMarkBuilders<EditorExtension>;
|
|
259
|
+
/** Typed mark builders bound to the shared schema. */
|
|
260
|
+
declare const getMarkBuilders: () => TypedMarkBuilders;
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/converters/md-to-pm.d.ts
|
|
263
|
+
/** Options for {@link markdownToDoc}. */
|
|
264
|
+
interface MarkdownToDocOptions {
|
|
265
|
+
/** Node builders to build the document with. Defaults to the shared schema's builders. */
|
|
266
|
+
nodes?: TypedNodeBuilders;
|
|
267
|
+
/** Whether to peel a leading `---` frontmatter block onto the doc's `frontmatter` attribute. Off by default. */
|
|
268
|
+
frontmatter?: boolean;
|
|
269
|
+
}
|
|
201
270
|
/**
|
|
202
|
-
*
|
|
203
|
-
* editor serializes content to the clipboard.
|
|
271
|
+
* Convert a markdown string into a ProseMirror document node.
|
|
204
272
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
273
|
+
* By default the document is built with the shared schema's node builders, so
|
|
274
|
+
* no editor is required. When the result will be loaded into a specific editor,
|
|
275
|
+
* pass that editor's `nodes` so the document uses the editor's own schema
|
|
276
|
+
* instance and can be inserted without a JSON round trip.
|
|
277
|
+
*
|
|
278
|
+
* The output follows the extension set defined in `../extensions/extension.ts`
|
|
279
|
+
* (doc, paragraph, text, heading, blockquote, list, codeBlock, table, tableRow,
|
|
280
|
+
* tableCell, tableHeaderCell, horizontalRule). The function does not produce
|
|
281
|
+
* inline marks because the markdown stays literal text - emphasis / link /
|
|
282
|
+
* inline-code characters survive verbatim.
|
|
208
283
|
*/
|
|
209
|
-
|
|
210
|
-
declare function defineMarkMode(mode: MarkMode): PlainExtension;
|
|
284
|
+
declare function markdownToDoc(markdown: string, options?: MarkdownToDocOptions): ProseMirrorNode;
|
|
211
285
|
//#endregion
|
|
212
|
-
//#region src/
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
286
|
+
//#region src/converters/pm-to-md.d.ts
|
|
287
|
+
/** Options for {@link docToMarkdown}. */
|
|
288
|
+
interface DocToMarkdownOptions {
|
|
289
|
+
/** Whether to serialize the doc's `frontmatter` attribute as a leading `---` block. Off by default. */
|
|
290
|
+
frontmatter?: boolean;
|
|
216
291
|
}
|
|
217
|
-
|
|
218
|
-
|
|
292
|
+
/**
|
|
293
|
+
* Convert a ProseMirror document into a Markdown string.
|
|
294
|
+
*
|
|
295
|
+
* Performance design:
|
|
296
|
+
* - Output accumulates in a `string[]` buffer; joined once at the end.
|
|
297
|
+
* Avoids per-block intermediate strings while keeping the
|
|
298
|
+
* function-per-node-type readability of a switch dispatch.
|
|
299
|
+
* - Indent stack lives as a mutable `linePrefix` on the buffer object,
|
|
300
|
+
* restored via local variables across nested calls - no fresh
|
|
301
|
+
* context objects per recursion.
|
|
302
|
+
* - Inline content is walked directly (not via `node.textContent`) to
|
|
303
|
+
* skip one intermediate string allocation per leaf block.
|
|
304
|
+
* - Backtick fence width and cell escaping use single linear loops, no
|
|
305
|
+
* regex on the hot path.
|
|
306
|
+
*/
|
|
307
|
+
declare function docToMarkdown(node: ProseMirrorNode, options?: DocToMarkdownOptions): string;
|
|
219
308
|
//#endregion
|
|
220
|
-
//#region src/extensions/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
declare function
|
|
309
|
+
//#region src/extensions/bullet-after-heading.d.ts
|
|
310
|
+
/**
|
|
311
|
+
* "Type a title, press Return, start bullets." When this extension is applied,
|
|
312
|
+
* pressing Enter at the end of the document's first heading (the title line)
|
|
313
|
+
* drops the caret into a fresh empty bullet instead of a plain paragraph.
|
|
314
|
+
*/
|
|
315
|
+
declare function defineBulletAfterHeading(): PlainExtension;
|
|
227
316
|
//#endregion
|
|
228
|
-
//#region src/extensions/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
317
|
+
//#region src/extensions/code-block-highlight.d.ts
|
|
318
|
+
/**
|
|
319
|
+
* Adds syntax highlighting to `codeBlock` nodes, parsing each block with the
|
|
320
|
+
* matching CodeMirror/Lezer grammar (loaded on demand from
|
|
321
|
+
* `@codemirror/language-data`). Tokens are tagged with `@lezer/highlight`
|
|
322
|
+
* `tok-*` classes; the default theme colors them per color scheme.
|
|
323
|
+
*/
|
|
324
|
+
declare function defineCodeBlockSyntaxHighlight(): Extension;
|
|
325
|
+
/** A highlighted span of code: `[from, to)` carries the `@lezer/highlight` classes. */
|
|
326
|
+
type CodeToken = readonly [from: number, to: number, classes: string];
|
|
327
|
+
/**
|
|
328
|
+
* Highlight `code` in `language` into `tok-*` token spans, the same classes the
|
|
329
|
+
* editor's decorations use. Returns synchronously when the grammar is already
|
|
330
|
+
* loaded (the common path, no render flash), and a `Promise` only when a grammar
|
|
331
|
+
* must load on demand. Returns `[]` for an empty or unsupported language.
|
|
332
|
+
*/
|
|
333
|
+
declare function getCodeTokens(code: string, language: string): CodeToken[] | Promise<CodeToken[]>;
|
|
237
334
|
//#endregion
|
|
238
|
-
//#region src/extensions/
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
declare function
|
|
255
|
-
/** Inline image/embed rendering (a mark view) plus paste/drop persistence. */
|
|
256
|
-
declare function defineImage(options?: ImageOptions): PlainExtension;
|
|
335
|
+
//#region src/extensions/code-block-languages.d.ts
|
|
336
|
+
/**
|
|
337
|
+
* A list of languages for code block syntax-highlight.
|
|
338
|
+
*/
|
|
339
|
+
declare const codeBlockLanguages: ReadonlyArray<{
|
|
340
|
+
label: string;
|
|
341
|
+
value: string;
|
|
342
|
+
}>;
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/extensions/embed-paste.d.ts
|
|
345
|
+
/**
|
|
346
|
+
* Auto-embed a pasted tweet or YouTube link. When the clipboard holds exactly
|
|
347
|
+
* one such URL, the link is rewritten to ``, which the image pipeline
|
|
348
|
+
* renders as a rich embed. Not part of `defineEditorExtension`; the React
|
|
349
|
+
* package applies it via the `embedPaste` prop (on by default).
|
|
350
|
+
*/
|
|
351
|
+
declare function defineEmbedPaste(): PlainExtension;
|
|
257
352
|
//#endregion
|
|
258
353
|
//#region src/extensions/embed/types.d.ts
|
|
259
354
|
/**
|
|
@@ -296,47 +391,16 @@ declare function listenForTweetHeight(iframe: HTMLIFrameElement): () => void;
|
|
|
296
391
|
/** Detect a tweet/YouTube embed in an image `src`, or `undefined` for a plain image. */
|
|
297
392
|
declare function matchEmbed(src: string): EmbedDescriptor | undefined;
|
|
298
393
|
//#endregion
|
|
299
|
-
//#region src/extensions/
|
|
300
|
-
/**
|
|
301
|
-
* Adds syntax highlighting to `codeBlock` nodes, parsing each block with the
|
|
302
|
-
* matching CodeMirror/Lezer grammar (loaded on demand from
|
|
303
|
-
* `@codemirror/language-data`). Tokens are tagged with `@lezer/highlight`
|
|
304
|
-
* `tok-*` classes; the default theme colors them per color scheme.
|
|
305
|
-
*/
|
|
306
|
-
declare function defineCodeBlockSyntaxHighlight(): Extension;
|
|
307
|
-
/** A highlighted span of code: `[from, to)` carries the `@lezer/highlight` classes. */
|
|
308
|
-
type CodeToken = readonly [from: number, to: number, classes: string];
|
|
309
|
-
/**
|
|
310
|
-
* Highlight `code` in `language` into `tok-*` token spans, the same classes the
|
|
311
|
-
* editor's decorations use. Returns synchronously when the grammar is already
|
|
312
|
-
* loaded (the common path, no render flash), and a `Promise` only when a grammar
|
|
313
|
-
* must load on demand. Returns `[]` for an empty or unsupported language.
|
|
314
|
-
*/
|
|
315
|
-
declare function getCodeTokens(code: string, language: string): CodeToken[] | Promise<CodeToken[]>;
|
|
316
|
-
//#endregion
|
|
317
|
-
//#region src/extensions/mark-chunk.d.ts
|
|
318
|
-
/**
|
|
319
|
-
* Contiguous range with a uniform inline-mark set.
|
|
320
|
-
*/
|
|
321
|
-
type MarkChunk = readonly [from: number, to: number, marks: readonly Mark[]];
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/extensions/schema.d.ts
|
|
324
|
-
type TypedNodeBuilders = ExtractNodeBuilders<EditorExtension>;
|
|
325
|
-
type TypedMarkBuilders = ExtractMarkBuilders<EditorExtension>;
|
|
326
|
-
/** Typed mark builders bound to the shared schema. */
|
|
327
|
-
declare const getMarkBuilders: () => TypedMarkBuilders;
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region src/extensions/inline-text-to-mark-chunks.d.ts
|
|
394
|
+
//#region src/extensions/html-paste.d.ts
|
|
330
395
|
/**
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
396
|
+
* Paste foreign rich-text HTML as meowdown Markdown. Rewrites the clipboard's
|
|
397
|
+
* `text/html` through `transformPastedHTML`: foreign HTML is converted to a
|
|
398
|
+
* Markdown string, reparsed into meowdown nodes (literal source text, no marks),
|
|
399
|
+
* and re-serialized to HTML so ProseMirror's own clipboard parser inserts it with
|
|
400
|
+
* the right open depths. `<strong>bold</strong>` thus lands as the text `**bold**`,
|
|
401
|
+
* which the inline-mark plugin renders.
|
|
334
402
|
*/
|
|
335
|
-
declare function
|
|
336
|
-
|
|
337
|
-
marks: TypedMarkBuilders, /** The raw inline text of one textblock (no block prefix). */
|
|
338
|
-
|
|
339
|
-
text: string): MarkChunk[];
|
|
403
|
+
declare function defineHTMLPaste(): PlainExtension;
|
|
340
404
|
//#endregion
|
|
341
405
|
//#region src/extensions/image-click.d.ts
|
|
342
406
|
interface ImageClickPayload {
|
|
@@ -350,51 +414,43 @@ interface ImageClickPayload {
|
|
|
350
414
|
type ImageClickHandler = (payload: ImageClickPayload) => void;
|
|
351
415
|
declare function defineImageClickHandler(onClick: ImageClickHandler): PlainExtension;
|
|
352
416
|
//#endregion
|
|
353
|
-
//#region src/extensions/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
*/
|
|
371
|
-
declare function
|
|
372
|
-
//#endregion
|
|
373
|
-
//#region src/extensions/markdown-copy.d.ts
|
|
374
|
-
/**
|
|
375
|
-
* Serialize copied/cut content to Markdown for the clipboard's `text/plain`, so
|
|
376
|
-
* pasting meowdown content into a plain-text field yields real Markdown (`- `
|
|
377
|
-
* list markers, blank-line block separation) instead of bare `textContent`.
|
|
378
|
-
*
|
|
379
|
-
* The copied fragment is wrapped in a `doc` so the existing block serializer can
|
|
380
|
-
* walk it. A purely inline fragment (a partial-paragraph copy) does not fit
|
|
381
|
-
* `doc`'s `block+` content, so it falls back to the inline text.
|
|
382
|
-
*/
|
|
383
|
-
declare function defineMarkdownCopy(): PlainExtension;
|
|
417
|
+
//#region src/extensions/image.d.ts
|
|
418
|
+
type ImageUrlResolver = (src: string) => string | undefined;
|
|
419
|
+
type ImagePasteHandler = (file: File) => string | undefined | Promise<string | undefined>;
|
|
420
|
+
type ImageSaveErrorHandler = (error: unknown, file: File) => void;
|
|
421
|
+
interface ImageOptions {
|
|
422
|
+
/**
|
|
423
|
+
* Map a markdown `src` to a displayable URL, or `undefined` to skip rendering
|
|
424
|
+
* that image. Defaults to `defaultResolveImageUrl`.
|
|
425
|
+
*/
|
|
426
|
+
resolveImageUrl?: ImageUrlResolver;
|
|
427
|
+
/** Persist a pasted/dropped image file and return its markdown `src`, or `undefined` to decline. */
|
|
428
|
+
onImagePaste?: ImagePasteHandler;
|
|
429
|
+
/** Called when persisting a pasted/dropped image throws. Defaults to `console.error`. */
|
|
430
|
+
onImageSaveError?: ImageSaveErrorHandler;
|
|
431
|
+
}
|
|
432
|
+
/** Show an `src` as-is when it is an http(s) URL, otherwise skip rendering it. */
|
|
433
|
+
declare function defaultResolveImageUrl(src: string): string | undefined;
|
|
434
|
+
/** Inline image/embed rendering (a mark view) plus paste/drop persistence. */
|
|
435
|
+
declare function defineImage(options?: ImageOptions): PlainExtension;
|
|
384
436
|
//#endregion
|
|
385
|
-
//#region src/extensions/
|
|
437
|
+
//#region src/extensions/mark-chunk.d.ts
|
|
386
438
|
/**
|
|
387
|
-
*
|
|
388
|
-
* pressing Enter at the end of the document's first heading (the title line)
|
|
389
|
-
* drops the caret into a fresh empty bullet instead of a plain paragraph.
|
|
439
|
+
* Contiguous range with a uniform inline-mark set.
|
|
390
440
|
*/
|
|
391
|
-
|
|
441
|
+
type MarkChunk = readonly [from: number, to: number, marks: readonly Mark[]];
|
|
392
442
|
//#endregion
|
|
393
|
-
//#region src/extensions/
|
|
443
|
+
//#region src/extensions/inline-text-to-mark-chunks.d.ts
|
|
394
444
|
/**
|
|
395
|
-
*
|
|
445
|
+
* Walk a textblock's inline content and produce a list of mark chunks
|
|
446
|
+
* with positions relative to the start of `text` (i.e. zero-based).
|
|
447
|
+
* Callers shift the chunks into the document's coordinate space.
|
|
396
448
|
*/
|
|
397
|
-
declare function
|
|
449
|
+
declare function inlineTextToMarkChunks(/** Typed mark builders bound to the target schema. */
|
|
450
|
+
|
|
451
|
+
marks: TypedMarkBuilders, /** The raw inline text of one textblock (no block prefix). */
|
|
452
|
+
|
|
453
|
+
text: string): MarkChunk[];
|
|
398
454
|
//#endregion
|
|
399
455
|
//#region src/extensions/key-bindings.d.ts
|
|
400
456
|
/** Human-readable descriptions of the editor's formatting and heading shortcuts. */
|
|
@@ -412,89 +468,71 @@ declare const EDITOR_KEY_BINDINGS: {
|
|
|
412
468
|
readonly 'Mod-6': "Heading 6";
|
|
413
469
|
};
|
|
414
470
|
//#endregion
|
|
415
|
-
//#region src/extensions/
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
declare const codeBlockLanguages: ReadonlyArray<{
|
|
420
|
-
label: string;
|
|
421
|
-
value: string;
|
|
422
|
-
}>;
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/converters/pm-to-md.d.ts
|
|
425
|
-
/** Options for {@link docToMarkdown}. */
|
|
426
|
-
interface DocToMarkdownOptions {
|
|
427
|
-
/** Whether to serialize the doc's `frontmatter` attribute as a leading `---` block. Off by default. */
|
|
428
|
-
frontmatter?: boolean;
|
|
471
|
+
//#region src/extensions/link-click.d.ts
|
|
472
|
+
interface LinkClickPayload {
|
|
473
|
+
href: string;
|
|
474
|
+
event: MouseEvent;
|
|
429
475
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
*
|
|
433
|
-
* Performance design:
|
|
434
|
-
* - Output accumulates in a `string[]` buffer; joined once at the end.
|
|
435
|
-
* Avoids per-block intermediate strings while keeping the
|
|
436
|
-
* function-per-node-type readability of a switch dispatch.
|
|
437
|
-
* - Indent stack lives as a mutable `linePrefix` on the buffer object,
|
|
438
|
-
* restored via local variables across nested calls - no fresh
|
|
439
|
-
* context objects per recursion.
|
|
440
|
-
* - Inline content is walked directly (not via `node.textContent`) to
|
|
441
|
-
* skip one intermediate string allocation per leaf block.
|
|
442
|
-
* - Backtick fence width and cell escaping use single linear loops, no
|
|
443
|
-
* regex on the hot path.
|
|
444
|
-
*/
|
|
445
|
-
declare function docToMarkdown(node: ProseMirrorNode, options?: DocToMarkdownOptions): string;
|
|
476
|
+
type LinkClickHandler = (payload: LinkClickPayload) => void;
|
|
477
|
+
declare function defineLinkClickHandler(onClick: LinkClickHandler): PlainExtension;
|
|
446
478
|
//#endregion
|
|
447
|
-
//#region src/
|
|
448
|
-
/** Options for {@link markdownToDoc}. */
|
|
449
|
-
interface MarkdownToDocOptions {
|
|
450
|
-
/** Node builders to build the document with. Defaults to the shared schema's builders. */
|
|
451
|
-
nodes?: TypedNodeBuilders;
|
|
452
|
-
/** Whether to peel a leading `---` frontmatter block onto the doc's `frontmatter` attribute. Off by default. */
|
|
453
|
-
frontmatter?: boolean;
|
|
454
|
-
}
|
|
479
|
+
//#region src/extensions/mark-mode.d.ts
|
|
455
480
|
/**
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
* By default the document is built with the shared schema's node builders, so
|
|
459
|
-
* no editor is required. When the result will be loaded into a specific editor,
|
|
460
|
-
* pass that editor's `nodes` so the document uses the editor's own schema
|
|
461
|
-
* instance and can be inserted without a JSON round trip.
|
|
481
|
+
* Controls how markdown syntax characters are rendered and how the
|
|
482
|
+
* editor serializes content to the clipboard.
|
|
462
483
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* inline marks because the markdown stays literal text - emphasis / link /
|
|
467
|
-
* inline-code characters survive verbatim.
|
|
484
|
+
* - 'hide': syntax chars never visible; copy strips them.
|
|
485
|
+
* - 'focus': syntax chars hidden by default; revealed near cursor; copy strips them.
|
|
486
|
+
* - 'show': syntax chars always visible (dim grey); copy keeps them.
|
|
468
487
|
*/
|
|
469
|
-
|
|
488
|
+
type MarkMode = 'hide' | 'focus' | 'show';
|
|
489
|
+
declare function defineMarkMode(mode: MarkMode): PlainExtension;
|
|
470
490
|
//#endregion
|
|
471
|
-
//#region src/
|
|
491
|
+
//#region src/extensions/mark-names.d.ts
|
|
492
|
+
declare const MARK_NAMES: readonly ["mdImageView", "mdImageSource", "mdMark", "mdEm", "mdStrong", "mdCode", "mdLinkText", "mdLinkUri", "mdDel", "mdHighlight", "mdTag", "mdWikilinkSource", "mdWikilinkView", "mdPack"];
|
|
493
|
+
type MarkName = (typeof MARK_NAMES)[number];
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/extensions/markdown-copy.d.ts
|
|
472
496
|
/**
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
497
|
+
* Serialize copied/cut content to Markdown for the clipboard's `text/plain`, so
|
|
498
|
+
* pasting meowdown content into a plain-text field yields real Markdown (`- `
|
|
499
|
+
* list markers, blank-line block separation) instead of bare `textContent`.
|
|
500
|
+
*
|
|
501
|
+
* The copied fragment is wrapped in a `doc` so the existing block serializer can
|
|
502
|
+
* walk it. A purely inline fragment (a partial-paragraph copy) does not fit
|
|
503
|
+
* `doc`'s `block+` content, so it falls back to the inline text.
|
|
479
504
|
*/
|
|
480
|
-
|
|
481
|
-
/** Options for {@link checkRoundTrip}. */
|
|
482
|
-
interface CheckRoundTripOptions {
|
|
483
|
-
/** Whether to handle a leading `---` frontmatter block. Off by default. */
|
|
484
|
-
frontmatter?: boolean;
|
|
485
|
-
}
|
|
486
|
-
/** Classify how `markdown` survives the editor's parse-then-serialize round trip. */
|
|
487
|
-
declare function checkRoundTrip(markdown: string, options?: CheckRoundTripOptions): RoundTripFidelity;
|
|
505
|
+
declare function defineMarkdownCopy(): PlainExtension;
|
|
488
506
|
//#endregion
|
|
489
507
|
//#region src/extensions/node-names.d.ts
|
|
490
508
|
/**
|
|
491
509
|
* Every ProseMirror node name the editor schema knows about.
|
|
492
510
|
*/
|
|
493
|
-
declare const NODE_NAMES: readonly ["doc", "text", "paragraph", "heading", "blockquote", "list", "codeBlock", "horizontalRule", "table", "tableRow", "tableCell", "tableHeaderCell"];
|
|
511
|
+
declare const NODE_NAMES: readonly ["doc", "text", "paragraph", "heading", "blockquote", "list", "codeBlock", "horizontalRule", "htmlComment", "table", "tableRow", "tableCell", "tableHeaderCell"];
|
|
494
512
|
type NodeName = (typeof NODE_NAMES)[number];
|
|
495
513
|
//#endregion
|
|
496
|
-
//#region src/extensions/
|
|
497
|
-
|
|
498
|
-
|
|
514
|
+
//#region src/extensions/tag-click.d.ts
|
|
515
|
+
interface TagClickPayload {
|
|
516
|
+
/** The tag name, without the leading `#`. */
|
|
517
|
+
tag: string;
|
|
518
|
+
/** The originating click. Read modifier keys or position a popover from it. */
|
|
519
|
+
event: MouseEvent;
|
|
520
|
+
}
|
|
521
|
+
type TagClickHandler = (payload: TagClickPayload) => void;
|
|
522
|
+
declare function defineTagClickHandler(onClick: TagClickHandler): PlainExtension;
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/extensions/wikilink-click.d.ts
|
|
525
|
+
interface WikilinkClickPayload {
|
|
526
|
+
target: string;
|
|
527
|
+
event: MouseEvent;
|
|
528
|
+
}
|
|
529
|
+
type WikilinkClickHandler = (payload: WikilinkClickPayload) => void;
|
|
530
|
+
declare function defineWikilinkClickHandler(onClick: WikilinkClickHandler): PlainExtension;
|
|
531
|
+
//#endregion
|
|
532
|
+
//#region src/extensions/wikilink-trigger.d.ts
|
|
533
|
+
/**
|
|
534
|
+
* Binds `Mod-Shift-k` to open the wikilink menu.
|
|
535
|
+
*/
|
|
536
|
+
declare function defineWikilinkTrigger(): PlainExtension;
|
|
499
537
|
//#endregion
|
|
500
|
-
export { type CheckRoundTripOptions, type CodeBlockAttrs, type CodeToken, type DocToMarkdownOptions, EDITOR_KEY_BINDINGS, type EditorExtension, type EmbedDescriptor, type ImageClickHandler, type ImageClickPayload, type ImageOptions, type LinkClickHandler, type LinkClickPayload, type MarkChunk, type MarkMode, type MarkName, type MarkdownToDocOptions, type MdImageViewAttrs, type MdLinkTextAttrs, type MdWikilinkViewAttrs, type NodeName, type PlaceholderOptions, Priority, type RoundTripFidelity, type TagClickHandler, type TagClickPayload, type TypedEditor, type TypedMarkBuilders, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineCodeBlockSyntaxHighlight, defineEditorExtension, defineEmbedPaste, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineMarkMode, defineMarkdownCopy, definePlaceholder, defineReadonly, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getMarkBuilders, inlineTextToMarkChunks, listenForTweetHeight, markdownToDoc, matchEmbed, withPriority };
|
|
538
|
+
export { type CheckRoundTripOptions, type CodeBlockAttrs, type CodeToken, type DocToMarkdownOptions, EDITOR_KEY_BINDINGS, type EditorExtension, type EmbedDescriptor, type ImageClickHandler, type ImageClickPayload, type ImageOptions, type LinkClickHandler, type LinkClickPayload, type MarkChunk, type MarkMode, type MarkName, type MarkdownToDocOptions, type MdImageViewAttrs, type MdLinkTextAttrs, type MdWikilinkViewAttrs, type MeowdownHTMLCommentAttrs, type NodeName, type PlaceholderOptions, Priority, type RoundTripFidelity, type TagClickHandler, type TagClickPayload, type TypedEditor, type TypedMarkBuilders, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineCodeBlockSyntaxHighlight, defineEditorExtension, defineEmbedPaste, defineHTMLComment, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineMarkMode, defineMarkdownCopy, definePlaceholder, defineReadonly, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getMarkBuilders, inlineTextToMarkChunks, listenForTweetHeight, markdownToDoc, matchEmbed, withPriority };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineCommands as o,defineHistory as s,defineKeymap as c,defineMarkSpec as l,defineMarkView as u,defineNodeAttr as d,defineNodeSpec as f,definePlugin as p,getMarkRange as m,getMarkType as ee,getNodeType as te,isAtBlockStart as ne,isTextSelection as re,toggleNode as ie,union as h,unsetBlockType as ae,withPriority as oe,withPriority as g,withSkipCodeBlock as se}from"@prosekit/core";import{
|
|
2
|
-
`)}function mt(e){let{selection:t}=e;if(!t.empty)return b.empty;let n=t.$head,{parent:r}=n;if(!r.isTextblock||r.type.spec.code)return b.empty;let i=m(n,ee(e.schema,`mdPack`));return i?b.create(e.doc,[ge.inline(i.from,i.to,{class:`show`})]):b.empty}function T(e,t){let n=ft(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function E(e,t,n){for(let r of n){let n=w(e,t,r);if(n)return n}}function D(e,t,n){let r=E(e,t,n);return r&&r.to===t?r:void 0}function O(e,t,n){let r=E(e,t,n);return r&&r.from===t?r:void 0}function k(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=E(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function ht(e,t){return y.create(e.doc,t.from,t.to)}function gt(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!re(t.selection))return!1;let i=t.selection;if(i.empty){let e=O(t,i.from,r);if(e)return n?.(t.tr.setSelection(ht(t,e))),!0;if(D(t,i.from,r)){let e=t.doc.resolve(i.from);return i.from>=e.end()?!1:(n?.(t.tr.setSelection(y.create(t.doc,i.from+1))),!0)}return!1}let a=k(t,r);return a?(n?.(t.tr.setSelection(y.create(t.doc,a.to))),!0):!1}}function _t(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!re(t.selection))return!1;let i=t.selection;if(i.empty){let e=D(t,i.from,r);return e?(n?.(t.tr.setSelection(ht(t,e))),!0):!1}let a=k(t,r);return a?(n?.(t.tr.setSelection(y.create(t.doc,a.from))),!0):!1}}function vt(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=D(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!O(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function yt(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=O(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!D(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}function bt(e,t){return new _({key:new v(`atomic-mark-selection-${t}`),props:{decorations:n=>{let r=T(e,n);if(r.length===0)return;let i=k(n,r);if(i)return b.create(n.doc,[ge.inline(i.from,i.to,{class:t})])}}})}function xt({marks:e,selectedClass:n}){return h(g(c({ArrowRight:gt(e),ArrowLeft:_t(e),Backspace:vt(e),Delete:yt(e)}),t.high),p(bt(e,n)))}const A=new Map,St=new Map;async function Ct(e){let t=A.get(e);if(t!==void 0)return t;let n=_e.matchLanguageName(ve,e,!0);if(!n)return A.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),A.set(e,null),null}return A.set(e,r),r}function wt(e,t){let n=St.get(e);if(n)return n;let r=xe({parse:e=>t.language.parser.parse(e.content),highlighter:ye});return St.set(e,r),r}const Tt=e=>{let t=e.language?.trim();if(!t)return[];let n=A.get(t);return n===null?[]:n?wt(t,n)(e):Ct(t).then(()=>void 0)};function Et(){return ue({parser:Tt,nodeTypes:[`codeBlock`]})}function Dt(e,t){let n=t.language.parser.parse(e),r=[];return be(n,ye,(e,t,n)=>{r.push([e,t,n])}),r}function Ot(e,t){let n=t.trim();if(!n)return[];let r=A.get(n);return r===null?[]:r?Dt(e,r):Ct(n).then(t=>t?Dt(e,t):[])}function kt(){return d({type:`doc`,attr:`frontmatter`,default:null})}function At(){return f({name:`heading`,whitespace:`pre`})}function jt(){return d({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function j(e){return se(ie({type:`heading`,attrs:{level:e}}))}const Mt=(e,t,n)=>ne(e,n)?.parent.type.name===`heading`?ae()(e,t,n):!1;function Nt(){return c({"Mod-1":j(1),"Mod-2":j(2),"Mod-3":j(3),"Mod-4":j(4),"Mod-5":j(5),"Mod-6":j(6),Backspace:Mt})}function Pt(){return h(we(),At(),jt(),Ce(),Se(),Nt())}function Ft(){return d({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function It(){return h(Te(),Ft())}function Lt(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Rt(e,t){let[n,r,i]=t;return[n,r,i.map(t=>je.fromJSON(e,t))]}var M=class e extends De{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Oe.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new ke(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new ke(e),n.addMark(i,c,t));return!1})}return Oe.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return zt;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new Ee(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(Lt)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Rt(t,e)))}};De.jsonID(`batchSetMark`,M);const zt=new M([]),Bt=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),Vt=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function Ht(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function Ut(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!Bt.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!Vt.test(e))return!1;return!0}function Wt(e){return e===32||e===9||e===10||e===13}const Gt=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,Kt=/[\s(*_~]/;function qt(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function Jt(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function Yt(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&Jt(e,t,`)`)>Jt(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const Xt={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!qt(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!Kt.test(r))return-1;let i=Gt.exec(e.slice(n,e.end));if(!i)return-1;let a=Yt(i[0]);return a===0||!Ut(Ht(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function Zt(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Qt(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const $t={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!Zt(t))break;i||=Qt(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},en={resolve:`Highlight`,mark:`HighlightMark`},tn=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,nn={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=tn.test(r),c=tn.test(i);return e.addDelimiter(en,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]},rn={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function an(e){return e.end}const N=Ne.configure([Me,$t,rn,Xt,nn]),on=N.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:an}]});function P(e){return N.parseInline(e,0)}function F(e,t,n=[]){for(let r of e)t(r)&&n.push(r),F(r.children,t,n);return n}function sn(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const I=sn(N);function cn(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}function ln(e){let t=e.replace(/^\[\[/,``).replace(/\]\]$/,``),n=t.indexOf(`|`);return n<0?{target:t.trim(),display:``}:{target:t.slice(0,n).trim(),display:t.slice(n+1).trim()}}function un(){return e=>{let t=e.attrs,n=document.createElement(`span`);n.className=`md-wikilink-view`;let r=document.createElement(`span`);r.className=`md-wikilink-label`,r.contentEditable=`false`,r.dataset.testid=`wikilink`,r.textContent=t.display||t.target,n.appendChild(r);let i=document.createElement(`span`);return i.className=`md-wikilink-view-content`,n.appendChild(i),{dom:n,contentDOM:i,ignoreMutation:e=>!i.contains(e.target)}}}function dn(){return u({name:`mdWikilinkView`,constructor:un()})}const L=new Map([[I.Emphasis,`mdEm`],[I.StrongEmphasis,`mdStrong`],[I.InlineCode,`mdCode`],[I.Strikethrough,`mdDel`],[I.Highlight,`mdHighlight`],[I.EmphasisMark,`mdMark`],[I.CodeMark,`mdMark`],[I.LinkMark,`mdMark`],[I.StrikethroughMark,`mdMark`],[I.HighlightMark,`mdMark`],[I.URL,`mdLinkUri`],[I.Hashtag,`mdTag`],[I.WikilinkMark,`mdMark`]]);function fn(e,t){let n=P(t),r=[];return R(n,[],0,t.length,t,e,r),r}function pn(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||Ut(Ht(e)))return`https://${e}`}function R(e,t,n,r,i,a,o){let s=n;for(let n of e){n.from>s&&z(o,s,n.from,t);let e=n.type;if(e===I.Link)mn(n,t,i,a,o);else if(e===I.Image)hn(n,t,i,a,o);else if(e===I.Wikilink)gn(n,t,i,a,o);else if(e===I.URL){let e=pn(i.slice(n.from,n.to)),r=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();z(o,n.from,n.to,[...t,r])}else{let r;e===I.Emphasis?r=`italic`:e===I.StrongEmphasis?r=`bold`:e===I.InlineCode?r=`code`:e===I.Strikethrough?r=`strike`:e===I.Highlight?r=`highlight`:e===I.Autolink&&(r=`autolink`);let s=r?[...t,a.mdPack.create({key:r})]:t,c=L.get(e),l=c?[...s,a[c].create()]:s;n.children.length===0?z(o,n.from,n.to,l):R(n.children,l,n.from,n.to,i,a,o)}s=n.to}s<r&&z(o,s,r,t)}function mn(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===I.LinkMark?(s++,s===2&&(a=t.from)):t.type===I.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c?r.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=r.mdPack.create({key:`link_${c}`}),f=[...t,d],p=e.from;for(let t of e.children){if(t.from>p){let e=u(p)?[...f,l]:f;z(i,p,t.from,e)}let e=u(t.from)?[...f,l]:f;if(t.type===I.Wikilink){gn(t,e,n,r,i),p=t.to;continue}let a=L.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?z(i,t.from,t.to,o):R(t.children,o,t.from,t.to,n,r,i),p=t.to}p<e.to&&z(i,p,e.to,f)}function hn(e,t,n,r,i){let a=e.children.find(e=>e.type===I.URL);if(!a){mn(e,t,n,r,i);return}let o=e.children.filter(e=>e.type===I.LinkMark),s=n.slice(a.from,a.to),c=o.length>=2?n.slice(o[0].to,o[1].from):``,l=r.mdImageSource.create({src:s,alt:c}),u=r.mdImageView.create({src:s,alt:c}),d=r.mdPack.create({key:`image_${s}`}),f=e.to-1,p=e=>e>=f?[...t,d,l,u]:[...t,d,l],m=e.from;for(let t of e.children){t.from>m&&z(i,m,t.from,p(m));let e=L.get(t.type),a=e?[...p(t.from),r[e].create()]:p(t.from);t.children.length===0?z(i,t.from,t.to,a):R(t.children,a,t.from,t.to,n,r,i),m=t.to}m<e.to&&z(i,m,e.to,p(m))}function gn(e,t,n,r,i){let{target:a,display:o}=ln(n.slice(e.from,e.to)),s=r.mdWikilinkSource.create({target:a}),c=r.mdWikilinkView.create({target:a,display:o}),l=e.to-1,u=e=>e>=l?[...t,s,c]:[...t,s],d=e.from;for(let t of e.children){t.from>d&&z(i,d,t.from,u(d));let e=r.mdMark.create();t.from<l&&t.to>l?(z(i,t.from,l,[...u(t.from),e]),z(i,l,t.to,[...u(l),e])):z(i,t.from,t.to,[...u(t.from),e]),d=t.to}d<e.to&&z(i,d,e.to,u(d))}function z(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&cn(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const _n=x(()=>{let e=jr().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),vn=x(()=>r(_n())),yn=x(()=>n(_n())),bn=`meowdown_mark_builders`;function xn(e){let t=e.cached[bn];if(t)return t;let r=n(e);return e.cached[bn]=r,r}const Sn=`meowdown_node_builders`;function Cn(e){let t=e.cached[Sn];if(t)return t;let n=r(e);return e.cached[Sn]=n,n}const wn=`inline-marks-applied`,Tn=new WeakMap;let En=0,Dn=0;function On(e,t,n){let r=Tn.get(e);if(r?Dn++:(En++,r=fn(xn(n),e.textContent),Tn.set(e,r)),t===0)return r;let i=[];for(let[e,n,a]of r)i.push([e+t,n+t,a]);return i}function kn(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function An(e,t){let n=[];return e.doc.nodesBetween(t.from,t.to,(t,r)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let i=On(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function jn(){return new _({key:new v(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(wn))return null;let r=An(n,kn(e,n));if(r.length===0)return null;let i=n.tr.step(new M(r));return i.setMeta(wn,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(Mn(e.state)),{}}})}function Mn(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function Nn(){return p(jn())}function Pn(){return l({name:`mdImageView`,inclusive:!1,attrs:{src:{default:``},alt:{default:``}},toDOM:()=>[`span`,{class:`md-image-anchor`},0],parseDOM:[{tag:`span.md-image-anchor`}]})}function Fn(){return l({name:`mdImageSource`,inclusive:!1,attrs:{src:{default:``},alt:{default:``}},toDOM:()=>[`span`,{class:`md-image-source`},0],parseDOM:[{tag:`span.md-image-source`}]})}function In(){return l({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function Ln(){return l({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function Rn(){return l({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function zn(){return l({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Bn(){return l({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{class:`md-link`,href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function Vn(){return l({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function Hn(){return l({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Un(){return l({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function Wn(){return l({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Gn(){return l({name:`mdWikilinkSource`,inclusive:!1,attrs:{target:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink-source`},0],parseDOM:[{tag:`span.md-wikilink-source`}]})}function Kn(){return l({name:`mdWikilinkView`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink-anchor`},0],parseDOM:[{tag:`span.md-wikilink-anchor`}]})}function qn(){return l({name:`mdPack`,excludes:``,inclusive:!1,attrs:{key:{default:``}},toDOM:e=>[`span`,{class:`md-pack`,"data-key":e.attrs.key},0],parseDOM:[{tag:`span.md-pack`}]})}function Jn(){return h(In(),Ln(),Rn(),zn(),Bn(),Vn(),Hn(),Un(),Wn(),Gn(),Kn(),Fn(),Pn(),qn())}function Yn(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const B={em:{node:I.Emphasis,delim:`*`},strong:{node:I.StrongEmphasis,delim:`**`},code:{node:I.InlineCode,delim:"`"},del:{node:I.Strikethrough,delim:`~~`},highlight:{node:I.Highlight,delim:`==`}},Xn=new Set([I.EmphasisMark,I.CodeMark,I.LinkMark,I.StrikethroughMark,I.HighlightMark]);function V(e){return[e.children[0],e.children.at(-1)]}function Zn(e){let{type:t,children:n}=e;if(t===I.Emphasis||t===I.StrongEmphasis||t===I.Strikethrough||t===I.Highlight)return[n[0].to,n.at(-1).from];if(t===I.Link||t===I.Image){let e=n.find((e,t)=>t>0&&e.type===I.LinkMark);return e?[n[0].to,e.from]:null}return null}function H(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Zn(r);return i&&i[0]<=t&&n<=i[1]?H(r.children,t,n):H(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Qn(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Qn(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const U=e=>e===` `||e===` `;function $n(e,t,n){for(;t<n&&U(e[t]);)t++;for(;n>t&&U(e[n-1]);)n--;return[t,n]}function er(e,t,n,r){let i=F(P(e),e=>e.type===r.node||Xn.has(e.type));for(let r=t;r<n;r++)if(!U(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function tr(e,t,n,r,i){let a=P(e),o=F(a,e=>e.type===r.node);return i?ir(e,o,t,n):nr(e,a,o,t,n,r)}function nr(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=H(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=V(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=rr(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function rr(e,t,n,r,i){if(i.node!==I.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(Yn(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function ir(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=V(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Qn(a.children.slice(1,-1),s,c);s>t.to&&U(e[s-1]);)s--;for(;c<o.from&&U(e[c]);)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function ar(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=P(e),o=F(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=V(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return or(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function or(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Zn(n);return!e||t<e[0]||t>e[1]?!0:or(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return sr(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=$n(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:er(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>tr(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(y.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function sr(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=ar(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(y.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(y.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function cr(){return o({toggleEm:()=>W(B.em),toggleStrong:()=>W(B.strong),toggleCode:()=>W(B.code),toggleDel:()=>W(B.del),toggleHighlight:()=>W(B.highlight)})}function lr(){return c({"Mod-b":W(B.strong),"Mod-i":W(B.em),"Mod-e":W(B.code),"Mod-Shift-x":W(B.del),"Mod-Shift-h":W(B.highlight)})}function ur(){return h(cr(),lr())}function dr(){return d({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>e===`)`||e===`*`||e===`+`?[`data-list-marker`,e]:null,parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function fr(){return d({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>e===`X`?[`data-list-task-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function pr(e){return e===2||e===3||e===4}function mr(){return d({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>pr(e)?[`data-list-marker-gap`,String(e)]:null,parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return pr(t)?t:1}})}const hr=[C(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),C(/^\s?(\d+)\.\s$/,({match:e})=>{let t=e[1],n=t?parseInt(t,10):void 0;return{kind:`ordered`,collapsed:!1,order:n&&n>=2&&Number.isSafeInteger(n)?n:null}}),C(/^\s?\[([\sXx]?)]\s$/,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),C(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function gr(){return h(hr.map(Pe))}function _r(){return S({kind:`task`,marker:`+`})}function vr(){return S({kind:`task`,marker:null})}function yr(){return o({wrapInCircleTask:_r,wrapInSquareTask:vr})}function br(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function xr(){return(e,t,n)=>{let r=br(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},S(a)(e,t,n)}}function Sr(){return(e,t,n)=>{let r=br(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},S(a)(e,t,n)}}function Cr(){return c({"Mod-Enter":xr(),"Mod-Shift-Enter":Sr()})}function wr(){return h(Be(),Re(),Le(),Fe(),ze(),Ie(),gr(),Cr(),dr(),fr(),mr(),yr())}function Tr(){return f({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function Er(){return h(g(Tr(),t.highest),Ve(),He())}const Dr=(e,t)=>{let{selection:n}=e;return!Ze(n)||!n.isColSelection()||!n.isRowSelection()?!1:Xe(e,t)};function Or(){return g(c({Backspace:Dr,Delete:Dr}),t.high)}function kr(){return h(Ye(),Je(),Ue(),qe(),Ke({allowTableNodeSelection:!0}),We(),Ge(),Or())}function Ar(){return h(Er(),de(),kt(),me(),ce(),wr(),Pt(),kr(),le(),It(),Jn(),Et(),Nn(),ur(),dn(),xt({marks:[{name:`mdImageSource`,modes:[`hide`]},{name:`mdWikilinkSource`,modes:[`hide`,`focus`,`show`]}],selectedClass:`md-atomic-selected`}),a(),i(),s(),fe(),he(),pe())}function jr(){return Ar()}function G(e){return p(new _({key:e.key,props:{handleClick:(t,n,r)=>{if(!r.target?.closest?.(e.selector))return!1;let i=e.findPayloadAt(t.state,n);return i==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(i,r),!0)}}}))}const Mr=new v(`meowdown-wikilink-click`);function Nr(e,t){let n=w(e,t,`mdWikilinkSource`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Pr(e){return G({key:Mr,selector:`.md-wikilink-label, .md-wikilink-source`,preventDefault:!1,findPayloadAt:(e,t)=>Nr(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Fr=new v(`meowdown-link-click`);function Ir(e,t){let n=w(e,t,`mdLinkText`);if(n)return{from:n.from,to:n.to,href:n.mark.attrs.href}}function Lr(e){return G({key:Fr,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>Ir(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}const Rr=new v(`meowdown-tag-click`);function zr(e,t){let n=w(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function Br(e){return G({key:Rr,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>zr(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}function Vr(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Hr=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Ur=/\/status(?:es)?\/(\d+)/;function Wr(e){let t;try{t=new URL(e)}catch{return}if(Hr.test(t.hostname))return Ur.exec(t.pathname)?.[1]}const Gr=e=>{let t=Wr(e);if(!t)return;let n=Vr()?`dark`:`light`;return{kind:`tweet`,key:`tweet:${t}`,src:`https://platform.twitter.com/embed/Tweet.html?id=${t}&theme=${n}&dnt=true`,title:`Tweet`,className:`md-embed md-embed-tweet`,testid:`tweet-embed`}};function Kr(e){let t=t=>{if(t.source===e.contentWindow)try{let n=t.data?.[`twttr.embed`]?.params?.[0]?.height;typeof n==`number`&&(e.style.height=`${n}px`)}catch(e){console.warn(`[meowdown] failed to parse tweet resize message:`,e)}};window.addEventListener(`message`,t);let n=!1,r=()=>{n||(n=!0,window.removeEventListener(`message`,t),i.disconnect())},i=new MutationObserver(()=>{e.isConnected||r()});return i.observe(document.body,{childList:!0,subtree:!0}),r}const qr=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Jr=/^(?:www\.)?youtu\.be$/i,Yr=/^[\w-]{11}$/;function Xr(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Jr.test(t.hostname))n=t.pathname.slice(1);else if(qr.test(t.hostname)){let[,e,r]=t.pathname.split(`/`);t.pathname===`/watch`?n=t.searchParams.get(`v`):(e===`shorts`||e===`embed`||e===`live`)&&(n=r??null)}if(!n||!Yr.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Zr(r):void 0;return{videoId:n,startSeconds:i}}function Zr(e){if(/^\d+$/.test(e))return Number(e);let t=/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(e);if(!(!t||!t[1]&&!t[2]&&!t[3]))return Number(t[1]??0)*3600+Number(t[2]??0)*60+Number(t[3]??0)}const Qr=[e=>{let t=Xr(e);if(!t)return;let n=t.startSeconds?`?start=${t.startSeconds}`:``;return{kind:`youtube`,key:`youtube:${t.videoId}:${t.startSeconds??0}`,src:`https://www.youtube-nocookie.com/embed/${t.videoId}${n}`,title:`YouTube video`,className:`md-embed md-embed-youtube`,testid:`youtube-embed`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen`,allowFullscreen:!0}},Gr];function K(e){for(let t of Qr){let n=t(e);if(n)return n}}function $r(e){return/^https?:\/\//i.test(e)?e:void 0}function ei(e){let t=document.createElement(`iframe`);return t.src=e.src,t.title=e.title,t.className=e.className,t.dataset.testid=e.testid,t.loading=`lazy`,t.referrerPolicy=`strict-origin-when-cross-origin`,t.setAttribute(`frameborder`,`0`),e.allow&&(t.allow=e.allow),e.allowFullscreen&&(t.allowFullscreen=!0),e.kind===`tweet`&&Kr(t),t}function ti(e,t,n){let r=K(e);if(r){let e=document.createElement(`span`);return e.className=`md-image-preview md-image-preview-embed`,e.appendChild(ei(r)),e}let i=(n.resolveImageUrl??$r)(e);if(!i)return;let a=document.createElement(`span`);a.className=`md-image-preview md-image-preview-img`,a.dataset.testid=`image-preview`;let o=document.createElement(`img`);return o.src=i,o.alt=t,o.draggable=!1,a.appendChild(o),a}function ni(e){return t=>{let n=t.attrs,r=document.createElement(`span`);r.className=`md-image-view`;let i=document.createElement(`span`);i.className=`md-image-view-content`,r.appendChild(i);let a=ti(n.src,n.alt,e);return a&&(a.contentEditable=`false`,r.appendChild(a)),{dom:r,contentDOM:i,ignoreMutation:e=>!i.contains(e.target)}}}function ri(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const ii=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function ai(e,t,n,r=ii,i){let a=i;for(let i of t){let t;try{t=await n(i)}catch(e){r(e,i);continue}if(!t||e.isDestroyed)continue;let o=``,s=a==null?e.state.tr.insertText(o):e.state.tr.insertText(o,a);e.dispatch(s),a!=null&&(a+=o.length)}}function oi(e){return new _({key:new v(`image-input`),props:{handlePaste:(t,n)=>{let r=ri(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(ai(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=ri(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(ai(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function si(e={}){return h(u({name:`mdImageView`,constructor:ni(e)}),g(p(oi(e)),t.high))}const ci=new v(`meowdown-image-click`);function li(e,t){let n=w(e,t,`mdImageSource`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function ui(e){return p(new _({key:ci,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-image-preview`);if(!i)return!1;let a=i.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(!a)return!1;let o=li(t.state,t.posAtDOM(a,0));return o?(e({src:o.src,alt:o.alt,event:r}),!0):!1}}}))}const di=new v(`meowdown-embed-paste`);function fi(e){let t=e.trim();if(!(!t||/\s/.test(t)))return K(t)?t:void 0}function pi(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
|
|
3
|
-
|
|
4
|
-
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function Ti(e,t){let n=0,r=0;for(;r<e.length&&n<t;){let t=e.charCodeAt(r);if(t===32)n+=1;else if(t===9)n+=4-n%4;else break;r++}return e.slice(r)}function Ei(e,t){return t===0||!e.includes(`
|
|
1
|
+
import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineCommands as o,defineHistory as s,defineKeymap as c,defineMarkSpec as l,defineMarkView as u,defineNodeAttr as d,defineNodeSpec as f,definePlugin as p,getMarkRange as m,getMarkType as ee,getNodeType as te,isAtBlockStart as ne,isTextSelection as re,toggleNode as ie,union as h,unsetBlockType as ae,withPriority as oe,withPriority as g,withSkipCodeBlock as se}from"@prosekit/core";import{definePlaceholder as ce}from"@prosekit/extensions/placeholder";import{defineReadonly as le}from"@prosekit/extensions/readonly";import{once as _}from"@ocavue/utils";import{defineBlockquote as ue}from"@prosekit/extensions/blockquote";import{defineCodeBlock as de,defineCodeBlockHighlight as fe}from"@prosekit/extensions/code-block";import{defineDoc as pe}from"@prosekit/extensions/doc";import{defineGapCursor as me}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as he}from"@prosekit/extensions/mod-click-prevention";import{defineText as ge}from"@prosekit/extensions/text";import{defineVirtualSelection as _e}from"@prosekit/extensions/virtual-selection";import{Plugin as v,PluginKey as y,TextSelection as b}from"@prosekit/pm/state";import{Decoration as ve,DecorationSet as x}from"@prosekit/pm/view";import{LanguageDescription as ye}from"@codemirror/language";import{languages as be}from"@codemirror/language-data";import{classHighlighter as xe,highlightTree as Se}from"@lezer/highlight";import{createParser as Ce}from"prosemirror-highlight/lezer";import{defineHeadingCommands as we,defineHeadingInputRule as Te,defineHeadingSpec as Ee}from"@prosekit/extensions/heading";import{defineHorizontalRule as De}from"@prosekit/extensions/horizontal-rule";import{ReplaceStep as Oe,Step as ke,StepResult as Ae,Transform as je}from"@prosekit/pm/transform";import{DOMSerializer as Me,Mark as Ne}from"@prosekit/pm/model";import{GFM as Pe,parser as Fe}from"@lezer/markdown";import{defineInputRule as Ie}from"@prosekit/extensions/input-rule";import{defineListCommands as Le,defineListDropIndicator as Re,defineListKeymap as ze,defineListPlugins as Be,defineListSerializer as Ve,defineListSpec as He,wrapInList as S}from"@prosekit/extensions/list";import{wrappingListInputRule as C}from"prosemirror-flat-list";import{defineParagraphCommands as Ue,defineParagraphKeymap as We}from"@prosekit/extensions/paragraph";import{defineTableCellSpec as Ge,defineTableCommands as Ke,defineTableDropIndicator as qe,defineTableEditingPlugin as Je,defineTableHeaderCellSpec as Ye,defineTableRowSpec as Xe,defineTableSpec as Ze,deleteTable as Qe,isCellSelection as $e}from"@prosekit/extensions/table";import{closeHistory as et}from"@prosekit/pm/history";import tt from"rehype-parse";import nt from"rehype-remark";import rt from"remark-gfm";import it from"remark-stringify";import{unified as at}from"unified";import{triggerAutocomplete as ot}from"@prosekit/extensions/autocomplete";function w(e,t,n){let r=e.doc.content.size;if(t<0||t>r)return;let i=e.doc.resolve(t);if(!(!i.parent.isTextblock||i.parent.type.spec.code))return m(i,n)}const st=new Set([`mdMark`,`mdLinkUri`]),ct=new Set([`mdImageSource`,`mdWikilinkSource`]),lt=new y(`mark-mode`);function ut(e){return new v({key:lt,state:{init:()=>e,apply:(e,t)=>t},props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>mt(e):void 0,clipboardTextSerializer:e===`show`?void 0:pt}})}function dt(e){return p(ut(e))}function ft(e){return lt.getState(e)}function pt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(!e.marks.some(e=>ct.has(e.type.name))&&e.marks.some(e=>st.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
|
|
2
|
+
`)}function mt(e){let{selection:t}=e;if(!t.empty)return x.empty;let n=t.$head,{parent:r}=n;if(!r.isTextblock||r.type.spec.code)return x.empty;let i=m(n,ee(e.schema,`mdPack`));return i?x.create(e.doc,[ve.inline(i.from,i.to,{class:`show`})]):x.empty}function T(e,t){let n=ft(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function E(e,t,n){for(let r of n){let n=w(e,t,r);if(n)return n}}function D(e,t,n){let r=E(e,t,n);return r&&r.to===t?r:void 0}function O(e,t,n){let r=E(e,t,n);return r&&r.from===t?r:void 0}function k(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=E(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function ht(e,t){return b.create(e.doc,t.from,t.to)}function gt(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!re(t.selection))return!1;let i=t.selection;if(i.empty){let e=O(t,i.from,r);if(e)return n?.(t.tr.setSelection(ht(t,e))),!0;if(D(t,i.from,r)){let e=t.doc.resolve(i.from);return i.from>=e.end()?!1:(n?.(t.tr.setSelection(b.create(t.doc,i.from+1))),!0)}return!1}let a=k(t,r);return a?(n?.(t.tr.setSelection(b.create(t.doc,a.to))),!0):!1}}function _t(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!re(t.selection))return!1;let i=t.selection;if(i.empty){let e=D(t,i.from,r);return e?(n?.(t.tr.setSelection(ht(t,e))),!0):!1}let a=k(t,r);return a?(n?.(t.tr.setSelection(b.create(t.doc,a.from))),!0):!1}}function vt(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=D(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!O(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function yt(e){return(t,n)=>{let r=T(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=O(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!D(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}function bt(e,t){return new v({key:new y(`atomic-mark-selection-${t}`),props:{decorations:n=>{let r=T(e,n);if(r.length===0)return;let i=k(n,r);if(i)return x.create(n.doc,[ve.inline(i.from,i.to,{class:t})])}}})}function xt({marks:e,selectedClass:n}){return h(g(c({ArrowRight:gt(e),ArrowLeft:_t(e),Backspace:vt(e),Delete:yt(e)}),t.high),p(bt(e,n)))}const A=new Map,St=new Map;async function Ct(e){let t=A.get(e);if(t!==void 0)return t;let n=ye.matchLanguageName(be,e,!0);if(!n)return A.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),A.set(e,null),null}return A.set(e,r),r}function wt(e,t){let n=St.get(e);if(n)return n;let r=Ce({parse:e=>t.language.parser.parse(e.content),highlighter:xe});return St.set(e,r),r}const Tt=e=>{let t=e.language?.trim();if(!t)return[];let n=A.get(t);return n===null?[]:n?wt(t,n)(e):Ct(t).then(()=>void 0)};function Et(){return fe({parser:Tt,nodeTypes:[`codeBlock`]})}function Dt(e,t){let n=t.language.parser.parse(e),r=[];return Se(n,xe,(e,t,n)=>{r.push([e,t,n])}),r}function Ot(e,t){let n=t.trim();if(!n)return[];let r=A.get(n);return r===null?[]:r?Dt(e,r):Ct(n).then(t=>t?Dt(e,t):[])}function kt(){return d({type:`doc`,attr:`frontmatter`,default:null})}function At(){return f({name:`heading`,whitespace:`pre`})}function jt(){return d({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function j(e){return se(ie({type:`heading`,attrs:{level:e}}))}const Mt=(e,t,n)=>ne(e,n)?.parent.type.name===`heading`?ae()(e,t,n):!1;function Nt(){return c({"Mod-1":j(1),"Mod-2":j(2),"Mod-3":j(3),"Mod-4":j(4),"Mod-5":j(5),"Mod-6":j(6),Backspace:Mt})}function Pt(){return h(Ee(),At(),jt(),Te(),we(),Nt())}function Ft(){return d({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function It(){return h(De(),Ft())}function Lt(){return f({name:`htmlComment`,group:`block`,atom:!0,selectable:!1,attrs:{content:{default:``}},toDOM:e=>[`div`,{"data-html-comment":e.attrs.content,style:`display: none`}],parseDOM:[{tag:`div[data-html-comment]`,getAttrs:e=>({content:e.getAttribute(`data-html-comment`)??``})}]})}function Rt(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function zt(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ne.fromJSON(e,t))]}var M=class e extends ke{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Ae.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new je(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new je(e),n.addMark(i,c,t));return!1})}return Ae.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Bt;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new Oe(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(Rt)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>zt(t,e)))}};ke.jsonID(`batchSetMark`,M);const Bt=new M([]),Vt=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),Ht=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function Ut(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function Wt(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!Vt.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!Ht.test(e))return!1;return!0}function Gt(e){return e===32||e===9||e===10||e===13}const Kt=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,qt=/[\s(*_~]/;function Jt(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function Yt(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function Xt(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&Yt(e,t,`)`)>Yt(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const Zt={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!Jt(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!qt.test(r))return-1;let i=Kt.exec(e.slice(n,e.end));if(!i)return-1;let a=Xt(i[0]);return a===0||!Wt(Ut(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function Qt(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function $t(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const en={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!Qt(t))break;i||=$t(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},tn={resolve:`Highlight`,mark:`HighlightMark`},nn=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,rn={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=nn.test(r),c=nn.test(i);return e.addDelimiter(tn,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]},an={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function on(e){return e.end}const N=Fe.configure([Pe,en,an,Zt,rn]),sn=N.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:on}]});function P(e){return N.parseInline(e,0)}function F(e,t,n=[]){for(let r of e)t(r)&&n.push(r),F(r.children,t,n);return n}function cn(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const I=cn(N);function ln(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}function un(e){let t=e.replace(/^\[\[/,``).replace(/\]\]$/,``),n=t.indexOf(`|`);return n<0?{target:t.trim(),display:``}:{target:t.slice(0,n).trim(),display:t.slice(n+1).trim()}}function dn(){return e=>{let t=e.attrs,n=document.createElement(`span`);n.className=`md-wikilink-view`;let r=document.createElement(`span`);r.className=`md-wikilink-label`,r.contentEditable=`false`,r.dataset.testid=`wikilink`,r.textContent=t.display||t.target,n.appendChild(r);let i=document.createElement(`span`);return i.className=`md-wikilink-view-content`,n.appendChild(i),{dom:n,contentDOM:i,ignoreMutation:e=>!i.contains(e.target)}}}function fn(){return u({name:`mdWikilinkView`,constructor:dn()})}const L=new Map([[I.Emphasis,`mdEm`],[I.StrongEmphasis,`mdStrong`],[I.InlineCode,`mdCode`],[I.Strikethrough,`mdDel`],[I.Highlight,`mdHighlight`],[I.EmphasisMark,`mdMark`],[I.CodeMark,`mdMark`],[I.LinkMark,`mdMark`],[I.StrikethroughMark,`mdMark`],[I.HighlightMark,`mdMark`],[I.URL,`mdLinkUri`],[I.Hashtag,`mdTag`],[I.WikilinkMark,`mdMark`]]);function pn(e,t){let n=P(t),r=[];return R(n,[],0,t.length,t,e,r),r}function mn(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||Wt(Ut(e)))return`https://${e}`}function R(e,t,n,r,i,a,o){let s=n;for(let n of e){n.from>s&&z(o,s,n.from,t);let e=n.type;if(e===I.Link)hn(n,t,i,a,o);else if(e===I.Image)gn(n,t,i,a,o);else if(e===I.Wikilink)_n(n,t,i,a,o);else if(e===I.URL){let e=mn(i.slice(n.from,n.to)),r=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();z(o,n.from,n.to,[...t,r])}else{let r;e===I.Emphasis?r=`italic`:e===I.StrongEmphasis?r=`bold`:e===I.InlineCode?r=`code`:e===I.Strikethrough?r=`strike`:e===I.Highlight?r=`highlight`:e===I.Autolink&&(r=`autolink`);let s=r?[...t,a.mdPack.create({key:r})]:t,c=L.get(e),l=c?[...s,a[c].create()]:s;n.children.length===0?z(o,n.from,n.to,l):R(n.children,l,n.from,n.to,i,a,o)}s=n.to}s<r&&z(o,s,r,t)}function hn(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===I.LinkMark?(s++,s===2&&(a=t.from)):t.type===I.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c?r.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=r.mdPack.create({key:`link_${c}`}),f=[...t,d],p=e.from;for(let t of e.children){if(t.from>p){let e=u(p)?[...f,l]:f;z(i,p,t.from,e)}let e=u(t.from)?[...f,l]:f;if(t.type===I.Wikilink){_n(t,e,n,r,i),p=t.to;continue}let a=L.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?z(i,t.from,t.to,o):R(t.children,o,t.from,t.to,n,r,i),p=t.to}p<e.to&&z(i,p,e.to,f)}function gn(e,t,n,r,i){let a=e.children.find(e=>e.type===I.URL);if(!a){hn(e,t,n,r,i);return}let o=e.children.filter(e=>e.type===I.LinkMark),s=n.slice(a.from,a.to),c=o.length>=2?n.slice(o[0].to,o[1].from):``,l=r.mdImageSource.create({src:s,alt:c}),u=r.mdImageView.create({src:s,alt:c}),d=r.mdPack.create({key:`image_${s}`}),f=e.to-1,p=e=>e>=f?[...t,d,l,u]:[...t,d,l],m=e.from;for(let t of e.children){t.from>m&&z(i,m,t.from,p(m));let e=L.get(t.type),a=e?[...p(t.from),r[e].create()]:p(t.from);t.children.length===0?z(i,t.from,t.to,a):R(t.children,a,t.from,t.to,n,r,i),m=t.to}m<e.to&&z(i,m,e.to,p(m))}function _n(e,t,n,r,i){let{target:a,display:o}=un(n.slice(e.from,e.to)),s=r.mdWikilinkSource.create({target:a}),c=r.mdWikilinkView.create({target:a,display:o}),l=e.to-1,u=e=>e>=l?[...t,s,c]:[...t,s],d=e.from;for(let t of e.children){t.from>d&&z(i,d,t.from,u(d));let e=r.mdMark.create();t.from<l&&t.to>l?(z(i,t.from,l,[...u(t.from),e]),z(i,l,t.to,[...u(l),e])):z(i,t.from,t.to,[...u(t.from),e]),d=t.to}d<e.to&&z(i,d,e.to,u(d))}function z(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&ln(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const vn=`inline-marks-applied`,yn=new WeakMap;let bn=0,xn=0;function Sn(e,t,n){let r=yn.get(e);if(r?xn++:(bn++,r=pn(Ar(n),e.textContent),yn.set(e,r)),t===0)return r;let i=[];for(let[e,n,a]of r)i.push([e+t,n+t,a]);return i}function Cn(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function wn(e,t){let n=[];return e.doc.nodesBetween(t.from,t.to,(t,r)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let i=Sn(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function Tn(){return new v({key:new y(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(vn))return null;let r=wn(n,Cn(e,n));if(r.length===0)return null;let i=n.tr.step(new M(r));return i.setMeta(vn,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(En(e.state)),{}}})}function En(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function Dn(){return p(Tn())}function On(){return l({name:`mdImageView`,inclusive:!1,attrs:{src:{default:``},alt:{default:``}},toDOM:()=>[`span`,{class:`md-image-anchor`},0],parseDOM:[{tag:`span.md-image-anchor`}]})}function kn(){return l({name:`mdImageSource`,inclusive:!1,attrs:{src:{default:``},alt:{default:``}},toDOM:()=>[`span`,{class:`md-image-source`},0],parseDOM:[{tag:`span.md-image-source`}]})}function An(){return l({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function jn(){return l({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function Mn(){return l({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function Nn(){return l({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Pn(){return l({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{class:`md-link`,href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function Fn(){return l({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function In(){return l({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Ln(){return l({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function Rn(){return l({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function zn(){return l({name:`mdWikilinkSource`,inclusive:!1,attrs:{target:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink-source`},0],parseDOM:[{tag:`span.md-wikilink-source`}]})}function Bn(){return l({name:`mdWikilinkView`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink-anchor`},0],parseDOM:[{tag:`span.md-wikilink-anchor`}]})}function Vn(){return l({name:`mdPack`,excludes:``,inclusive:!1,attrs:{key:{default:``}},toDOM:e=>[`span`,{class:`md-pack`,"data-key":e.attrs.key},0],parseDOM:[{tag:`span.md-pack`}]})}function Hn(){return h(An(),jn(),Mn(),Nn(),Pn(),Fn(),In(),Ln(),Rn(),zn(),Bn(),kn(),On(),Vn())}function Un(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const B={em:{node:I.Emphasis,delim:`*`},strong:{node:I.StrongEmphasis,delim:`**`},code:{node:I.InlineCode,delim:"`"},del:{node:I.Strikethrough,delim:`~~`},highlight:{node:I.Highlight,delim:`==`}},Wn=new Set([I.EmphasisMark,I.CodeMark,I.LinkMark,I.StrikethroughMark,I.HighlightMark]);function V(e){return[e.children[0],e.children.at(-1)]}function Gn(e){let{type:t,children:n}=e;if(t===I.Emphasis||t===I.StrongEmphasis||t===I.Strikethrough||t===I.Highlight)return[n[0].to,n.at(-1).from];if(t===I.Link||t===I.Image){let e=n.find((e,t)=>t>0&&e.type===I.LinkMark);return e?[n[0].to,e.from]:null}return null}function H(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Gn(r);return i&&i[0]<=t&&n<=i[1]?H(r.children,t,n):H(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Kn(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Kn(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const U=e=>e===` `||e===` `;function qn(e,t,n){for(;t<n&&U(e[t]);)t++;for(;n>t&&U(e[n-1]);)n--;return[t,n]}function Jn(e,t,n,r){let i=F(P(e),e=>e.type===r.node||Wn.has(e.type));for(let r=t;r<n;r++)if(!U(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Yn(e,t,n,r,i){let a=P(e),o=F(a,e=>e.type===r.node);return i?Qn(e,o,t,n):Xn(e,a,o,t,n,r)}function Xn(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=H(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=V(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Zn(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Zn(e,t,n,r,i){if(i.node!==I.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(Un(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Qn(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=V(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Kn(a.children.slice(1,-1),s,c);s>t.to&&U(e[s-1]);)s--;for(;c<o.from&&U(e[c]);)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function $n(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=P(e),o=F(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=V(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return er(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function er(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Gn(n);return!e||t<e[0]||t>e[1]?!0:er(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return tr(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=qn(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:Jn(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Yn(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(b.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function tr(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=$n(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(b.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(b.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function nr(){return o({toggleEm:()=>W(B.em),toggleStrong:()=>W(B.strong),toggleCode:()=>W(B.code),toggleDel:()=>W(B.del),toggleHighlight:()=>W(B.highlight)})}function rr(){return c({"Mod-b":W(B.strong),"Mod-i":W(B.em),"Mod-e":W(B.code),"Mod-Shift-x":W(B.del),"Mod-Shift-h":W(B.highlight)})}function ir(){return h(nr(),rr())}function ar(){return d({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>e===`)`||e===`*`||e===`+`?[`data-list-marker`,e]:null,parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function or(){return d({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>e===`X`?[`data-list-task-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function sr(e){return e===2||e===3||e===4}function cr(){return d({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>sr(e)?[`data-list-marker-gap`,String(e)]:null,parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return sr(t)?t:1}})}const lr=[C(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),C(/^\s?(\d+)\.\s$/,({match:e})=>{let t=e[1],n=t?parseInt(t,10):void 0;return{kind:`ordered`,collapsed:!1,order:n&&n>=2&&Number.isSafeInteger(n)?n:null}}),C(/^\s?\[([\sXx]?)]\s$/,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),C(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function ur(){return h(lr.map(Ie))}function dr(){return S({kind:`task`,marker:`+`})}function fr(){return S({kind:`task`,marker:null})}function pr(){return o({wrapInCircleTask:dr,wrapInSquareTask:fr})}function mr(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function hr(){return(e,t,n)=>{let r=mr(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},S(a)(e,t,n)}}function gr(){return(e,t,n)=>{let r=mr(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},S(a)(e,t,n)}}function _r(){return c({"Mod-Enter":hr(),"Mod-Shift-Enter":gr()})}function vr(){return h(He(),Be(),ze(),Le(),Ve(),Re(),ur(),_r(),ar(),or(),cr(),pr())}function yr(){return f({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function br(){return h(g(yr(),t.highest),Ue(),We())}const xr=(e,t)=>{let{selection:n}=e;return!$e(n)||!n.isColSelection()||!n.isRowSelection()?!1:Qe(e,t)};function Sr(){return g(c({Backspace:xr,Delete:xr}),t.high)}function Cr(){return h(Ze(),Xe(),Ge(),Ye(),Je({allowTableNodeSelection:!0}),Ke(),qe(),Sr())}function wr(){return h(br(),pe(),kt(),ge(),ue(),vr(),Pt(),Cr(),de(),It(),Lt(),Hn(),Et(),Dn(),ir(),fn(),xt({marks:[{name:`mdImageSource`,modes:[`hide`]},{name:`mdWikilinkSource`,modes:[`hide`,`focus`,`show`]}],selectedClass:`md-atomic-selected`}),a(),i(),s(),me(),_e(),he())}function Tr(){return wr()}const Er=_(()=>{let e=Tr().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Dr=_(()=>r(Er())),Or=_(()=>n(Er())),kr=`meowdown_mark_builders`;function Ar(e){let t=e.cached[kr];if(t)return t;let r=n(e);return e.cached[kr]=r,r}const jr=`meowdown_node_builders`;function Mr(e){let t=e.cached[jr];if(t)return t;let n=r(e);return e.cached[jr]=n,n}function G(e,t={}){let{nodes:n=Dr(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=Pr(e);i=t,n&&(a=e.slice(n))}let o=Fr(n,sn.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const Nr=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function Pr(e){let t=Nr.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function Fr(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...K(e,t,n));while(t.nextSibling());return t.parent(),r}function K(e,t,n){switch(t.type.id){case I.ATXHeading1:return[q(e,t,n,1,!1)];case I.ATXHeading2:return[q(e,t,n,2,!1)];case I.ATXHeading3:return[q(e,t,n,3,!1)];case I.ATXHeading4:return[q(e,t,n,4,!1)];case I.ATXHeading5:return[q(e,t,n,5,!1)];case I.ATXHeading6:return[q(e,t,n,6,!1)];case I.SetextHeading1:return[q(e,t,n,1,!0)];case I.SetextHeading2:return[q(e,t,n,2,!0)];case I.Paragraph:return[Z(e,t,n)];case I.CommentBlock:return[Rr(e,t,n)];case I.HTMLBlock:case I.ProcessingInstructionBlock:return[Z(e,t,n)];case I.Blockquote:return[zr(e,t,n)];case I.BulletList:return Br(e,t,n,`bullet`);case I.OrderedList:return Br(e,t,n,`ordered`);case I.FencedCode:case I.CodeBlock:return[Hr(e,t,n)];case I.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case I.Table:return[Ur(e,t,n)];case I.Task:return[Z(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[Z(e,t,n)])}}function q(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===I.HeaderMark&&t.from===a&&(o=t.to);let e=-1,n=-1,r=-1;do e=t.type.id,n=t.from,r=t.to;while(t.nextSibling());e===I.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=Y(n.slice(o,s),J(n,o)).trim(),d=i?Ir(n,c,l)||1:null;return e.heading({level:r,setextUnderline:d},u)}function Ir(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);(t===61||t===45)&&r++}return r}function J(e,t){let n=e.lastIndexOf(`
|
|
3
|
+
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function Lr(e,t){let n=0,r=0;for(;r<e.length&&n<t;){let t=e.charCodeAt(r);if(t===32)n+=1;else if(t===9)n+=4-n%4;else break;r++}return e.slice(r)}function Y(e,t){return t===0||!e.includes(`
|
|
5
4
|
`)?e:e.split(`
|
|
6
|
-
`).map((e,n)=>n===0?e:
|
|
7
|
-
`)}function
|
|
5
|
+
`).map((e,n)=>n===0?e:Lr(e,t)).join(`
|
|
6
|
+
`)}function X(e,t,n){return e.paragraph(Y(t,n))}function Z(e,t,n){let r=t.from,i=t.to,a=J(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===I.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,Gt(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),X(e,o,a)}return X(e,n.slice(r,i),a)}function Rr(e,t,n){let r=J(n,t.from),i=Y(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function zr(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===I.QuoteMark)continue;r.push(...K(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Br(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===I.ListItem&&i.push(Vr(e,t,n,r));while(t.nextSibling());t.parent()}return i}function Vr(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==I.ListMark&&u==null&&(u=J(n,t.from)),t.type.id===I.ListMark){if(r===`ordered`){let e=n.charCodeAt(t.to-1);e===41?c=`)`:e===46&&(c=`.`);let r=Number.parseInt(n.slice(t.from,t.to),10);s=Number.isFinite(r)?r:1}else{let e=n.charCodeAt(t.from);c=e===42?`*`:e===43?`+`:`-`}l=J(n,t.to);continue}if(r===`bullet`&&t.type.id===I.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===I.TaskMarker){let e=n.charCodeAt(t.from+1);e===120?(a=!0,o=`x`):e===88&&(a=!0,o=`X`),r=t.to}t.parent()}Gt(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(X(e,c,J(n,r)));continue}i.push(...K(e,t,n))}while(t.nextSibling());t.parent()}let d=u!=null&&l!=null?u-l:1;return e.list({kind:a==null?r:`task`,order:r===`ordered`?s??1:null,checked:a??!1,collapsed:!1,marker:c,taskMarker:o,markerGap:d>=2&&d<=4?d:1},i)}function Hr(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case I.CodeInfo:r=n.slice(t.from,t.to);break;case I.CodeText:i+=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:r},i)}function Ur(e,t,n){let r=0;if(t.firstChild()){do t.type.id===I.TableDelimiter&&(r=Wr(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===I.TableHeader?i.push(Gr(e,t,n,!0,r)):a===I.TableRow&&i.push(Gr(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function Wr(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function Gr(e,t,n,r,i){let a=Array(i).fill(``);if(t.firstChild()){let e=t.type.id===I.TableDelimiter,r=0;do if(t.type.id===I.TableDelimiter)r++;else if(t.type.id===I.TableCell){let o=r-+!!e;o>=0&&o<i&&(a[o]=n.slice(t.from,t.to).trim().replaceAll(String.raw`\|`,`|`))}while(t.nextSibling());t.parent()}let o=a.map(t=>{let n=e.paragraph(t);return r?e.tableHeaderCell(n):e.tableCell(n)});return e.tableRow(o)}function Q(e,t={}){let n=new Yr;return t.frontmatter&&Kr(e.attrs.frontmatter,n),Xr(e,n),n.finish()}function Kr(e,t){e!==null&&(t.write(`---`),t.write(`
|
|
8
7
|
`),e!==``&&(t.write(e),t.write(`
|
|
9
|
-
`)),t.write(`---`),t.closeBlock())}const
|
|
10
|
-
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(
|
|
8
|
+
`)),t.write(`---`),t.closeBlock())}const qr=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function Jr(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){$r(e,t);let i=n.level===1?`=`:`-`;t.write(`
|
|
9
|
+
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(qr[n.level]??`# `),$r(e,t),t.closeBlock()}var Yr=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
|
|
11
10
|
`)){this.parts.push(e);return}let t=e.split(`
|
|
12
11
|
`);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
|
|
13
12
|
`,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeBlock(){this.atLineStart&&this.pendingFirst!==null&&(this.emitDeferredBlankLine(),this.parts.push(this.pendingFirst.trimEnd()),this.pendingFirst=null,this.atLineStart=!1),this.atLineStart||this.parts.push(`
|
|
14
13
|
`),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=t===null?i:null}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
|
|
15
14
|
`}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
|
|
16
|
-
`),this.deferredBlankPrefix=null)}};function
|
|
15
|
+
`),this.deferredBlankPrefix=null)}};function Xr(e,t){switch(e.type.name){case`doc`:$(e,t);return;case`paragraph`:$r(e,t),t.closeBlock();return;case`heading`:Jr(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>$(e,t)),t.closeBlock();return;case`list`:ei(e,t,Qr(e));return;case`codeBlock`:ti(e,t);return;case`horizontalRule`:{let{marker:n}=e.attrs;t.write(n||`---`),t.closeBlock();return}case`htmlComment`:{let{content:n}=e.attrs;t.write(n),t.closeBlock();return}case`table`:ni(e,t);return;case`text`:e.text&&t.write(e.text);return}}function $(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),Xr(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=Zr(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),ei(e.child(r),t,s);i=o}}function Zr(e,t,n){for(let r=t;r<n;r++)if(!Qr(e.child(r)))return!1;return!0}function Qr(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function $r(e,t){let n=e.childCount;for(let r=0;r<n;r++){let n=e.child(r);n.isText&&n.text&&t.write(n.text)}}function ei(e,t,n){let r=e.attrs,i=r.marker===`*`||r.marker===`+`?r.marker:`-`,a=r.marker===`)`?`)`:`.`,o=r.taskMarker===`X`?`X`:`x`,s=Math.min(Math.max(r.markerGap??1,1),4),c=`${r.kind===`ordered`?`${r.order??1}${a}`:i}${` `.repeat(s)}`,l=r.kind===`task`?`${c}[${r.checked?o:` `}] `:c,u=` `.repeat(c.length);t.withPrefix(u,l,()=>$(e,t,n)),t.closeBlock()}function ti(e,t){let n=e.attrs.language||``,r=e.textContent,i="`".repeat(Un(r,2)+1);t.write(i),n&&t.write(n),t.write(`
|
|
17
16
|
`),r&&(t.write(r),t.write(`
|
|
18
|
-
`)),t.write(i),t.closeBlock()}function
|
|
17
|
+
`)),t.write(i),t.closeBlock()}function ni(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(ii(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=`| `+Array(i).fill(`---`).join(` | `)+` |`,s=a>=0?r[a]:Array(i).fill(``);t.write(ri(s,i)),t.write(`
|
|
19
18
|
`),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
20
|
-
`),t.write(
|
|
19
|
+
`),t.write(ri(r[e],i)));t.closeBlock()}function ri(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function ii(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
21
20
|
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
22
|
-
`,` `)}
|
|
21
|
+
`,` `)}function ai(e){return e.replace(/\n+$/u,``)}function oi(e){return/^[\s>]*$/u.test(e)}function si(e){return e.split(`
|
|
22
|
+
`).filter(e=>!oi(e))}function ci(e,t={}){let n=Q(G(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(ai(n)===ai(e))return`exact`;let r=si(e),i=si(n);return r.length===i.length&&r.every((e,t)=>e.trimEnd()===i[t].trimEnd())?`normalizing`:`lossy`}const li=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=te(e.schema,`list`),i=te(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(b.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function ui(){return g(c({Enter:li}),t.high)}const di=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`]),fi=be.map(e=>e.name).filter(e=>!di.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function pi(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const mi=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,hi=/\/status(?:es)?\/(\d+)/;function gi(e){let t;try{t=new URL(e)}catch{return}if(mi.test(t.hostname))return hi.exec(t.pathname)?.[1]}const _i=e=>{let t=gi(e);if(!t)return;let n=pi()?`dark`:`light`;return{kind:`tweet`,key:`tweet:${t}`,src:`https://platform.twitter.com/embed/Tweet.html?id=${t}&theme=${n}&dnt=true`,title:`Tweet`,className:`md-embed md-embed-tweet`,testid:`tweet-embed`}};function vi(e){let t=t=>{if(t.source===e.contentWindow)try{let n=t.data?.[`twttr.embed`]?.params?.[0]?.height;typeof n==`number`&&(e.style.height=`${n}px`)}catch(e){console.warn(`[meowdown] failed to parse tweet resize message:`,e)}};window.addEventListener(`message`,t);let n=!1,r=()=>{n||(n=!0,window.removeEventListener(`message`,t),i.disconnect())},i=new MutationObserver(()=>{e.isConnected||r()});return i.observe(document.body,{childList:!0,subtree:!0}),r}const yi=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,bi=/^(?:www\.)?youtu\.be$/i,xi=/^[\w-]{11}$/;function Si(e){let t;try{t=new URL(e)}catch{return}let n=null;if(bi.test(t.hostname))n=t.pathname.slice(1);else if(yi.test(t.hostname)){let[,e,r]=t.pathname.split(`/`);t.pathname===`/watch`?n=t.searchParams.get(`v`):(e===`shorts`||e===`embed`||e===`live`)&&(n=r??null)}if(!n||!xi.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Ci(r):void 0;return{videoId:n,startSeconds:i}}function Ci(e){if(/^\d+$/.test(e))return Number(e);let t=/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(e);if(!(!t||!t[1]&&!t[2]&&!t[3]))return Number(t[1]??0)*3600+Number(t[2]??0)*60+Number(t[3]??0)}const wi=[e=>{let t=Si(e);if(!t)return;let n=t.startSeconds?`?start=${t.startSeconds}`:``;return{kind:`youtube`,key:`youtube:${t.videoId}:${t.startSeconds??0}`,src:`https://www.youtube-nocookie.com/embed/${t.videoId}${n}`,title:`YouTube video`,className:`md-embed md-embed-youtube`,testid:`youtube-embed`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen`,allowFullscreen:!0}},_i];function Ti(e){for(let t of wi){let n=t(e);if(n)return n}}const Ei=new y(`meowdown-embed-paste`);function Di(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Ti(t)?t:void 0}function Oi(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
|
|
23
|
+
`)}function ki(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(et(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(et(i))}function Ai(){return p(new v({key:Ei,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Oi(t,n);if(!i)return!1;let a=Di(i);return a?(ki(e,a),!0):!1}}}))}const ji=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},Mi=(e,t,n,r)=>{let i=e,a=n.createTracker(r),o=a.move(`==`);return o+=a.move(n.containerPhrasing(i,{...a.current(),before:o,after:`=`})),o+=a.move(`==`),o};function Ni(){return at().use(tt).use(nt,{handlers:{mark:ji}}).use(rt).use(it,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:Mi}}).freeze()}const Pi=_(Ni);function Fi(e){return String(Pi().processSync(e))}const Ii=new y(`meowdown-html-paste`);function Li(){return p(new v({key:Ii,props:{transformPastedHTML:(e,t)=>{if(e.includes(`data-pm-slice`))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=Fi(e);if(!r.trim())return e;let i=G(r,{nodes:Mr(t.state.schema)}),a=Me.fromSchema(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}const Ri=new y(`meowdown-image-click`);function zi(e,t){let n=w(e,t,`mdImageSource`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Bi(e){return p(new v({key:Ri,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-image-preview`);if(!i)return!1;let a=i.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(!a)return!1;let o=zi(t.state,t.posAtDOM(a,0));return o?(e({src:o.src,alt:o.alt,event:r}),!0):!1}}}))}function Vi(e){return/^https?:\/\//i.test(e)?e:void 0}function Hi(e){let t=document.createElement(`iframe`);return t.src=e.src,t.title=e.title,t.className=e.className,t.dataset.testid=e.testid,t.loading=`lazy`,t.referrerPolicy=`strict-origin-when-cross-origin`,t.setAttribute(`frameborder`,`0`),e.allow&&(t.allow=e.allow),e.allowFullscreen&&(t.allowFullscreen=!0),e.kind===`tweet`&&vi(t),t}function Ui(e,t,n){let r=Ti(e);if(r){let e=document.createElement(`span`);return e.className=`md-image-preview md-image-preview-embed`,e.appendChild(Hi(r)),e}let i=(n.resolveImageUrl??Vi)(e);if(!i)return;let a=document.createElement(`span`);a.className=`md-image-preview md-image-preview-img`,a.dataset.testid=`image-preview`;let o=document.createElement(`img`);return o.src=i,o.alt=t,o.draggable=!1,a.appendChild(o),a}function Wi(e){return t=>{let n=t.attrs,r=document.createElement(`span`);r.className=`md-image-view`;let i=document.createElement(`span`);i.className=`md-image-view-content`,r.appendChild(i);let a=Ui(n.src,n.alt,e);return a&&(a.contentEditable=`false`,r.appendChild(a)),{dom:r,contentDOM:i,ignoreMutation:e=>!i.contains(e.target)}}}function Gi(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const Ki=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function qi(e,t,n,r=Ki,i){let a=i;for(let i of t){let t;try{t=await n(i)}catch(e){r(e,i);continue}if(!t||e.isDestroyed)continue;let o=``,s=a==null?e.state.tr.insertText(o):e.state.tr.insertText(o,a);e.dispatch(s),a!=null&&(a+=o.length)}}function Ji(e){return new v({key:new y(`image-input`),props:{handlePaste:(t,n)=>{let r=Gi(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(qi(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=Gi(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(qi(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function Yi(e={}){return h(u({name:`mdImageView`,constructor:Wi(e)}),g(p(Ji(e)),t.high))}const Xi={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-Shift-h":`Highlight`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`};function Zi(e){return p(new v({key:e.key,props:{handleClick:(t,n,r)=>{if(!r.target?.closest?.(e.selector))return!1;let i=e.findPayloadAt(t.state,n);return i==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(i,r),!0)}}}))}const Qi=new y(`meowdown-link-click`);function $i(e,t){let n=w(e,t,`mdLinkText`);if(n)return{from:n.from,to:n.to,href:n.mark.attrs.href}}function ea(e){return Zi({key:Qi,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>$i(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}const ta=new y(`meowdown-markdown-copy`);function na(){return p(new v({key:ta,props:{clipboardTextSerializer:(e,t)=>{let n=e.content,r;try{r=t.state.schema.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?Q(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
|
|
23
24
|
`,`
|
|
24
|
-
`)}}}))}const
|
|
25
|
-
`).filter(e=>!oa(e))}function ca(e,t={}){let n=$(q(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(aa(n)===aa(e))return`exact`;let r=sa(e),i=sa(n);return r.length===i.length&&r.every((e,t)=>e.trimEnd()===i[t].trimEnd())?`normalizing`:`lossy`}export{na as EDITOR_KEY_BINDINGS,e as Priority,ca as checkRoundTrip,ia as codeBlockLanguages,$r as defaultResolveImageUrl,$i as defineBulletAfterHeading,Et as defineCodeBlockSyntaxHighlight,jr as defineEditorExtension,hi as defineEmbedPaste,Fi as defineHTMLPaste,si as defineImage,ui as defineImageClickHandler,Lr as defineLinkClickHandler,dt as defineMarkMode,Zi as defineMarkdownCopy,at as definePlaceholder,ot as defineReadonly,Br as defineTagClickHandler,Pr as defineWikilinkClickHandler,ta as defineWikilinkTrigger,$ as docToMarkdown,Ot as getCodeTokens,yn as getMarkBuilders,fn as inlineTextToMarkChunks,Kr as listenForTweetHeight,q as markdownToDoc,K as matchEmbed,oe as withPriority};
|
|
25
|
+
`)}}}))}const ra=new y(`meowdown-tag-click`);function ia(e,t){let n=w(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function aa(e){return Zi({key:ra,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>ia(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const oa=new y(`meowdown-wikilink-click`);function sa(e,t){let n=w(e,t,`mdWikilinkSource`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function ca(e){return Zi({key:oa,selector:`.md-wikilink-label, .md-wikilink-source`,preventDefault:!1,findPayloadAt:(e,t)=>sa(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const la=(e,t)=>{let{selection:n}=e;if(!n.empty&&!n.$head.sameParent(n.$anchor))return!1;let r=e.doc.textBetween(n.from,n.to);if(r.startsWith(`[[`))return!1;r.startsWith(`[`)&&(r=r.slice(1));let i=`[[`+r;if(t){let r=e.tr.insertText(i,n.from,n.to);r.setSelection(b.create(r.doc,n.from+i.length)),ot(r),t(r.scrollIntoView())}return!0};function ua(){return c({"Mod-Shift-k":la})}export{Xi as EDITOR_KEY_BINDINGS,e as Priority,ci as checkRoundTrip,fi as codeBlockLanguages,Vi as defaultResolveImageUrl,ui as defineBulletAfterHeading,Et as defineCodeBlockSyntaxHighlight,Tr as defineEditorExtension,Ai as defineEmbedPaste,Lt as defineHTMLComment,Li as defineHTMLPaste,Yi as defineImage,Bi as defineImageClickHandler,ea as defineLinkClickHandler,dt as defineMarkMode,na as defineMarkdownCopy,ce as definePlaceholder,le as defineReadonly,aa as defineTagClickHandler,ca as defineWikilinkClickHandler,ua as defineWikilinkTrigger,Q as docToMarkdown,Ot as getCodeTokens,Or as getMarkBuilders,pn as inlineTextToMarkChunks,vi as listenForTweetHeight,G as markdownToDoc,Ti as matchEmbed,oe as withPriority};
|