@milkdown/preset-commonmark 7.3.2 → 7.3.4
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/composed/inputrules.d.ts +2 -1
- package/lib/composed/inputrules.d.ts.map +1 -1
- package/lib/composed/plugins.d.ts.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +599 -728
- package/lib/index.es.js.map +1 -1
- package/lib/mark/emphasis.d.ts +2 -0
- package/lib/mark/emphasis.d.ts.map +1 -1
- package/lib/mark/inline-code.d.ts +1 -0
- package/lib/mark/inline-code.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +1 -0
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/plugin/index.d.ts +0 -1
- package/lib/plugin/index.d.ts.map +1 -1
- package/package.json +15 -9
- package/src/composed/inputrules.ts +10 -1
- package/src/composed/plugins.ts +0 -5
- package/src/index.ts +3 -2
- package/src/mark/emphasis.ts +28 -1
- package/src/mark/inline-code.ts +12 -1
- package/src/mark/strong.ts +12 -1
- package/src/plugin/index.ts +0 -2
- package/lib/plugin/inline-sync-plugin/config.d.ts +0 -24
- package/lib/plugin/inline-sync-plugin/config.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/context.d.ts +0 -11
- package/lib/plugin/inline-sync-plugin/context.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/index.d.ts +0 -3
- package/lib/plugin/inline-sync-plugin/index.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts +0 -2
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/regexp.d.ts +0 -9
- package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/replacer.d.ts +0 -5
- package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/utils.d.ts +0 -9
- package/lib/plugin/inline-sync-plugin/utils.d.ts.map +0 -1
- package/src/plugin/inline-sync-plugin/config.ts +0 -78
- package/src/plugin/inline-sync-plugin/context.ts +0 -121
- package/src/plugin/inline-sync-plugin/index.ts +0 -4
- package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +0 -72
- package/src/plugin/inline-sync-plugin/regexp.ts +0 -16
- package/src/plugin/inline-sync-plugin/replacer.ts +0 -50
- package/src/plugin/inline-sync-plugin/utils.ts +0 -96
package/lib/mark/emphasis.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const emphasisAttr: import("@milkdown/utils").$MarkAttr;
|
|
2
2
|
export declare const emphasisSchema: import("@milkdown/utils").$MarkSchema<"emphasis">;
|
|
3
3
|
export declare const toggleEmphasisCommand: import("@milkdown/utils").$Command<unknown>;
|
|
4
|
+
export declare const emphasisStarInputRule: import("@milkdown/utils").$InputRule;
|
|
5
|
+
export declare const emphasisUnderscoreInputRule: import("@milkdown/utils").$InputRule;
|
|
4
6
|
export declare const emphasisKeymap: import("@milkdown/utils").$UserKeymap<"emphasisKeymap", "ToggleEmphasis">;
|
|
5
7
|
//# sourceMappingURL=emphasis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,mDA4BxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,6CAEhC,CAAA;AAQF,eAAO,MAAM,qBAAqB,sCAKhC,CAAA;AAQF,eAAO,MAAM,2BAA2B,sCAKtC,CAAA;AASF,eAAO,MAAM,cAAc,2EAQzB,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const inlineCodeAttr: import("@milkdown/utils").$MarkAttr;
|
|
2
2
|
export declare const inlineCodeSchema: import("@milkdown/utils").$MarkSchema<"inlineCode">;
|
|
3
3
|
export declare const toggleInlineCodeCommand: import("@milkdown/utils").$Command<unknown>;
|
|
4
|
+
export declare const inlineCodeInputRule: import("@milkdown/utils").$InputRule;
|
|
4
5
|
export declare const inlineCodeKeymap: import("@milkdown/utils").$UserKeymap<"inlineCodeKeymap", "ToggleInlineCode">;
|
|
5
6
|
//# sourceMappingURL=inline-code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-code.d.ts","sourceRoot":"","sources":["../../src/mark/inline-code.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inline-code.d.ts","sourceRoot":"","sources":["../../src/mark/inline-code.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,qDAoB1B,CAAA;AAaH,eAAO,MAAM,uBAAuB,6CAyBlC,CAAA;AAQF,eAAO,MAAM,mBAAmB,sCAE9B,CAAA;AASF,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
|
package/lib/mark/strong.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const strongAttr: import("@milkdown/utils").$MarkAttr;
|
|
2
2
|
export declare const strongSchema: import("@milkdown/utils").$MarkSchema<"strong">;
|
|
3
3
|
export declare const toggleStrongCommand: import("@milkdown/utils").$Command<unknown>;
|
|
4
|
+
export declare const strongInputRule: import("@milkdown/utils").$InputRule;
|
|
4
5
|
export declare const strongKeymap: import("@milkdown/utils").$UserKeymap<"strongKeymap", "ToggleBold">;
|
|
5
6
|
//# sourceMappingURL=strong.d.ts.map
|
package/lib/mark/strong.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,UAAU,qCAAsB,CAAA;AAQ7C,eAAO,MAAM,YAAY,iDA4BtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,6CAE9B,CAAA;AAQF,eAAO,MAAM,eAAe,sCAE1B,CAAA;AASF,eAAO,MAAM,YAAY,qEAQvB,CAAA"}
|
package/lib/plugin/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AAEtC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AAEzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA"}
|
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.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -15,8 +15,13 @@
|
|
|
15
15
|
"commonmark"
|
|
16
16
|
],
|
|
17
17
|
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./lib/index.es.js",
|
|
21
|
+
"types": "./lib/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
18
24
|
"main": "./lib/index.es.js",
|
|
19
|
-
"types": "./lib/index.d.ts",
|
|
20
25
|
"files": [
|
|
21
26
|
"lib",
|
|
22
27
|
"src"
|
|
@@ -32,14 +37,14 @@
|
|
|
32
37
|
"remark-inline-links": "^7.0.0",
|
|
33
38
|
"tslib": "^2.5.0",
|
|
34
39
|
"unist-util-visit": "^5.0.0",
|
|
35
|
-
"@milkdown/exception": "7.3.
|
|
36
|
-
"@milkdown/utils": "7.3.
|
|
40
|
+
"@milkdown/exception": "7.3.4",
|
|
41
|
+
"@milkdown/utils": "7.3.4"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {
|
|
39
|
-
"@milkdown/core": "7.3.
|
|
40
|
-
"@milkdown/ctx": "7.3.
|
|
41
|
-
"@milkdown/prose": "7.3.
|
|
42
|
-
"@milkdown/transformer": "7.3.
|
|
44
|
+
"@milkdown/core": "7.3.4",
|
|
45
|
+
"@milkdown/ctx": "7.3.4",
|
|
46
|
+
"@milkdown/prose": "7.3.4",
|
|
47
|
+
"@milkdown/transformer": "7.3.4"
|
|
43
48
|
},
|
|
44
49
|
"nx": {
|
|
45
50
|
"targets": {
|
|
@@ -70,5 +75,6 @@
|
|
|
70
75
|
"test": "vitest",
|
|
71
76
|
"tsc": "tsc --noEmit && echo",
|
|
72
77
|
"build": "tsc --emitDeclarationOnly && vite build"
|
|
73
|
-
}
|
|
78
|
+
},
|
|
79
|
+
"types": "./lib/index.d.ts"
|
|
74
80
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import type { MilkdownPlugin } from '@milkdown/ctx'
|
|
3
3
|
import { createCodeBlockInputRule, insertHrInputRule, wrapInBlockquoteInputRule, wrapInBulletListInputRule, wrapInHeadingInputRule, wrapInOrderedListInputRule } from '../node'
|
|
4
|
+
import { emphasisStarInputRule, emphasisUnderscoreInputRule, inlineCodeInputRule, strongInputRule } from '../mark'
|
|
4
5
|
|
|
5
6
|
/// @internal
|
|
6
|
-
export const
|
|
7
|
+
export const inputRules: MilkdownPlugin[] = [
|
|
7
8
|
wrapInBlockquoteInputRule,
|
|
8
9
|
wrapInBulletListInputRule,
|
|
9
10
|
wrapInOrderedListInputRule,
|
|
@@ -11,3 +12,11 @@ export const inputrules: MilkdownPlugin[] = [
|
|
|
11
12
|
insertHrInputRule,
|
|
12
13
|
wrapInHeadingInputRule,
|
|
13
14
|
].flat()
|
|
15
|
+
|
|
16
|
+
/// @internal
|
|
17
|
+
export const markInputRules: MilkdownPlugin[] = [
|
|
18
|
+
emphasisStarInputRule,
|
|
19
|
+
emphasisUnderscoreInputRule,
|
|
20
|
+
inlineCodeInputRule,
|
|
21
|
+
strongInputRule,
|
|
22
|
+
]
|
package/src/composed/plugins.ts
CHANGED
|
@@ -6,8 +6,6 @@ import {
|
|
|
6
6
|
hardbreakFilterNodes,
|
|
7
7
|
hardbreakFilterPlugin,
|
|
8
8
|
inlineNodesCursorPlugin,
|
|
9
|
-
inlineSyncConfig,
|
|
10
|
-
inlineSyncPlugin,
|
|
11
9
|
remarkAddOrderInListPlugin,
|
|
12
10
|
remarkHtmlTransformer,
|
|
13
11
|
remarkInlineLinkPlugin,
|
|
@@ -19,9 +17,6 @@ import {
|
|
|
19
17
|
|
|
20
18
|
/// @internal
|
|
21
19
|
export const plugins: MilkdownPlugin[] = [
|
|
22
|
-
inlineSyncConfig,
|
|
23
|
-
inlineSyncPlugin,
|
|
24
|
-
|
|
25
20
|
hardbreakClearMarkPlugin,
|
|
26
21
|
hardbreakFilterNodes,
|
|
27
22
|
hardbreakFilterPlugin,
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { MilkdownPlugin } from '@milkdown/ctx'
|
|
4
|
+
import { commands, inputRules, keymap, markInputRules, plugins, schema } from './composed'
|
|
4
5
|
|
|
5
6
|
export * from './node'
|
|
6
7
|
export * from './mark'
|
|
@@ -8,4 +9,4 @@ export * from './plugin'
|
|
|
8
9
|
export * from './composed'
|
|
9
10
|
|
|
10
11
|
/// The commonmark preset, includes all the plugins.
|
|
11
|
-
export const commonmark = [schema,
|
|
12
|
+
export const commonmark: MilkdownPlugin[] = [schema, inputRules, markInputRules, commands, keymap, plugins].flat()
|
package/src/mark/emphasis.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
|
|
3
|
-
import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
3
|
+
import { $command, $inputRule, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
4
4
|
import { toggleMark } from '@milkdown/prose/commands'
|
|
5
|
+
import { markRule } from '@milkdown/prose'
|
|
5
6
|
import { withMeta } from '../__internal__'
|
|
6
7
|
|
|
7
8
|
/// HTML attributes for the emphasis mark.
|
|
@@ -63,6 +64,32 @@ withMeta(toggleEmphasisCommand, {
|
|
|
63
64
|
group: 'Emphasis',
|
|
64
65
|
})
|
|
65
66
|
|
|
67
|
+
/// Input rule for use `*` to create emphasis mark.
|
|
68
|
+
export const emphasisStarInputRule = $inputRule((ctx) => {
|
|
69
|
+
return markRule(/(?:^|[^*])\*([^*]+)\*$/, emphasisSchema.type(ctx), {
|
|
70
|
+
updateCaptured: ({ fullMatch, start }) =>
|
|
71
|
+
!fullMatch.startsWith('*') ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {},
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
withMeta(emphasisStarInputRule, {
|
|
76
|
+
displayName: 'InputRule<emphasis>|Star',
|
|
77
|
+
group: 'Emphasis',
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
/// Input rule for use `_` to create emphasis mark.
|
|
81
|
+
export const emphasisUnderscoreInputRule = $inputRule((ctx) => {
|
|
82
|
+
return markRule(/(?:^|[^_])_([^_]+)_$/, emphasisSchema.type(ctx), {
|
|
83
|
+
updateCaptured: ({ fullMatch, start }) =>
|
|
84
|
+
!fullMatch.startsWith('_') ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {},
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
withMeta(emphasisUnderscoreInputRule, {
|
|
89
|
+
displayName: 'InputRule<emphasis>|Underscore',
|
|
90
|
+
group: 'Emphasis',
|
|
91
|
+
})
|
|
92
|
+
|
|
66
93
|
/// Keymap for the emphasis mark.
|
|
67
94
|
/// - `Mod-i` - Toggle the emphasis mark.
|
|
68
95
|
export const emphasisKeymap = $useKeymap('emphasisKeymap', {
|
package/src/mark/inline-code.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx } from '@milkdown/core'
|
|
3
3
|
import type { MarkType } from '@milkdown/prose/model'
|
|
4
|
-
import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
4
|
+
import { $command, $inputRule, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
5
|
+
import { markRule } from '@milkdown/prose'
|
|
5
6
|
import { withMeta } from '../__internal__'
|
|
6
7
|
|
|
7
8
|
/// HTML attributes for the inlineCode mark.
|
|
@@ -78,6 +79,16 @@ withMeta(toggleInlineCodeCommand, {
|
|
|
78
79
|
group: 'InlineCode',
|
|
79
80
|
})
|
|
80
81
|
|
|
82
|
+
/// Input rule for create inlineCode mark.
|
|
83
|
+
export const inlineCodeInputRule = $inputRule((ctx) => {
|
|
84
|
+
return markRule(/(?:\`)([^\`]+)(?:\`)$/, inlineCodeSchema.type(ctx))
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
withMeta(inlineCodeInputRule, {
|
|
88
|
+
displayName: 'InputRule<inlineCodeInputRule>',
|
|
89
|
+
group: 'InlineCode',
|
|
90
|
+
})
|
|
91
|
+
|
|
81
92
|
/// Keymap for the inlineCode mark.
|
|
82
93
|
/// - `Mod-e` - Toggle the inlineCode mark.
|
|
83
94
|
export const inlineCodeKeymap = $useKeymap('inlineCodeKeymap', {
|
package/src/mark/strong.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
|
|
3
|
-
import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
3
|
+
import { $command, $inputRule, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
4
4
|
import { toggleMark } from '@milkdown/prose/commands'
|
|
5
|
+
import { markRule } from '@milkdown/prose'
|
|
5
6
|
import { withMeta } from '../__internal__'
|
|
6
7
|
|
|
7
8
|
/// HTML attributes for the strong mark.
|
|
@@ -63,6 +64,16 @@ withMeta(toggleStrongCommand, {
|
|
|
63
64
|
group: 'Strong',
|
|
64
65
|
})
|
|
65
66
|
|
|
67
|
+
/// A input rule that will capture the strong mark.
|
|
68
|
+
export const strongInputRule = $inputRule((ctx) => {
|
|
69
|
+
return markRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, strongSchema.type(ctx))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
withMeta(strongInputRule, {
|
|
73
|
+
displayName: 'InputRule<strong>',
|
|
74
|
+
group: 'Strong',
|
|
75
|
+
})
|
|
76
|
+
|
|
66
77
|
/// Keymap for the strong mark.
|
|
67
78
|
/// - `Mod-b` - Toggle the strong mark.
|
|
68
79
|
export const strongKeymap = $useKeymap('strongKeymap', {
|
package/src/plugin/index.ts
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/ctx';
|
|
2
|
-
import type { Node, NodeType } from '@milkdown/prose/model';
|
|
3
|
-
import type { Transaction } from '@milkdown/prose/state';
|
|
4
|
-
export type ShouldSyncNode = (context: {
|
|
5
|
-
prevNode: Node;
|
|
6
|
-
nextNode: Node;
|
|
7
|
-
ctx: Ctx;
|
|
8
|
-
tr: Transaction;
|
|
9
|
-
text: string;
|
|
10
|
-
}) => boolean;
|
|
11
|
-
export interface SyncNodePlaceholder {
|
|
12
|
-
hole: string;
|
|
13
|
-
punctuation: string;
|
|
14
|
-
char: string;
|
|
15
|
-
}
|
|
16
|
-
export interface InlineSyncConfig {
|
|
17
|
-
placeholderConfig: SyncNodePlaceholder;
|
|
18
|
-
shouldSyncNode: ShouldSyncNode;
|
|
19
|
-
globalNodes: Array<NodeType | string>;
|
|
20
|
-
movePlaceholder: (placeholderToMove: string, text: string) => string;
|
|
21
|
-
}
|
|
22
|
-
export declare const defaultConfig: InlineSyncConfig;
|
|
23
|
-
export declare const inlineSyncConfig: import("@milkdown/utils").$Ctx<InlineSyncConfig, "inlineSyncConfig">;
|
|
24
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE;IACrC,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,GAAG,EAAE,GAAG,CAAA;IACR,EAAE,EAAE,WAAW,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,KAAK,OAAO,CAAA;AAGb,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb;AAGD,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,mBAAmB,CAAA;IACtC,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAA;IACrC,eAAe,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACrE;AAGD,eAAO,MAAM,aAAa,EAAE,gBAyB3B,CAAA;AAaD,eAAO,MAAM,gBAAgB,sEAAgF,CAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/ctx';
|
|
2
|
-
import type { Node } from '@milkdown/prose/model';
|
|
3
|
-
import type { EditorState } from '@milkdown/prose/state';
|
|
4
|
-
export interface InlineSyncContext {
|
|
5
|
-
text: string;
|
|
6
|
-
prevNode: Node;
|
|
7
|
-
nextNode: Node;
|
|
8
|
-
placeholder: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function getContextByState(ctx: Ctx, state: EditorState): InlineSyncContext | null;
|
|
11
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,sBAAsB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inline-sync-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/inline-sync-plugin.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,kCAkD3B,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const linkRegexp: RegExp;
|
|
2
|
-
export declare const keepLinkRegexp: RegExp;
|
|
3
|
-
export declare function punctuationRegexp(holePlaceholder: string): RegExp;
|
|
4
|
-
export declare const ZERO_WIDTH_SPACE = "\u200B";
|
|
5
|
-
export declare const asterisk: string;
|
|
6
|
-
export declare const asteriskHolder: string;
|
|
7
|
-
export declare const underline: string;
|
|
8
|
-
export declare const underlineHolder: string;
|
|
9
|
-
//# sourceMappingURL=regexp.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/ctx';
|
|
2
|
-
import type { Attrs } from '@milkdown/prose/model';
|
|
3
|
-
import type { EditorState, PluginKey, Transaction } from '@milkdown/prose/state';
|
|
4
|
-
export declare function runReplacer(ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs): void;
|
|
5
|
-
//# sourceMappingURL=replacer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import type { Node } from '@milkdown/prose/model';
|
|
2
|
-
import type { SyncNodePlaceholder } from './config';
|
|
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
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Ctx } from '@milkdown/ctx'
|
|
3
|
-
import type { Node, NodeType } from '@milkdown/prose/model'
|
|
4
|
-
import type { Transaction } from '@milkdown/prose/state'
|
|
5
|
-
import { $ctx } from '@milkdown/utils'
|
|
6
|
-
|
|
7
|
-
import { withMeta } from '../../__internal__'
|
|
8
|
-
import { swap } from './utils'
|
|
9
|
-
|
|
10
|
-
/// @internal
|
|
11
|
-
export type ShouldSyncNode = (context: {
|
|
12
|
-
prevNode: Node
|
|
13
|
-
nextNode: Node
|
|
14
|
-
ctx: Ctx
|
|
15
|
-
tr: Transaction
|
|
16
|
-
text: string
|
|
17
|
-
}) => boolean
|
|
18
|
-
|
|
19
|
-
/// @internal
|
|
20
|
-
export interface SyncNodePlaceholder {
|
|
21
|
-
hole: string
|
|
22
|
-
punctuation: string
|
|
23
|
-
char: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/// @internal
|
|
27
|
-
export interface InlineSyncConfig {
|
|
28
|
-
placeholderConfig: SyncNodePlaceholder
|
|
29
|
-
shouldSyncNode: ShouldSyncNode
|
|
30
|
-
globalNodes: Array<NodeType | string>
|
|
31
|
-
movePlaceholder: (placeholderToMove: string, text: string) => string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/// @internal
|
|
35
|
-
export const defaultConfig: InlineSyncConfig = {
|
|
36
|
-
placeholderConfig: {
|
|
37
|
-
hole: '∅',
|
|
38
|
-
punctuation: '⁂',
|
|
39
|
-
char: '∴',
|
|
40
|
-
},
|
|
41
|
-
globalNodes: ['footnote_definition'],
|
|
42
|
-
shouldSyncNode: ({ prevNode, nextNode }) =>
|
|
43
|
-
prevNode.inlineContent
|
|
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
|
-
movePlaceholder: (placeholderToMove: string, text: string) => {
|
|
50
|
-
const symbolsNeedToMove = ['*', '_']
|
|
51
|
-
|
|
52
|
-
let index = text.indexOf(placeholderToMove)
|
|
53
|
-
while (symbolsNeedToMove.includes(text[index - 1] || '') && symbolsNeedToMove.includes(text[index + 1] || '')) {
|
|
54
|
-
text = swap(text, index, index + 1)
|
|
55
|
-
index = index + 1
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return text
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// A slice that contains the inline sync config.
|
|
63
|
-
/// You can set value to this slice to change the config.
|
|
64
|
-
///
|
|
65
|
-
/// ```typescript
|
|
66
|
-
/// ctx.update(inlineSyncConfigCtx, (prevCfg) => ({
|
|
67
|
-
/// ...prevCfg,
|
|
68
|
-
/// // your config
|
|
69
|
-
/// }));
|
|
70
|
-
/// ```
|
|
71
|
-
///
|
|
72
|
-
/// You can find the default config [here](https://github.com/Milkdown/milkdown/blob/main/packages/preset-commonmark/src/plugin/inline-sync-plugin/config.ts).
|
|
73
|
-
export const inlineSyncConfig = $ctx<InlineSyncConfig, 'inlineSyncConfig'>(defaultConfig, 'inlineSyncConfig')
|
|
74
|
-
|
|
75
|
-
withMeta(inlineSyncConfig, {
|
|
76
|
-
displayName: 'Ctx<inlineSyncConfig>',
|
|
77
|
-
group: 'Prose',
|
|
78
|
-
})
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Ctx } from '@milkdown/ctx'
|
|
3
|
-
import { parserCtx, serializerCtx } from '@milkdown/core'
|
|
4
|
-
import type { Node } from '@milkdown/prose/model'
|
|
5
|
-
import type { EditorState } from '@milkdown/prose/state'
|
|
6
|
-
import { pipe } from '@milkdown/utils'
|
|
7
|
-
|
|
8
|
-
import { inlineSyncConfig } from './config'
|
|
9
|
-
import { calculatePlaceholder, keepLink, mergeSlash, replacePunctuation } from './utils'
|
|
10
|
-
import { asterisk, asteriskHolder, underline, underlineHolder } from './regexp'
|
|
11
|
-
|
|
12
|
-
export interface InlineSyncContext {
|
|
13
|
-
text: string
|
|
14
|
-
prevNode: Node
|
|
15
|
-
nextNode: Node
|
|
16
|
-
placeholder: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getNodeFromSelection(state: EditorState) {
|
|
20
|
-
return state.selection.$from.node()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getMarkdown(ctx: Ctx, state: EditorState, node: Node, globalNode: Node[]) {
|
|
24
|
-
const serializer = ctx.get(serializerCtx)
|
|
25
|
-
const doc = state.schema.topNodeType.create(undefined, [node, ...globalNode])
|
|
26
|
-
|
|
27
|
-
return serializer(doc)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function addPlaceholder(ctx: Ctx, markdown: string) {
|
|
31
|
-
const config = ctx.get(inlineSyncConfig.key)
|
|
32
|
-
const holePlaceholder = config.placeholderConfig.hole
|
|
33
|
-
|
|
34
|
-
const [firstLine = '', ...rest] = markdown.split('\n\n')
|
|
35
|
-
|
|
36
|
-
const movePlaceholder = (text: string) => config.movePlaceholder(holePlaceholder, text)
|
|
37
|
-
|
|
38
|
-
const handleText = pipe(replacePunctuation(holePlaceholder), movePlaceholder, keepLink, mergeSlash)
|
|
39
|
-
|
|
40
|
-
let text = handleText(firstLine)
|
|
41
|
-
const placeholder = calculatePlaceholder(config.placeholderConfig)(text)
|
|
42
|
-
|
|
43
|
-
text = text.replace(holePlaceholder, placeholder)
|
|
44
|
-
|
|
45
|
-
text = [text, ...rest].join('\n\n')
|
|
46
|
-
|
|
47
|
-
return [text, placeholder] as [markdown: string, placeholder: string]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getNewNode(ctx: Ctx, text: string) {
|
|
51
|
-
const parser = ctx.get(parserCtx)
|
|
52
|
-
const parsed = parser(text)
|
|
53
|
-
|
|
54
|
-
if (!parsed)
|
|
55
|
-
return null
|
|
56
|
-
|
|
57
|
-
return parsed.firstChild
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function collectGlobalNodes(ctx: Ctx, state: EditorState) {
|
|
61
|
-
const { globalNodes } = ctx.get(inlineSyncConfig.key)
|
|
62
|
-
const nodes: Node[] = []
|
|
63
|
-
|
|
64
|
-
state.doc.descendants((node) => {
|
|
65
|
-
if (globalNodes.includes(node.type.name) || globalNodes.includes(node.type)) {
|
|
66
|
-
nodes.push(node)
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return undefined
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return nodes
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const removeGlobalFromText = (text: string) => text.split('\n\n')[0] || ''
|
|
77
|
-
|
|
78
|
-
function onlyHTML(node: Node) {
|
|
79
|
-
return node.childCount === 1 && node.child(0).type.name === 'html'
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function getContextByState(ctx: Ctx, state: EditorState): InlineSyncContext | null {
|
|
83
|
-
try {
|
|
84
|
-
const globalNode = collectGlobalNodes(ctx, state)
|
|
85
|
-
const node = getNodeFromSelection(state)
|
|
86
|
-
|
|
87
|
-
const markdown = getMarkdown(ctx, state, node, globalNode)
|
|
88
|
-
const [text, placeholder] = addPlaceholder(ctx, markdown)
|
|
89
|
-
|
|
90
|
-
const newNode = getNewNode(ctx, text)
|
|
91
|
-
|
|
92
|
-
if (!newNode || node.type !== newNode.type || onlyHTML(newNode))
|
|
93
|
-
return null
|
|
94
|
-
|
|
95
|
-
// @ts-expect-error hijack the node attribute
|
|
96
|
-
newNode.attrs = { ...node.attrs }
|
|
97
|
-
|
|
98
|
-
newNode.descendants((node) => {
|
|
99
|
-
const marks = node.marks
|
|
100
|
-
const link = marks.find(mark => mark.type.name === 'link')
|
|
101
|
-
if (link && node.text?.includes(placeholder) && link.attrs.href.includes(placeholder)) {
|
|
102
|
-
// @ts-expect-error hijack the mark attribute
|
|
103
|
-
link.attrs.href = link.attrs.href.replace(placeholder, '')
|
|
104
|
-
}
|
|
105
|
-
if (node.text?.includes(asteriskHolder) || node.text?.includes(underlineHolder)) {
|
|
106
|
-
// @ts-expect-error hijack the attribute
|
|
107
|
-
node.text = node.text.replaceAll(asteriskHolder, asterisk).replaceAll(underlineHolder, underline)
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
text: removeGlobalFromText(text),
|
|
113
|
-
prevNode: node,
|
|
114
|
-
nextNode: newNode,
|
|
115
|
-
placeholder,
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
return null
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Ctx } from '@milkdown/ctx'
|
|
3
|
-
import { editorViewCtx } from '@milkdown/core'
|
|
4
|
-
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
5
|
-
import { $prose } from '@milkdown/utils'
|
|
6
|
-
|
|
7
|
-
import { withMeta } from '../../__internal__'
|
|
8
|
-
import { inlineSyncConfig } from './config'
|
|
9
|
-
import { getContextByState } from './context'
|
|
10
|
-
import { runReplacer } from './replacer'
|
|
11
|
-
|
|
12
|
-
/// This plugin is used to sync the inline mark.
|
|
13
|
-
/// It will create and remove marks automatically according to the user input.
|
|
14
|
-
///
|
|
15
|
-
/// When users type something, the plugin will transform the line (for better performance) to real markdown AST by serializer
|
|
16
|
-
/// and render the AST to dom by parser, thus the input texts can be displayed correctly.
|
|
17
|
-
export const inlineSyncPlugin = $prose((ctx: Ctx) => {
|
|
18
|
-
let requestId: number | null = null
|
|
19
|
-
const inlineSyncPluginKey = new PluginKey('MILKDOWN_INLINE_SYNC')
|
|
20
|
-
|
|
21
|
-
return new Plugin<null>({
|
|
22
|
-
key: inlineSyncPluginKey,
|
|
23
|
-
state: {
|
|
24
|
-
init: () => {
|
|
25
|
-
return null
|
|
26
|
-
},
|
|
27
|
-
apply: (tr, _value, _oldState, newState) => {
|
|
28
|
-
const view = ctx.get(editorViewCtx)
|
|
29
|
-
if (!view.hasFocus?.() || !view.editable)
|
|
30
|
-
return null
|
|
31
|
-
|
|
32
|
-
if (!tr.docChanged)
|
|
33
|
-
return null
|
|
34
|
-
|
|
35
|
-
const meta = tr.getMeta(inlineSyncPluginKey)
|
|
36
|
-
if (meta)
|
|
37
|
-
return null
|
|
38
|
-
|
|
39
|
-
const context = getContextByState(ctx, newState)
|
|
40
|
-
if (!context)
|
|
41
|
-
return null
|
|
42
|
-
|
|
43
|
-
if (requestId) {
|
|
44
|
-
cancelAnimationFrame(requestId)
|
|
45
|
-
requestId = null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { prevNode, nextNode, text } = context
|
|
49
|
-
|
|
50
|
-
const { shouldSyncNode } = ctx.get(inlineSyncConfig.key)
|
|
51
|
-
|
|
52
|
-
if (!shouldSyncNode({ prevNode, nextNode, ctx, tr, text }))
|
|
53
|
-
return null
|
|
54
|
-
|
|
55
|
-
requestId = requestAnimationFrame(() => {
|
|
56
|
-
requestId = null
|
|
57
|
-
|
|
58
|
-
const { dispatch, state } = ctx.get(editorViewCtx)
|
|
59
|
-
|
|
60
|
-
runReplacer(ctx, inlineSyncPluginKey, state, dispatch, prevNode.attrs)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
return null
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
withMeta(inlineSyncPlugin, {
|
|
70
|
-
displayName: 'Prose<inlineSyncPlugin>',
|
|
71
|
-
group: 'Prose',
|
|
72
|
-
})
|