@meowdown/core 0.65.0 → 0.65.2
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 +4 -1
- package/dist/index.js +90 -31
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -810,7 +810,7 @@ declare function defineEditorExtensionImpl(options: EditorExtensionOptions): imp
|
|
|
810
810
|
Commands: {
|
|
811
811
|
setMarkMode: [mode: MarkMode];
|
|
812
812
|
};
|
|
813
|
-
}>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<{
|
|
813
|
+
}>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<{
|
|
814
814
|
Commands: {
|
|
815
815
|
insertMarkdown: [markdown: string];
|
|
816
816
|
insertTrigger: [text: string];
|
|
@@ -1396,6 +1396,9 @@ type NodeName = (typeof NODE_NAMES)[number];
|
|
|
1396
1396
|
declare function isNodeOfType(node: ProseMirrorNode, name: NodeName): boolean;
|
|
1397
1397
|
//#endregion
|
|
1398
1398
|
//#region src/extensions/spell-check.d.ts
|
|
1399
|
+
/**
|
|
1400
|
+
* @deprecated This will be removed in future versions.
|
|
1401
|
+
*/
|
|
1399
1402
|
declare function defineSpellCheckPlugin(spellCheck: boolean): PlainExtension;
|
|
1400
1403
|
//#endregion
|
|
1401
1404
|
//#region src/extensions/substitution.d.ts
|
package/dist/index.js
CHANGED
|
@@ -440,13 +440,14 @@ function getSelectedAtomRange(state) {
|
|
|
440
440
|
return getSelectedRange(state, ATOM_SOURCE_MARK_NAMES);
|
|
441
441
|
}
|
|
442
442
|
function findSelectionAcrossBlockBoundary(state, pos, markNames, direction) {
|
|
443
|
+
const unitMarkNames = [...markNames, "mdPack"];
|
|
443
444
|
const $pos = state.doc.resolve(pos);
|
|
444
445
|
if (!(direction === -1 ? $pos.parentOffset === 0 : $pos.parentOffset === $pos.parent.content.size) || $pos.depth === 0) return;
|
|
445
|
-
const nearUnit = direction === -1 ? getMarkRangeAfter(state, pos,
|
|
446
|
+
const nearUnit = direction === -1 ? getMarkRangeAfter(state, pos, unitMarkNames) : getMarkRangeBefore(state, pos, unitMarkNames);
|
|
446
447
|
const boundary = direction === -1 ? $pos.before() : $pos.after();
|
|
447
448
|
const target = Selection.findFrom(state.doc.resolve(boundary), direction);
|
|
448
449
|
if (!target) return;
|
|
449
|
-
const farUnit = isTextSelection(target) ? direction === -1 ? getMarkRangeBefore(state, target.head,
|
|
450
|
+
const farUnit = isTextSelection(target) ? direction === -1 ? getMarkRangeBefore(state, target.head, unitMarkNames) : getMarkRangeAfter(state, target.head, unitMarkNames) : void 0;
|
|
450
451
|
if (nearUnit == null && farUnit == null) return;
|
|
451
452
|
return target;
|
|
452
453
|
}
|
|
@@ -2537,7 +2538,7 @@ const emptyBatchSetMarkStep = new BatchSetMarkStep([]);
|
|
|
2537
2538
|
//#endregion
|
|
2538
2539
|
//#region src/extensions/magic-comment.ts
|
|
2539
2540
|
const MAGIC_COMMENT_RE = /^<!--\s*(\{[^}]*\})\s*-->$/;
|
|
2540
|
-
const TRAILING_MAGIC_COMMENT_RE =
|
|
2541
|
+
const TRAILING_MAGIC_COMMENT_RE = /(?:<!--\s*\{[^}]*\}\s*-->)+$/;
|
|
2541
2542
|
/**
|
|
2542
2543
|
* Read the metadata out of a `<!-- {...} -->` comment, or `undefined` when the
|
|
2543
2544
|
* text is not a comment carrying at least one recognized field.
|
|
@@ -2570,7 +2571,7 @@ function formatMagicComment(magic) {
|
|
|
2570
2571
|
return `<!-- ${JSON.stringify(magic)} -->`;
|
|
2571
2572
|
}
|
|
2572
2573
|
/**
|
|
2573
|
-
* Drop
|
|
2574
|
+
* Drop the trailing run of magic comments from the source text.
|
|
2574
2575
|
*/
|
|
2575
2576
|
function stripMagicComment(source) {
|
|
2576
2577
|
return source.replace(TRAILING_MAGIC_COMMENT_RE, "");
|
|
@@ -2889,12 +2890,11 @@ function walk(nodes, parentMarks, rangeStart, rangeEnd, text, marks, out, option
|
|
|
2889
2890
|
let pos = rangeStart;
|
|
2890
2891
|
for (let index = 0; index < nodes.length; index++) {
|
|
2891
2892
|
const node = nodes[index];
|
|
2893
|
+
if (node.to <= pos) continue;
|
|
2892
2894
|
if (node.from > pos) emit(out, pos, node.from, parentMarks);
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
if (trailing) index++;
|
|
2897
|
-
pos = trailing ? trailing.to : node.to;
|
|
2895
|
+
const atomEnd = walkAtomChild(nodes, index, parentMarks, text, marks, out, options, context);
|
|
2896
|
+
if (atomEnd != null) {
|
|
2897
|
+
pos = atomEnd;
|
|
2898
2898
|
continue;
|
|
2899
2899
|
}
|
|
2900
2900
|
walkNode(node, parentMarks, text, marks, out, options, context);
|
|
@@ -2905,8 +2905,6 @@ function walk(nodes, parentMarks, rangeStart, rangeEnd, text, marks, out, option
|
|
|
2905
2905
|
function walkNode(node, parentMarks, text, marks, out, options, context) {
|
|
2906
2906
|
switch (node.type) {
|
|
2907
2907
|
case LEZER_NODE_IDS.Link: return walkLink(node, parentMarks, text, marks, out, options, context);
|
|
2908
|
-
case LEZER_NODE_IDS.Wikilink: return walkWikilink(node, parentMarks, text, marks, out);
|
|
2909
|
-
case LEZER_NODE_IDS.WikiEmbed: return walkWikiEmbed(node, parentMarks, text, marks, out, options);
|
|
2910
2908
|
case LEZER_NODE_IDS.InlineMath: return walkMath(node, parentMarks, text, marks, out);
|
|
2911
2909
|
case LEZER_NODE_IDS.Autolink: return walkAutolink(node, parentMarks, text, marks, out);
|
|
2912
2910
|
case LEZER_NODE_IDS.URL: return walkURL(node, parentMarks, text, marks, out);
|
|
@@ -2914,6 +2912,31 @@ function walkNode(node, parentMarks, text, marks, out, options, context) {
|
|
|
2914
2912
|
}
|
|
2915
2913
|
}
|
|
2916
2914
|
/**
|
|
2915
|
+
* Walk `nodes[index]` when it is a source-backed atom (wikilink, wiki embed,
|
|
2916
|
+
* or image); returns the source position after everything the atom consumed,
|
|
2917
|
+
* or undefined for any other node type. An image also consumes the magic
|
|
2918
|
+
* comments chained behind it, so callers must skip children ending at or
|
|
2919
|
+
* before the returned position. Shared by `walk` and `walkResolvedLink` so an
|
|
2920
|
+
* atom behaves the same at the top level and inside a link label.
|
|
2921
|
+
*/
|
|
2922
|
+
function walkAtomChild(nodes, index, parentMarks, text, marks, out, options, context) {
|
|
2923
|
+
const node = nodes[index];
|
|
2924
|
+
switch (node.type) {
|
|
2925
|
+
case LEZER_NODE_IDS.Wikilink:
|
|
2926
|
+
walkWikilink(node, parentMarks, text, marks, out);
|
|
2927
|
+
return node.to;
|
|
2928
|
+
case LEZER_NODE_IDS.WikiEmbed:
|
|
2929
|
+
walkWikiEmbed(node, parentMarks, text, marks, out, options);
|
|
2930
|
+
return node.to;
|
|
2931
|
+
case LEZER_NODE_IDS.Image: {
|
|
2932
|
+
const trailing = takeMagicComments(nodes, index, text);
|
|
2933
|
+
walkImage(node, parentMarks, text, marks, out, options, context, trailing);
|
|
2934
|
+
return trailing ? trailing.to : node.to;
|
|
2935
|
+
}
|
|
2936
|
+
default: return;
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
/**
|
|
2917
2940
|
* A node with no source-backed atom of its own: it contributes its `mdPack` and
|
|
2918
2941
|
* syntax marks, then recurses into its children.
|
|
2919
2942
|
*/
|
|
@@ -3131,25 +3154,17 @@ function walkResolvedLink(node, parts, resolution, parentMarks, text, marks, out
|
|
|
3131
3154
|
});
|
|
3132
3155
|
const base = [...parentMarks, pack];
|
|
3133
3156
|
let pos = node.from;
|
|
3134
|
-
for (
|
|
3157
|
+
for (let index = 0; index < node.children.length; index++) {
|
|
3158
|
+
const child = node.children[index];
|
|
3159
|
+
if (child.to <= pos) continue;
|
|
3135
3160
|
if (child.from > pos) {
|
|
3136
3161
|
const childMarks = inLabel(pos) ? [...base, linkTextMark] : base;
|
|
3137
3162
|
emit(out, pos, child.from, childMarks);
|
|
3138
3163
|
}
|
|
3139
3164
|
const baseForChild = inLabel(child.from) ? [...base, linkTextMark] : base;
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
pos =
|
|
3143
|
-
continue;
|
|
3144
|
-
}
|
|
3145
|
-
if (child.type === LEZER_NODE_IDS.WikiEmbed) {
|
|
3146
|
-
walkWikiEmbed(child, baseForChild, text, marks, out, options);
|
|
3147
|
-
pos = child.to;
|
|
3148
|
-
continue;
|
|
3149
|
-
}
|
|
3150
|
-
if (child.type === LEZER_NODE_IDS.Image) {
|
|
3151
|
-
walkImage(child, baseForChild, text, marks, out, options, context);
|
|
3152
|
-
pos = child.to;
|
|
3165
|
+
const atomEnd = walkAtomChild(node.children, index, baseForChild, text, marks, out, options, context);
|
|
3166
|
+
if (atomEnd != null) {
|
|
3167
|
+
pos = atomEnd;
|
|
3153
3168
|
continue;
|
|
3154
3169
|
}
|
|
3155
3170
|
if (isReference && child.type === LEZER_NODE_IDS.LinkLabel) {
|
|
@@ -3170,19 +3185,33 @@ function walkResolvedLink(node, parts, resolution, parentMarks, text, marks, out
|
|
|
3170
3185
|
}
|
|
3171
3186
|
if (pos < node.to) emit(out, pos, node.to, base);
|
|
3172
3187
|
}
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3188
|
+
/**
|
|
3189
|
+
* The run of magic comments chained immediately behind `nodes[index]` (an
|
|
3190
|
+
* image), or undefined when no magic comment directly abuts it. The first
|
|
3191
|
+
* comment's data wins: a rewrite of an unfolded image inserted the fresh
|
|
3192
|
+
* comment right at the image's end, so in a stacked run left is newest.
|
|
3193
|
+
*/
|
|
3194
|
+
function takeMagicComments(nodes, index, text) {
|
|
3195
|
+
let magic;
|
|
3196
|
+
let to = nodes[index].to;
|
|
3197
|
+
for (let i = index + 1; i < nodes.length; i++) {
|
|
3198
|
+
const next = nodes[i];
|
|
3199
|
+
if (next.type !== LEZER_NODE_IDS.Comment || next.from !== to) break;
|
|
3200
|
+
const parsed = parseMagicComment(text.slice(next.from, next.to));
|
|
3201
|
+
if (!parsed) break;
|
|
3202
|
+
magic ??= parsed;
|
|
3203
|
+
to = next.to;
|
|
3204
|
+
}
|
|
3176
3205
|
if (!magic) return void 0;
|
|
3177
3206
|
return {
|
|
3178
3207
|
magic,
|
|
3179
|
-
to
|
|
3208
|
+
to
|
|
3180
3209
|
};
|
|
3181
3210
|
}
|
|
3182
3211
|
/**
|
|
3183
3212
|
* Special walker for a direct image ``.
|
|
3184
3213
|
*
|
|
3185
|
-
* A `trailing` magic
|
|
3214
|
+
* A `trailing` run of magic comments immediately after the image (e.g.
|
|
3186
3215
|
* `<!-- {"width":320} -->`) is folded into the mark range so it round-trips as
|
|
3187
3216
|
* source while supplying the image's `width`.
|
|
3188
3217
|
*/
|
|
@@ -5543,6 +5572,33 @@ function defineSelectDocBoundary() {
|
|
|
5543
5572
|
});
|
|
5544
5573
|
}
|
|
5545
5574
|
|
|
5575
|
+
//#endregion
|
|
5576
|
+
//#region src/extensions/system-substitution-guard.ts
|
|
5577
|
+
const EM_DASH = "—";
|
|
5578
|
+
/**
|
|
5579
|
+
* Block the macOS "smart dashes" rewrite. With the `spellcheck` attribute on,
|
|
5580
|
+
* WebKit rewrites already-typed `--` near the caret into an em dash and
|
|
5581
|
+
* delivers the rewrite as a cancelable `beforeinput` with
|
|
5582
|
+
* `inputType: 'insertReplacementText'`. That corrupts Markdown such as the
|
|
5583
|
+
* `-->` closing an image sizing comment, so cancel any replacement that
|
|
5584
|
+
* inserts an em dash; word-level autocorrect passes through.
|
|
5585
|
+
*/
|
|
5586
|
+
function defineSystemSubstitutionGuard() {
|
|
5587
|
+
const plugin = new Plugin({ props: { handleDOMEvents: { beforeinput: (view, event) => {
|
|
5588
|
+
if (event.inputType !== "insertReplacementText") return false;
|
|
5589
|
+
if (!(event.dataTransfer?.getData("text/plain") || event.data || "").includes(EM_DASH)) return false;
|
|
5590
|
+
event.preventDefault();
|
|
5591
|
+
const { doc, selection } = view.state;
|
|
5592
|
+
requestAnimationFrame(() => {
|
|
5593
|
+
const { state } = view;
|
|
5594
|
+
if (view.isDestroyed || state.doc !== doc || state.selection.eq(selection)) return;
|
|
5595
|
+
view.dispatch(state.tr.setSelection(selection));
|
|
5596
|
+
});
|
|
5597
|
+
return true;
|
|
5598
|
+
} } } });
|
|
5599
|
+
return withPriority$1(definePlugin(plugin), Priority$1.highest);
|
|
5600
|
+
}
|
|
5601
|
+
|
|
5546
5602
|
//#endregion
|
|
5547
5603
|
//#region src/extensions/view-attributes.ts
|
|
5548
5604
|
/**
|
|
@@ -5557,7 +5613,7 @@ function defineViewAttributes(attributes) {
|
|
|
5557
5613
|
//#endregion
|
|
5558
5614
|
//#region src/extensions/extension.ts
|
|
5559
5615
|
function defineEditorExtensionImpl(options) {
|
|
5560
|
-
return union(defineMeowdownParagraph(), defineDoc(), defineDocFrontmatterAttr(), defineText(), defineBlockquote(), defineMeowdownList(), defineHeading(), defineTable(), defineCodeBlock$1(), defineMeowdownHorizontalRule(), defineHTMLComment(), defineInlineMarks(), defineViewAttributes({ class: "meowdown-content" }), defineCodeBlockSyntaxHighlight(), defineCrossEditorDrag(), defineEscapeCollapse(), defineMoveBlock(), defineSelectDocBoundary(), defineInlineMarkPlugin(options), defineInlineToggle(), defineLinkCommands(), defineWikilink(), defineMath(), defineMarkMode(options.markMode ?? "focus"), defineClipboard(), defineScrollToSelection(), defineHiddenRunCaret(), defineAtomMarkNavigation({ marks: ATOM_SOURCE_MARK_NAMES.map((name) => ({
|
|
5616
|
+
return union(defineMeowdownParagraph(), defineDoc(), defineDocFrontmatterAttr(), defineText(), defineBlockquote(), defineMeowdownList(), defineHeading(), defineTable(), defineCodeBlock$1(), defineMeowdownHorizontalRule(), defineHTMLComment(), defineInlineMarks(), defineViewAttributes({ class: "meowdown-content" }), defineCodeBlockSyntaxHighlight(), defineCrossEditorDrag(), defineEscapeCollapse(), defineMoveBlock(), defineSelectDocBoundary(), defineInlineMarkPlugin(options), defineInlineToggle(), defineLinkCommands(), defineWikilink(), defineMath(), defineMarkMode(options.markMode ?? "focus"), defineClipboard(), defineScrollToSelection(), defineHiddenRunCaret(), defineSystemSubstitutionGuard(), defineAtomMarkNavigation({ marks: ATOM_SOURCE_MARK_NAMES.map((name) => ({
|
|
5561
5617
|
name,
|
|
5562
5618
|
modes: [
|
|
5563
5619
|
"hide",
|
|
@@ -7632,6 +7688,9 @@ function createSpellCheckPlugin(spellCheck) {
|
|
|
7632
7688
|
}
|
|
7633
7689
|
});
|
|
7634
7690
|
}
|
|
7691
|
+
/**
|
|
7692
|
+
* @deprecated This will be removed in future versions.
|
|
7693
|
+
*/
|
|
7635
7694
|
function defineSpellCheckPlugin(spellCheck) {
|
|
7636
7695
|
return definePlugin(createSpellCheckPlugin(spellCheck));
|
|
7637
7696
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meowdown/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.65.
|
|
4
|
+
"version": "0.65.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -26,24 +26,24 @@
|
|
|
26
26
|
"@floating-ui/dom": "^1.8.0",
|
|
27
27
|
"@lezer/highlight": "^1.2.3",
|
|
28
28
|
"@ocavue/utils": "^1.7.0",
|
|
29
|
-
"@prosekit/core": "^0.13.0
|
|
30
|
-
"@prosekit/extensions": "^0.18.0
|
|
31
|
-
"@prosekit/pm": "^0.1.19
|
|
32
|
-
"@prosekit/web": "^0.9.0
|
|
29
|
+
"@prosekit/core": "^0.13.0",
|
|
30
|
+
"@prosekit/extensions": "^0.18.0",
|
|
31
|
+
"@prosekit/pm": "^0.1.19",
|
|
32
|
+
"@prosekit/web": "^0.9.0",
|
|
33
33
|
"hast-util-to-mdast": "^10.1.2",
|
|
34
34
|
"katex": "^0.18.1",
|
|
35
35
|
"mdast-util-to-markdown": "^2.1.2",
|
|
36
36
|
"micromark-util-decode-string": "^2.0.1",
|
|
37
37
|
"micromark-util-normalize-identifier": "^2.0.1",
|
|
38
38
|
"prosemirror-flat-list": "^0.7.1",
|
|
39
|
-
"prosemirror-highlight": "^0.
|
|
39
|
+
"prosemirror-highlight": "^0.16.0",
|
|
40
40
|
"rehype-parse": "^9.0.1",
|
|
41
41
|
"rehype-remark": "^10.0.1",
|
|
42
42
|
"remark-gfm": "^4.0.1",
|
|
43
43
|
"remark-stringify": "^11.0.0",
|
|
44
44
|
"unicode-by-name": "^0.2.0",
|
|
45
45
|
"unified": "^11.0.5",
|
|
46
|
-
"@meowdown/markdown": "^0.65.
|
|
46
|
+
"@meowdown/markdown": "^0.65.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@ocavue/tsconfig": "^0.7.1",
|