@milkdown/preset-commonmark 7.3.0 → 7.3.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/lib/__internal__/serialize-text.d.ts +1 -1
- package/lib/__internal__/serialize-text.d.ts.map +1 -1
- package/lib/__internal__/with-meta.d.ts +1 -1
- package/lib/__internal__/with-meta.d.ts.map +1 -1
- package/lib/composed/plugins.d.ts.map +1 -1
- package/lib/composed/schema.d.ts.map +1 -1
- package/lib/index.es.js +106 -63
- package/lib/index.es.js.map +1 -1
- package/lib/mark/link.d.ts +2 -2
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts +3 -1
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/hr.d.ts.map +1 -1
- package/lib/node/image.d.ts +2 -2
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/context.d.ts +1 -1
- package/lib/plugin/inline-sync-plugin/context.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/regexp.d.ts +1 -1
- package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/replacer.d.ts +1 -1
- package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/utils.d.ts +6 -6
- package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/__internal__/serialize-text.ts +1 -1
- package/src/__internal__/with-meta.ts +1 -4
- package/src/composed/plugins.ts +2 -1
- package/src/composed/schema.ts +2 -1
- package/src/mark/link.ts +1 -1
- package/src/node/code-block.ts +1 -1
- package/src/node/hardbreak.ts +5 -2
- package/src/node/heading.ts +3 -2
- package/src/node/hr.ts +2 -1
- package/src/node/image.ts +1 -1
- package/src/node/list-item.ts +24 -22
- package/src/plugin/hardbreak-clear-mark-plugin.ts +1 -1
- package/src/plugin/inline-sync-plugin/config.ts +5 -5
- package/src/plugin/inline-sync-plugin/context.ts +7 -7
- package/src/plugin/inline-sync-plugin/regexp.ts +3 -2
- package/src/plugin/inline-sync-plugin/replacer.ts +1 -7
- package/src/plugin/inline-sync-plugin/utils.ts +24 -20
- package/src/plugin/remark-html-transformer.ts +1 -1
package/lib/mark/link.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const linkAttr: import("@milkdown/utils").$MarkAttr;
|
|
2
2
|
export declare const linkSchema: import("@milkdown/utils").$MarkSchema<"link">;
|
|
3
|
-
export
|
|
3
|
+
export interface UpdateLinkCommandPayload {
|
|
4
4
|
href?: string;
|
|
5
5
|
title?: string;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
export declare const toggleLinkCommand: import("@milkdown/utils").$Command<UpdateLinkCommandPayload>;
|
|
8
8
|
export declare const updateLinkCommand: import("@milkdown/utils").$Command<UpdateLinkCommandPayload>;
|
|
9
9
|
//# sourceMappingURL=link.d.ts.map
|
package/lib/mark/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ,qCAAoB,CAAA;AAQzC,eAAO,MAAM,UAAU,+CAoCpB,CAAA;AAQH,MAAM,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ,qCAAoB,CAAA;AAQzC,eAAO,MAAM,UAAU,+CAoCpB,CAAA;AAQH,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAGD,eAAO,MAAM,iBAAiB,8DAAuH,CAAA;AASrJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hardbreak.d.ts","sourceRoot":"","sources":["../../src/node/hardbreak.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,aAAa,qCAIxB,CAAA;AAQF,eAAO,MAAM,eAAe,oDA4BzB,CAAA;AAaH,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"hardbreak.d.ts","sourceRoot":"","sources":["../../src/node/hardbreak.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,aAAa,qCAIxB,CAAA;AAQF,eAAO,MAAM,eAAe,oDA4BzB,CAAA;AAaH,eAAO,MAAM,sBAAsB,6CAoBjC,CAAA;AASF,eAAO,MAAM,eAAe,6EAQ1B,CAAA"}
|
package/lib/node/heading.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Node } from '@milkdown/prose/model';
|
|
2
|
-
|
|
2
|
+
declare function defaultHeadingIdGenerator(node: Node): string;
|
|
3
|
+
export declare const headingIdGenerator: import("@milkdown/utils").$Ctx<typeof defaultHeadingIdGenerator, "headingIdGenerator">;
|
|
3
4
|
export declare const headingAttr: import("@milkdown/utils").$NodeAttr;
|
|
4
5
|
export declare const headingSchema: import("@milkdown/utils").$NodeSchema<"heading">;
|
|
5
6
|
export declare const wrapInHeadingInputRule: import("@milkdown/utils").$InputRule;
|
|
6
7
|
export declare const wrapInHeadingCommand: import("@milkdown/utils").$Command<number>;
|
|
7
8
|
export declare const downgradeHeadingCommand: import("@milkdown/utils").$Command<unknown>;
|
|
8
9
|
export declare const headingKeymap: import("@milkdown/utils").$UserKeymap<"headingKeymap", "DowngradeHeading" | "TurnIntoH1" | "TurnIntoH2" | "TurnIntoH3" | "TurnIntoH4" | "TurnIntoH5" | "TurnIntoH6">;
|
|
10
|
+
export {};
|
|
9
11
|
//# sourceMappingURL=heading.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAUjD,iBAAS,yBAAyB,CAAC,IAAI,EAAE,IAAI,UAE5C;AAID,eAAO,MAAM,kBAAkB,wFAAwD,CAAA;AAQvF,eAAO,MAAM,WAAW,qCAAuB,CAAA;AAQ/C,eAAO,MAAM,aAAa,kDAmDxB,CAAA;AAcF,eAAO,MAAM,sBAAsB,sCAgBjC,CAAA;AAUF,eAAO,MAAM,oBAAoB,4CAS/B,CAAA;AAUF,eAAO,MAAM,uBAAuB,6CAkBhC,CAAA;AAUJ,eAAO,MAAM,aAAa,sKAkDxB,CAAA"}
|
package/lib/node/hr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,qCAAkB,CAAA;AAQrC,eAAO,MAAM,QAAQ,6CAgBlB,CAAA;AAcH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,qCAAkB,CAAA;AAQrC,eAAO,MAAM,QAAQ,6CAgBlB,CAAA;AAcH,eAAO,MAAM,iBAAiB,sCAU5B,CAAA;AAQF,eAAO,MAAM,eAAe,6CAkB1B,CAAA"}
|
package/lib/node/image.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const imageAttr: import("@milkdown/utils").$NodeAttr;
|
|
2
2
|
export declare const imageSchema: import("@milkdown/utils").$NodeSchema<"image">;
|
|
3
|
-
export
|
|
3
|
+
export interface UpdateImageCommandPayload {
|
|
4
4
|
src?: string;
|
|
5
5
|
title?: string;
|
|
6
6
|
alt?: string;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
8
|
export declare const insertImageCommand: import("@milkdown/utils").$Command<UpdateImageCommandPayload>;
|
|
9
9
|
export declare const updateImageCommand: import("@milkdown/utils").$Command<UpdateImageCommandPayload>;
|
|
10
10
|
export declare const insertImageInputRule: import("@milkdown/utils").$InputRule;
|
package/lib/node/image.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,qCAAqB,CAAA;AAQ3C,eAAO,MAAM,WAAW,gDAyDtB,CAAA;AAaF,MAAM,
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,qCAAqB,CAAA;AAQ3C,eAAO,MAAM,WAAW,gDAyDtB,CAAA;AAaF,MAAM,WAAW,yBAAyB;IACxC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAID,eAAO,MAAM,kBAAkB,+DAa3B,CAAA;AASJ,eAAO,MAAM,kBAAkB,+DAkB7B,CAAA;AAUF,eAAO,MAAM,oBAAoB,sCAS/B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAAgF,CAAA;AAmBhH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AAoBjH,eAAO,MAAM,oBAAoB,6CAAkF,CAAA;
|
|
1
|
+
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAAgF,CAAA;AAmBhH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AAoBjH,eAAO,MAAM,oBAAoB,6CAAkF,CAAA;AAuCnH,eAAO,MAAM,wBAAwB,6CAAqE,CAAA;AAW1G,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
|
|
@@ -7,5 +7,5 @@ export interface InlineSyncContext {
|
|
|
7
7
|
nextNode: Node;
|
|
8
8
|
placeholder: string;
|
|
9
9
|
}
|
|
10
|
-
export declare
|
|
10
|
+
export declare function getContextByState(ctx: Ctx, state: EditorState): InlineSyncContext | null;
|
|
11
11
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAiED,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAiED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,GAAG,iBAAiB,GAAG,IAAI,CAuCxF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const linkRegexp: RegExp;
|
|
2
2
|
export declare const keepLinkRegexp: RegExp;
|
|
3
|
-
export declare
|
|
3
|
+
export declare function punctuationRegexp(holePlaceholder: string): RegExp;
|
|
4
4
|
export declare const ZERO_WIDTH_SPACE = "\u200B";
|
|
5
5
|
export declare const asterisk: string;
|
|
6
6
|
export declare const asteriskHolder: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,
|
|
1
|
+
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,UAExD;AAED,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,eAAO,MAAM,QAAQ,QAAyB,CAAA;AAC9C,eAAO,MAAM,cAAc,QAAyB,CAAA;AACpD,eAAO,MAAM,SAAS,QAAyB,CAAA;AAC/C,eAAO,MAAM,eAAe,QAAyB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ctx } from '@milkdown/ctx';
|
|
2
2
|
import type { Attrs } from '@milkdown/prose/model';
|
|
3
3
|
import type { EditorState, PluginKey, Transaction } from '@milkdown/prose/state';
|
|
4
|
-
export declare
|
|
4
|
+
export declare function runReplacer(ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs): void;
|
|
5
5
|
//# sourceMappingURL=replacer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAQhF,
|
|
1
|
+
{"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAQhF,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,EAAE,KAAK,EAAE,KAAK,QAsC1H"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Node } from '@milkdown/prose/model';
|
|
2
2
|
import type { SyncNodePlaceholder } from './config';
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
3
|
+
export declare function keepLink(str: string): string;
|
|
4
|
+
export declare function mergeSlash(str: string): string;
|
|
5
|
+
export declare function swap(text: string, first: number, last: number): string;
|
|
6
|
+
export declare function replacePunctuation(holePlaceholder: string): (text: string) => string;
|
|
7
|
+
export declare function calculatePlaceholder(placeholder: SyncNodePlaceholder): (text: string) => string;
|
|
8
|
+
export declare function calcOffset(node: Node, from: number, placeholder: string): number;
|
|
9
9
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAUnD,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAUnD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAUnC;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,UAMrC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAQ7D;AAED,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,UAC1C,MAAM,YAErB;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,mBAAmB,UACrD,MAAM,YAmBrB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAwBvE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.3.
|
|
4
|
+
"version": "7.3.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,23 +29,23 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@sindresorhus/slugify": "^2.2.0",
|
|
32
|
-
"remark-inline-links": "^
|
|
32
|
+
"remark-inline-links": "^7.0.0",
|
|
33
33
|
"tslib": "^2.5.0",
|
|
34
34
|
"unist-util-visit": "^5.0.0",
|
|
35
|
-
"@milkdown/exception": "7.3.
|
|
36
|
-
"@milkdown/utils": "7.3.
|
|
35
|
+
"@milkdown/exception": "7.3.2",
|
|
36
|
+
"@milkdown/utils": "7.3.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@milkdown/core": "7.3.
|
|
40
|
-
"@milkdown/ctx": "7.3.
|
|
41
|
-
"@milkdown/prose": "7.3.
|
|
42
|
-
"@milkdown/transformer": "7.3.
|
|
39
|
+
"@milkdown/core": "7.3.2",
|
|
40
|
+
"@milkdown/ctx": "7.3.2",
|
|
41
|
+
"@milkdown/prose": "7.3.2",
|
|
42
|
+
"@milkdown/transformer": "7.3.2"
|
|
43
43
|
},
|
|
44
44
|
"nx": {
|
|
45
45
|
"targets": {
|
|
46
46
|
"build": {
|
|
47
47
|
"outputs": [
|
|
48
|
-
"
|
|
48
|
+
"{projectRoot}/lib"
|
|
49
49
|
],
|
|
50
50
|
"dependsOn": [
|
|
51
51
|
{
|
|
@@ -3,7 +3,7 @@ import type { SerializerState } from '@milkdown/transformer'
|
|
|
3
3
|
import type { Node } from '@milkdown/prose/model'
|
|
4
4
|
import { Fragment } from '@milkdown/prose/model'
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export function serializeText(state: SerializerState, node: Node) {
|
|
7
7
|
const lastIsHardBreak
|
|
8
8
|
= node.childCount >= 1 && node.lastChild?.type.name === 'hardbreak'
|
|
9
9
|
if (!lastIsHardBreak) {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import type { Meta, MilkdownPlugin } from '@milkdown/ctx'
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
plugin: T,
|
|
6
|
-
meta: Partial<Meta> & Pick<Meta, 'displayName'>,
|
|
7
|
-
): T => {
|
|
4
|
+
export function withMeta<T extends MilkdownPlugin>(plugin: T, meta: Partial<Meta> & Pick<Meta, 'displayName'>): T {
|
|
8
5
|
Object.assign(plugin, {
|
|
9
6
|
meta: {
|
|
10
7
|
package: '@milkdown/preset-commonmark',
|
package/src/composed/plugins.ts
CHANGED
package/src/composed/schema.ts
CHANGED
package/src/mark/link.ts
CHANGED
package/src/node/code-block.ts
CHANGED
|
@@ -107,7 +107,7 @@ withMeta(createCodeBlockCommand, {
|
|
|
107
107
|
})
|
|
108
108
|
|
|
109
109
|
/// A command for updating the code block language of the target position.
|
|
110
|
-
export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number
|
|
110
|
+
export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number, language: string } = { pos: -1, language: '' }) => (state, dispatch) => {
|
|
111
111
|
if (pos >= 0) {
|
|
112
112
|
dispatch?.(state.tr.setNodeAttribute(pos, 'language', language))
|
|
113
113
|
return true
|
package/src/node/hardbreak.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx } from '@milkdown/core'
|
|
3
|
-
import { Selection } from '@milkdown/prose/state'
|
|
3
|
+
import { Selection, TextSelection } from '@milkdown/prose/state'
|
|
4
4
|
import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
|
|
5
5
|
import { withMeta } from '../__internal__'
|
|
6
6
|
|
|
@@ -34,7 +34,7 @@ export const hardbreakSchema = $nodeSchema('hardbreak', ctx => ({
|
|
|
34
34
|
parseMarkdown: {
|
|
35
35
|
match: ({ type }) => type === 'break',
|
|
36
36
|
runner: (state, node, type) => {
|
|
37
|
-
state.addNode(type, { isInline: Boolean(node.data?.isInline) })
|
|
37
|
+
state.addNode(type, { isInline: Boolean((node.data as (undefined | { isInline: boolean }))?.isInline) })
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
leafText: () => '\n',
|
|
@@ -63,6 +63,9 @@ withMeta(hardbreakSchema.ctx, {
|
|
|
63
63
|
/// Command to insert a hardbreak.
|
|
64
64
|
export const insertHardbreakCommand = $command('InsertHardbreak', ctx => () => (state, dispatch) => {
|
|
65
65
|
const { selection, tr } = state
|
|
66
|
+
if (!(selection instanceof TextSelection))
|
|
67
|
+
return false
|
|
68
|
+
|
|
66
69
|
if (selection.empty) {
|
|
67
70
|
// Transform two successive hardbreak into a new line
|
|
68
71
|
const node = selection.$from.node()
|
package/src/node/heading.ts
CHANGED
|
@@ -13,8 +13,9 @@ const headingIndex = Array(6)
|
|
|
13
13
|
.fill(0)
|
|
14
14
|
.map((_, i) => i + 1)
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
slugify(node.textContent)
|
|
16
|
+
function defaultHeadingIdGenerator(node: Node) {
|
|
17
|
+
return slugify(node.textContent)
|
|
18
|
+
}
|
|
18
19
|
|
|
19
20
|
/// This is a slice contains a function to generate heading id.
|
|
20
21
|
/// You can configure it to generate id in your own way.
|
package/src/node/hr.ts
CHANGED
|
@@ -45,7 +45,8 @@ withMeta(hrSchema.ctx, {
|
|
|
45
45
|
/// Input rule to insert a hr.
|
|
46
46
|
/// For example, `---` will be converted to a hr.
|
|
47
47
|
export const insertHrInputRule = $inputRule(ctx => new InputRule(
|
|
48
|
-
/^(?:---|___\s|\*\*\*\s)$/,
|
|
48
|
+
/^(?:---|___\s|\*\*\*\s)$/,
|
|
49
|
+
(state, match, start, end) => {
|
|
49
50
|
const { tr } = state
|
|
50
51
|
|
|
51
52
|
if (match[0])
|
package/src/node/image.ts
CHANGED
package/src/node/list-item.ts
CHANGED
|
@@ -145,28 +145,30 @@ withMeta(splitListItemCommand, {
|
|
|
145
145
|
group: 'ListItem',
|
|
146
146
|
})
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
148
|
+
function liftFirstListItem(ctx: Ctx): Command {
|
|
149
|
+
return (state, dispatch, view) => {
|
|
150
|
+
const { selection } = state
|
|
151
|
+
if (!(selection instanceof TextSelection))
|
|
152
|
+
return false
|
|
153
|
+
|
|
154
|
+
const { empty, $from } = selection
|
|
155
|
+
|
|
156
|
+
// selection should be empty and at the start of the node
|
|
157
|
+
if (!empty || $from.parentOffset !== 0)
|
|
158
|
+
return false
|
|
159
|
+
|
|
160
|
+
const parentItem = $from.node(-1)
|
|
161
|
+
// selection should be in list item and list item should be the first child of the list
|
|
162
|
+
if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
|
|
163
|
+
return false
|
|
164
|
+
|
|
165
|
+
const list = $from.node(-2)
|
|
166
|
+
// list should have only one list item
|
|
167
|
+
if (list.childCount > 1)
|
|
168
|
+
return false
|
|
169
|
+
|
|
170
|
+
return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
|
|
171
|
+
}
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
/// The command to remove list item **only if**:
|
|
@@ -31,7 +31,7 @@ export const hardbreakClearMarkPlugin = $prose((ctx) => {
|
|
|
31
31
|
const isAddMarkStep = step instanceof AddMarkStep
|
|
32
32
|
if (isAddMarkStep) {
|
|
33
33
|
let _tr = newState.tr
|
|
34
|
-
const { from, to } = step as unknown as { from: number
|
|
34
|
+
const { from, to } = step as unknown as { from: number, to: number }
|
|
35
35
|
newState.doc.nodesBetween(from, to, (node, pos) => {
|
|
36
36
|
if (node.type === hardbreakSchema.type(ctx))
|
|
37
37
|
_tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(ctx), undefined, [])
|
|
@@ -41,11 +41,11 @@ export const defaultConfig: InlineSyncConfig = {
|
|
|
41
41
|
globalNodes: ['footnote_definition'],
|
|
42
42
|
shouldSyncNode: ({ prevNode, nextNode }) =>
|
|
43
43
|
prevNode.inlineContent
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
&& nextNode
|
|
45
|
+
// if node type changes, do not sync
|
|
46
|
+
&& prevNode.type === nextNode.type
|
|
47
|
+
// if two node fully equal, we don't modify them
|
|
48
|
+
&& !prevNode.eq(nextNode),
|
|
49
49
|
movePlaceholder: (placeholderToMove: string, text: string) => {
|
|
50
50
|
const symbolsNeedToMove = ['*', '_']
|
|
51
51
|
|
|
@@ -16,18 +16,18 @@ export interface InlineSyncContext {
|
|
|
16
16
|
placeholder: string
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
function getNodeFromSelection(state: EditorState) {
|
|
20
20
|
return state.selection.$from.node()
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
function getMarkdown(ctx: Ctx, state: EditorState, node: Node, globalNode: Node[]) {
|
|
24
24
|
const serializer = ctx.get(serializerCtx)
|
|
25
25
|
const doc = state.schema.topNodeType.create(undefined, [node, ...globalNode])
|
|
26
26
|
|
|
27
27
|
return serializer(doc)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
function addPlaceholder(ctx: Ctx, markdown: string) {
|
|
31
31
|
const config = ctx.get(inlineSyncConfig.key)
|
|
32
32
|
const holePlaceholder = config.placeholderConfig.hole
|
|
33
33
|
|
|
@@ -47,7 +47,7 @@ const addPlaceholder = (ctx: Ctx, markdown: string) => {
|
|
|
47
47
|
return [text, placeholder] as [markdown: string, placeholder: string]
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
function getNewNode(ctx: Ctx, text: string) {
|
|
51
51
|
const parser = ctx.get(parserCtx)
|
|
52
52
|
const parsed = parser(text)
|
|
53
53
|
|
|
@@ -57,7 +57,7 @@ const getNewNode = (ctx: Ctx, text: string) => {
|
|
|
57
57
|
return parsed.firstChild
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
function collectGlobalNodes(ctx: Ctx, state: EditorState) {
|
|
61
61
|
const { globalNodes } = ctx.get(inlineSyncConfig.key)
|
|
62
62
|
const nodes: Node[] = []
|
|
63
63
|
|
|
@@ -75,11 +75,11 @@ const collectGlobalNodes = (ctx: Ctx, state: EditorState) => {
|
|
|
75
75
|
|
|
76
76
|
const removeGlobalFromText = (text: string) => text.split('\n\n')[0] || ''
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
function onlyHTML(node: Node) {
|
|
79
79
|
return node.childCount === 1 && node.child(0).type.name === 'html'
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export
|
|
82
|
+
export function getContextByState(ctx: Ctx, state: EditorState): InlineSyncContext | null {
|
|
83
83
|
try {
|
|
84
84
|
const globalNode = collectGlobalNodes(ctx, state)
|
|
85
85
|
const node = getNodeFromSelection(state)
|
|
@@ -4,8 +4,9 @@ export const linkRegexp = /\[([^\]]+)]\([^\s\]]+\)/
|
|
|
4
4
|
|
|
5
5
|
export const keepLinkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
|
|
7
|
+
export function punctuationRegexp(holePlaceholder: string) {
|
|
8
|
+
return new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
|
|
9
|
+
}
|
|
9
10
|
|
|
10
11
|
export const ZERO_WIDTH_SPACE = '\u200B'
|
|
11
12
|
|
|
@@ -9,13 +9,7 @@ import { getContextByState } from './context'
|
|
|
9
9
|
import { calcOffset } from './utils'
|
|
10
10
|
import { linkRegexp } from './regexp'
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
ctx: Ctx,
|
|
14
|
-
key: PluginKey,
|
|
15
|
-
state: EditorState,
|
|
16
|
-
dispatch: (tr: Transaction) => void,
|
|
17
|
-
attrs: Attrs,
|
|
18
|
-
) => {
|
|
12
|
+
export function runReplacer(ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs) {
|
|
19
13
|
const { placeholderConfig } = ctx.get(inlineSyncConfig.key)
|
|
20
14
|
const holePlaceholder = placeholderConfig.hole
|
|
21
15
|
// insert a placeholder to restore the selection
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
underlineHolder,
|
|
13
13
|
} from './regexp'
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export function keepLink(str: string) {
|
|
16
16
|
let text = str
|
|
17
17
|
let match = text.match(keepLinkRegexp)
|
|
18
18
|
while (match && match.groups) {
|
|
@@ -24,7 +24,7 @@ export const keepLink = (str: string) => {
|
|
|
24
24
|
return text
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export
|
|
27
|
+
export function mergeSlash(str: string) {
|
|
28
28
|
return str
|
|
29
29
|
.replaceAll(/\\\\\*/g, asterisk)
|
|
30
30
|
.replaceAll(/\\\\_/g, underline)
|
|
@@ -32,7 +32,7 @@ export const mergeSlash = (str: string) => {
|
|
|
32
32
|
.replaceAll(underline, underlineHolder)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export
|
|
35
|
+
export function swap(text: string, first: number, last: number) {
|
|
36
36
|
const arr = text.split('')
|
|
37
37
|
const temp = arr[first]
|
|
38
38
|
if (arr[first] && arr[last]) {
|
|
@@ -42,30 +42,34 @@ export const swap = (text: string, first: number, last: number) => {
|
|
|
42
42
|
return arr.join('').toString()
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export
|
|
46
|
-
text
|
|
45
|
+
export function replacePunctuation(holePlaceholder: string) {
|
|
46
|
+
return (text: string) =>
|
|
47
|
+
text.replace(punctuationRegexp(holePlaceholder), '')
|
|
48
|
+
}
|
|
47
49
|
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
export function calculatePlaceholder(placeholder: SyncNodePlaceholder) {
|
|
51
|
+
return (text: string) => {
|
|
52
|
+
const index = text.indexOf(placeholder.hole)
|
|
53
|
+
const left = text.charAt(index - 1)
|
|
54
|
+
const right = text.charAt(index + 1)
|
|
55
|
+
const notAWord = /[^\w]|_/
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
// cursor on the right
|
|
58
|
+
if (!right)
|
|
59
|
+
return placeholder.punctuation
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
// cursor on the left
|
|
62
|
+
if (!left)
|
|
63
|
+
return placeholder.char
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
if (notAWord.test(left) && notAWord.test(right))
|
|
66
|
+
return placeholder.punctuation
|
|
64
67
|
|
|
65
|
-
|
|
68
|
+
return placeholder.char
|
|
69
|
+
}
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
export
|
|
72
|
+
export function calcOffset(node: Node, from: number, placeholder: string) {
|
|
69
73
|
let offset = from
|
|
70
74
|
let find = false
|
|
71
75
|
node.descendants((n) => {
|
|
@@ -4,7 +4,7 @@ import type { Node } from '@milkdown/transformer'
|
|
|
4
4
|
import { withMeta } from '../__internal__'
|
|
5
5
|
|
|
6
6
|
const isParent = (node: Node): node is Node & { children: Node[] } => !!(node as Node & { children: Node[] }).children
|
|
7
|
-
const isHTML = (node: Node): node is Node & { children: Node[]
|
|
7
|
+
const isHTML = (node: Node): node is Node & { children: Node[], value: unknown } => node.type === 'html'
|
|
8
8
|
|
|
9
9
|
function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
|
|
10
10
|
return transform(ast, 0, null)[0]
|