@milkdown/preset-commonmark 7.2.3 → 7.2.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/index.es.js +384 -390
- package/lib/index.es.js.map +1 -1
- package/lib/mark/emphasis.d.ts.map +1 -1
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-block.d.ts.map +1 -1
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/mark/emphasis.ts +2 -4
- package/src/mark/inline-code.ts +4 -4
- package/src/mark/link.ts +5 -5
- package/src/mark/strong.ts +2 -5
- package/src/node/blockquote.ts +2 -2
- package/src/node/bullet-list.ts +2 -2
- package/src/node/code-block.ts +2 -2
- package/src/node/hardbreak.ts +2 -2
- package/src/node/heading.ts +10 -10
- package/src/node/hr.ts +5 -5
- package/src/node/image.ts +6 -6
- package/src/node/list-item.ts +8 -7
- package/src/node/ordered-list.ts +3 -3
- package/src/node/paragraph.ts +1 -1
- package/src/plugin/hardbreak-clear-mark-plugin.ts +4 -4
- package/src/plugin/remark-marker-plugin.ts +2 -2
- package/src/plugin/sync-heading-id-plugin.ts +1 -1
- package/src/plugin/sync-list-order-plugin.ts +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,mDA4BxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,mDA4BxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,6CAEhC,CAAA;AASF,eAAO,MAAM,cAAc,2EAQzB,CAAA"}
|
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,MAAM,wBAAwB,GAAG;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAGD,eAAO,MAAM,iBAAiB,
|
|
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,MAAM,wBAAwB,GAAG;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAGD,eAAO,MAAM,iBAAiB,8DAAuH,CAAA;AASrJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
|
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":"AAOA,eAAO,MAAM,UAAU,qCAAsB,CAAA;AAQ7C,eAAO,MAAM,YAAY,iDA4BtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,qCAAsB,CAAA;AAQ7C,eAAO,MAAM,YAAY,iDA4BtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,6CAE9B,CAAA;AASF,eAAO,MAAM,YAAY,qEAQvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["../../src/node/blockquote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,YAAY,CAkBpD,CAAA;AAcH,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["../../src/node/blockquote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,YAAY,CAkBpD,CAAA;AAcH,eAAO,MAAM,yBAAyB,sCAA+E,CAAA;AAQrH,eAAO,MAAM,uBAAuB,6CAAgF,CAAA;AASpH,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,sDAiD3B,CAAA;AAaF,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,sDAiD3B,CAAA;AAaF,eAAO,MAAM,yBAAyB,sCAAqF,CAAA;AAQ3H,eAAO,MAAM,uBAAuB,6CAAgF,CAAA;AASpH,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/node/code-block.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,qCAGvB,CAAA;AAQH,eAAO,MAAM,eAAe,qDAwD1B,CAAA;AAcF,eAAO,MAAM,wBAAwB,sCAEjC,CAAA;AASJ,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/node/code-block.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,qCAGvB,CAAA;AAQH,eAAO,MAAM,eAAe,qDAwD1B,CAAA;AAcF,eAAO,MAAM,wBAAwB,sCAEjC,CAAA;AASJ,eAAO,MAAM,sBAAsB,6CAA+G,CAAA;AAQlJ,eAAO,MAAM,8BAA8B;SAAwE,MAAM;cAAY,MAAM;EAOzI,CAAA;AASF,eAAO,MAAM,eAAe,6EAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"
|
|
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;AAqCnH,eAAO,MAAM,wBAAwB,6CAAqE,CAAA;AAW1G,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,qCAA2B,CAAA;AAQvD,eAAO,MAAM,iBAAiB,uDAiD3B,CAAA;AAaH,eAAO,MAAM,0BAA0B,sCAKrC,CAAA;AAQF,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,qCAA2B,CAAA;AAQvD,eAAO,MAAM,iBAAiB,uDAiD3B,CAAA;AAaH,eAAO,MAAM,0BAA0B,sCAKrC,CAAA;AAQF,eAAO,MAAM,wBAAwB,6CAAkF,CAAA;AASvH,eAAO,MAAM,iBAAiB,iFAQ5B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../src/node/paragraph.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,qCAAyB,CAAA;AAQnD,eAAO,MAAM,eAAe,oDA0BzB,CAAA;AAYH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../src/node/paragraph.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,qCAAyB,CAAA;AAQnD,eAAO,MAAM,eAAe,oDA0BzB,CAAA;AAYH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AASjH,eAAO,MAAM,eAAe,0EAQ1B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.2.
|
|
4
|
+
"version": "7.2.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,16 +32,15 @@
|
|
|
32
32
|
"remark-inline-links": "^6.0.0",
|
|
33
33
|
"tslib": "^2.5.0",
|
|
34
34
|
"unist-util-visit": "^4.0.0",
|
|
35
|
-
"
|
|
36
|
-
"@milkdown/
|
|
37
|
-
"@milkdown/utils": "7.2.3"
|
|
35
|
+
"@milkdown/exception": "7.2.4",
|
|
36
|
+
"@milkdown/utils": "7.2.4"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@types/unist": "^2.0.6",
|
|
41
|
-
"@milkdown/core": "7.2.
|
|
42
|
-
"@milkdown/ctx": "7.2.
|
|
43
|
-
"@milkdown/prose": "7.2.
|
|
44
|
-
"@milkdown/transformer": "7.2.
|
|
40
|
+
"@milkdown/core": "7.2.4",
|
|
41
|
+
"@milkdown/ctx": "7.2.4",
|
|
42
|
+
"@milkdown/prose": "7.2.4",
|
|
43
|
+
"@milkdown/transformer": "7.2.4"
|
|
45
44
|
},
|
|
46
45
|
"nx": {
|
|
47
46
|
"targets": {
|
package/src/mark/emphasis.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
|
|
3
3
|
import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
4
|
-
import {
|
|
4
|
+
import { toggleMark } from '@milkdown/prose/commands'
|
|
5
5
|
import { withMeta } from '../__internal__'
|
|
6
6
|
|
|
7
7
|
/// HTML attributes for the emphasis mark.
|
|
@@ -55,9 +55,7 @@ withMeta(emphasisSchema.ctx, {
|
|
|
55
55
|
|
|
56
56
|
/// A command to toggle the emphasis mark.
|
|
57
57
|
export const toggleEmphasisCommand = $command('ToggleEmphasis', ctx => () => {
|
|
58
|
-
|
|
59
|
-
const mark = ctx.get(remarkStringifyOptionsCtx).emphasis || '*'
|
|
60
|
-
return toggleMarkdownMark(markType, mark)
|
|
58
|
+
return toggleMark(emphasisSchema.type(ctx))
|
|
61
59
|
})
|
|
62
60
|
|
|
63
61
|
withMeta(toggleEmphasisCommand, {
|
package/src/mark/inline-code.ts
CHANGED
|
@@ -46,16 +46,16 @@ withMeta(inlineCodeSchema.ctx, {
|
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
/// A command to toggle the inlineCode mark.
|
|
49
|
-
export const toggleInlineCodeCommand = $command('ToggleInlineCode',
|
|
49
|
+
export const toggleInlineCodeCommand = $command('ToggleInlineCode', ctx => () => (state, dispatch) => {
|
|
50
50
|
const { selection, tr } = state
|
|
51
51
|
if (selection.empty)
|
|
52
52
|
return false
|
|
53
53
|
const { from, to } = selection
|
|
54
54
|
|
|
55
|
-
const has = state.doc.rangeHasMark(from, to, inlineCodeSchema.type())
|
|
55
|
+
const has = state.doc.rangeHasMark(from, to, inlineCodeSchema.type(ctx))
|
|
56
56
|
// remove exists inlineCode mark if have
|
|
57
57
|
if (has) {
|
|
58
|
-
dispatch?.(tr.removeMark(from, to, inlineCodeSchema.type()))
|
|
58
|
+
dispatch?.(tr.removeMark(from, to, inlineCodeSchema.type(ctx)))
|
|
59
59
|
return true
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -69,7 +69,7 @@ export const toggleInlineCodeCommand = $command('ToggleInlineCode', () => () =>
|
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
// add inlineCode mark
|
|
72
|
-
dispatch?.(tr.addMark(from, to, inlineCodeSchema.type().create()))
|
|
72
|
+
dispatch?.(tr.addMark(from, to, inlineCodeSchema.type(ctx).create()))
|
|
73
73
|
return true
|
|
74
74
|
})
|
|
75
75
|
|
package/src/mark/link.ts
CHANGED
|
@@ -65,7 +65,7 @@ export type UpdateLinkCommandPayload = {
|
|
|
65
65
|
}
|
|
66
66
|
/// A command to toggle the link mark.
|
|
67
67
|
/// You can pass the `href` and `title` to the link.
|
|
68
|
-
export const toggleLinkCommand = $command('ToggleLink',
|
|
68
|
+
export const toggleLinkCommand = $command('ToggleLink', ctx => (payload: UpdateLinkCommandPayload = {}) => toggleMark(linkSchema.type(ctx), payload))
|
|
69
69
|
|
|
70
70
|
withMeta(toggleLinkCommand, {
|
|
71
71
|
displayName: 'Command<toggleLinkCommand>',
|
|
@@ -74,7 +74,7 @@ withMeta(toggleLinkCommand, {
|
|
|
74
74
|
|
|
75
75
|
/// A command to update the link mark.
|
|
76
76
|
/// You can pass the `href` and `title` to update the link.
|
|
77
|
-
export const updateLinkCommand = $command('UpdateLink',
|
|
77
|
+
export const updateLinkCommand = $command('UpdateLink', ctx => (payload: UpdateLinkCommandPayload = {}) => (state, dispatch) => {
|
|
78
78
|
if (!dispatch)
|
|
79
79
|
return false
|
|
80
80
|
|
|
@@ -83,7 +83,7 @@ export const updateLinkCommand = $command('UpdateLink', () => (payload: UpdateLi
|
|
|
83
83
|
const { selection } = state
|
|
84
84
|
const { from, to } = selection
|
|
85
85
|
state.doc.nodesBetween(from, from === to ? to + 1 : to, (n, p) => {
|
|
86
|
-
if (linkSchema.type().isInSet(n.marks)) {
|
|
86
|
+
if (linkSchema.type(ctx).isInSet(n.marks)) {
|
|
87
87
|
node = n
|
|
88
88
|
pos = p
|
|
89
89
|
return false
|
|
@@ -95,14 +95,14 @@ export const updateLinkCommand = $command('UpdateLink', () => (payload: UpdateLi
|
|
|
95
95
|
if (!node)
|
|
96
96
|
return false
|
|
97
97
|
|
|
98
|
-
const mark = node.marks.find(({ type }) => type === linkSchema.type())
|
|
98
|
+
const mark = node.marks.find(({ type }) => type === linkSchema.type(ctx))
|
|
99
99
|
if (!mark)
|
|
100
100
|
return false
|
|
101
101
|
|
|
102
102
|
const start = pos
|
|
103
103
|
const end = pos + node.nodeSize
|
|
104
104
|
const { tr } = state
|
|
105
|
-
const linkMark = linkSchema.type().create({ ...mark.attrs, ...payload })
|
|
105
|
+
const linkMark = linkSchema.type(ctx).create({ ...mark.attrs, ...payload })
|
|
106
106
|
if (!linkMark)
|
|
107
107
|
return false
|
|
108
108
|
|
package/src/mark/strong.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
|
|
3
3
|
import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
|
|
4
|
-
import {
|
|
4
|
+
import { toggleMark } from '@milkdown/prose/commands'
|
|
5
5
|
import { withMeta } from '../__internal__'
|
|
6
6
|
|
|
7
7
|
/// HTML attributes for the strong mark.
|
|
@@ -55,10 +55,7 @@ withMeta(strongSchema.ctx, {
|
|
|
55
55
|
|
|
56
56
|
/// A command to toggle the strong mark.
|
|
57
57
|
export const toggleStrongCommand = $command('ToggleStrong', ctx => () => {
|
|
58
|
-
|
|
59
|
-
const markSymbol = ctx.get(remarkStringifyOptionsCtx).strong || '*'
|
|
60
|
-
const mark = markSymbol + markSymbol
|
|
61
|
-
return toggleMarkdownMark(markType, mark)
|
|
58
|
+
return toggleMark(strongSchema.type(ctx))
|
|
62
59
|
})
|
|
63
60
|
|
|
64
61
|
withMeta(toggleStrongCommand, {
|
package/src/node/blockquote.ts
CHANGED
|
@@ -47,7 +47,7 @@ withMeta(blockquoteSchema.ctx, {
|
|
|
47
47
|
|
|
48
48
|
/// This input rule will convert a line that starts with `> ` into a blockquote.
|
|
49
49
|
/// You can type `> ` at the start of a line to create a blockquote.
|
|
50
|
-
export const wrapInBlockquoteInputRule = $inputRule(
|
|
50
|
+
export const wrapInBlockquoteInputRule = $inputRule(ctx => wrappingInputRule(/^\s*>\s$/, blockquoteSchema.type(ctx)))
|
|
51
51
|
|
|
52
52
|
withMeta(wrapInBlockquoteInputRule, {
|
|
53
53
|
displayName: 'InputRule<wrapInBlockquoteInputRule>',
|
|
@@ -55,7 +55,7 @@ withMeta(wrapInBlockquoteInputRule, {
|
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
/// This command will wrap the current selection in a blockquote.
|
|
58
|
-
export const wrapInBlockquoteCommand = $command('WrapInBlockquote',
|
|
58
|
+
export const wrapInBlockquoteCommand = $command('WrapInBlockquote', ctx => () => wrapIn(blockquoteSchema.type(ctx)))
|
|
59
59
|
|
|
60
60
|
withMeta(wrapInBlockquoteCommand, {
|
|
61
61
|
displayName: 'Command<wrapInBlockquoteCommand>',
|
package/src/node/bullet-list.ts
CHANGED
|
@@ -77,7 +77,7 @@ withMeta(bulletListSchema.ctx, {
|
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
/// Input rule for wrapping a block in bullet list node.
|
|
80
|
-
export const wrapInBulletListInputRule = $inputRule(
|
|
80
|
+
export const wrapInBulletListInputRule = $inputRule(ctx => wrappingInputRule(/^\s*([-+*])\s$/, bulletListSchema.type(ctx)))
|
|
81
81
|
|
|
82
82
|
withMeta(wrapInBulletListInputRule, {
|
|
83
83
|
displayName: 'InputRule<wrapInBulletListInputRule>',
|
|
@@ -85,7 +85,7 @@ withMeta(wrapInBulletListInputRule, {
|
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
/// Command for creating bullet list node.
|
|
88
|
-
export const wrapInBulletListCommand = $command('WrapInBulletList',
|
|
88
|
+
export const wrapInBulletListCommand = $command('WrapInBulletList', ctx => () => wrapIn(bulletListSchema.type(ctx)))
|
|
89
89
|
|
|
90
90
|
withMeta(wrapInBulletListCommand, {
|
|
91
91
|
displayName: 'Command<wrapInBulletListCommand>',
|
package/src/node/code-block.ts
CHANGED
|
@@ -88,7 +88,7 @@ withMeta(codeBlockSchema.ctx, {
|
|
|
88
88
|
|
|
89
89
|
/// A input rule for creating code block.
|
|
90
90
|
/// For example, ` ```javascript ` will create a code block with language javascript.
|
|
91
|
-
export const createCodeBlockInputRule = $inputRule(
|
|
91
|
+
export const createCodeBlockInputRule = $inputRule(ctx => textblockTypeInputRule(/^```(?<language>[a-z]*)?[\s\n]$/, codeBlockSchema.type(ctx), match => ({
|
|
92
92
|
language: match.groups?.language ?? '',
|
|
93
93
|
})))
|
|
94
94
|
|
|
@@ -99,7 +99,7 @@ withMeta(createCodeBlockInputRule, {
|
|
|
99
99
|
|
|
100
100
|
/// A command for creating code block.
|
|
101
101
|
/// You can pass the language of the code block as the parameter.
|
|
102
|
-
export const createCodeBlockCommand = $command('CreateCodeBlock',
|
|
102
|
+
export const createCodeBlockCommand = $command('CreateCodeBlock', ctx => (language = '') => setBlockType(codeBlockSchema.type(ctx), { language }))
|
|
103
103
|
|
|
104
104
|
withMeta(createCodeBlockCommand, {
|
|
105
105
|
displayName: 'Command<createCodeBlockCommand>',
|
package/src/node/hardbreak.ts
CHANGED
|
@@ -61,7 +61,7 @@ withMeta(hardbreakSchema.ctx, {
|
|
|
61
61
|
})
|
|
62
62
|
|
|
63
63
|
/// Command to insert a hardbreak.
|
|
64
|
-
export const insertHardbreakCommand = $command('InsertHardbreak',
|
|
64
|
+
export const insertHardbreakCommand = $command('InsertHardbreak', ctx => () => (state, dispatch) => {
|
|
65
65
|
const { selection, tr } = state
|
|
66
66
|
if (selection.empty) {
|
|
67
67
|
// Transform two successive hardbreak into a new line
|
|
@@ -76,7 +76,7 @@ export const insertHardbreakCommand = $command('InsertHardbreak', () => () => (s
|
|
|
76
76
|
return true
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
dispatch?.(tr.setMeta('hardbreak', true).replaceSelectionWith(hardbreakSchema.type().create()).scrollIntoView())
|
|
79
|
+
dispatch?.(tr.setMeta('hardbreak', true).replaceSelectionWith(hardbreakSchema.type(ctx).create()).scrollIntoView())
|
|
80
80
|
return true
|
|
81
81
|
})
|
|
82
82
|
|
package/src/node/heading.ts
CHANGED
|
@@ -100,7 +100,7 @@ withMeta(headingSchema.ctx, {
|
|
|
100
100
|
/// This input rule can turn the selected block into heading.
|
|
101
101
|
/// You can input numbers of `#` and a `space` to create heading.
|
|
102
102
|
export const wrapInHeadingInputRule = $inputRule((ctx) => {
|
|
103
|
-
return textblockTypeInputRule(/^(?<hashes>#+)\s$/, headingSchema.type(), (match) => {
|
|
103
|
+
return textblockTypeInputRule(/^(?<hashes>#+)\s$/, headingSchema.type(ctx), (match) => {
|
|
104
104
|
const x = match.groups?.hashes?.length || 0
|
|
105
105
|
|
|
106
106
|
const view = ctx.get(editorViewCtx)
|
|
@@ -125,14 +125,14 @@ withMeta(wrapInHeadingInputRule, {
|
|
|
125
125
|
/// This command can turn the selected block into heading.
|
|
126
126
|
/// You can pass the level of heading to this command.
|
|
127
127
|
/// By default, the level is 1, which means it will create a `h1` element.
|
|
128
|
-
export const wrapInHeadingCommand = $command('WrapInHeading', () => {
|
|
128
|
+
export const wrapInHeadingCommand = $command('WrapInHeading', (ctx) => {
|
|
129
129
|
return (level?: number) => {
|
|
130
130
|
level ??= 1
|
|
131
131
|
|
|
132
132
|
if (level < 1)
|
|
133
|
-
return setBlockType(paragraphSchema.type())
|
|
133
|
+
return setBlockType(paragraphSchema.type(ctx))
|
|
134
134
|
|
|
135
|
-
return setBlockType(headingSchema.type(), { level })
|
|
135
|
+
return setBlockType(headingSchema.type(ctx), { level })
|
|
136
136
|
}
|
|
137
137
|
})
|
|
138
138
|
|
|
@@ -144,16 +144,16 @@ withMeta(wrapInHeadingCommand, {
|
|
|
144
144
|
/// This command can downgrade the selected heading.
|
|
145
145
|
/// For example, if you have a `h2` element, and you call this command, you will get a `h1` element.
|
|
146
146
|
/// If the element is already a `h1` element, it will turn it into a `p` element.
|
|
147
|
-
export const downgradeHeadingCommand = $command('DowngradeHeading',
|
|
147
|
+
export const downgradeHeadingCommand = $command('DowngradeHeading', ctx => () =>
|
|
148
148
|
(state, dispatch, view) => {
|
|
149
149
|
const { $from } = state.selection
|
|
150
150
|
const node = $from.node()
|
|
151
|
-
if (node.type !== headingSchema.type() || !state.selection.empty || $from.parentOffset !== 0)
|
|
151
|
+
if (node.type !== headingSchema.type(ctx) || !state.selection.empty || $from.parentOffset !== 0)
|
|
152
152
|
return false
|
|
153
153
|
|
|
154
154
|
const level = node.attrs.level - 1
|
|
155
155
|
if (!level)
|
|
156
|
-
return setBlockType(paragraphSchema.type())(state, dispatch, view)
|
|
156
|
+
return setBlockType(paragraphSchema.type(ctx))(state, dispatch, view)
|
|
157
157
|
|
|
158
158
|
dispatch?.(
|
|
159
159
|
state.tr.setNodeMarkup(state.selection.$from.before(), undefined, {
|
|
@@ -198,21 +198,21 @@ export const headingKeymap = $useKeymap('headingKeymap', {
|
|
|
198
198
|
shortcuts: 'Mod-Alt-4',
|
|
199
199
|
command: (ctx) => {
|
|
200
200
|
const commands = ctx.get(commandsCtx)
|
|
201
|
-
return () => commands.call(wrapInHeadingCommand.key,
|
|
201
|
+
return () => commands.call(wrapInHeadingCommand.key, 4)
|
|
202
202
|
},
|
|
203
203
|
},
|
|
204
204
|
TurnIntoH5: {
|
|
205
205
|
shortcuts: 'Mod-Alt-5',
|
|
206
206
|
command: (ctx) => {
|
|
207
207
|
const commands = ctx.get(commandsCtx)
|
|
208
|
-
return () => commands.call(wrapInHeadingCommand.key,
|
|
208
|
+
return () => commands.call(wrapInHeadingCommand.key, 5)
|
|
209
209
|
},
|
|
210
210
|
},
|
|
211
211
|
TurnIntoH6: {
|
|
212
212
|
shortcuts: 'Mod-Alt-6',
|
|
213
213
|
command: (ctx) => {
|
|
214
214
|
const commands = ctx.get(commandsCtx)
|
|
215
|
-
return () => commands.call(wrapInHeadingCommand.key,
|
|
215
|
+
return () => commands.call(wrapInHeadingCommand.key, 6)
|
|
216
216
|
},
|
|
217
217
|
},
|
|
218
218
|
DowngradeHeading: {
|
package/src/node/hr.ts
CHANGED
|
@@ -44,12 +44,12 @@ withMeta(hrSchema.ctx, {
|
|
|
44
44
|
|
|
45
45
|
/// Input rule to insert a hr.
|
|
46
46
|
/// For example, `---` will be converted to a hr.
|
|
47
|
-
export const insertHrInputRule = $inputRule(
|
|
47
|
+
export const insertHrInputRule = $inputRule(ctx => new InputRule(
|
|
48
48
|
/^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
|
|
49
49
|
const { tr } = state
|
|
50
50
|
|
|
51
51
|
if (match[0])
|
|
52
|
-
tr.replaceWith(start - 1, end, hrSchema.type().create())
|
|
52
|
+
tr.replaceWith(start - 1, end, hrSchema.type(ctx).create())
|
|
53
53
|
|
|
54
54
|
return tr
|
|
55
55
|
},
|
|
@@ -61,14 +61,14 @@ withMeta(insertHrInputRule, {
|
|
|
61
61
|
})
|
|
62
62
|
|
|
63
63
|
/// Command to insert a hr.
|
|
64
|
-
export const insertHrCommand = $command('InsertHr',
|
|
64
|
+
export const insertHrCommand = $command('InsertHr', ctx => () => (state, dispatch) => {
|
|
65
65
|
if (!dispatch)
|
|
66
66
|
return true
|
|
67
67
|
|
|
68
|
-
const paragraph = paragraphSchema.node.type().create()
|
|
68
|
+
const paragraph = paragraphSchema.node.type(ctx).create()
|
|
69
69
|
const { tr, selection } = state
|
|
70
70
|
const { from } = selection
|
|
71
|
-
const node = hrSchema.type().create()
|
|
71
|
+
const node = hrSchema.type(ctx).create()
|
|
72
72
|
if (!node)
|
|
73
73
|
return true
|
|
74
74
|
|
package/src/node/image.ts
CHANGED
|
@@ -92,14 +92,14 @@ export type UpdateImageCommandPayload = {
|
|
|
92
92
|
|
|
93
93
|
/// This command will insert a image node.
|
|
94
94
|
/// You can pass a payload to set `src`, `alt` and `title` for the image node.
|
|
95
|
-
export const insertImageCommand = $command('InsertImage',
|
|
95
|
+
export const insertImageCommand = $command('InsertImage', ctx => (payload: UpdateImageCommandPayload = {}) =>
|
|
96
96
|
(state, dispatch) => {
|
|
97
97
|
if (!dispatch)
|
|
98
98
|
return true
|
|
99
99
|
|
|
100
100
|
const { src = '', alt = '', title = '' } = payload
|
|
101
101
|
|
|
102
|
-
const node = imageSchema.type().create({ src, alt, title })
|
|
102
|
+
const node = imageSchema.type(ctx).create({ src, alt, title })
|
|
103
103
|
if (!node)
|
|
104
104
|
return true
|
|
105
105
|
|
|
@@ -114,8 +114,8 @@ withMeta(insertImageCommand, {
|
|
|
114
114
|
|
|
115
115
|
/// This command will update the selected image node.
|
|
116
116
|
/// You can pass a payload to update `src`, `alt` and `title` for the image node.
|
|
117
|
-
export const updateImageCommand = $command('UpdateImage',
|
|
118
|
-
const nodeWithPos = findSelectedNodeOfType(state.selection, imageSchema.type())
|
|
117
|
+
export const updateImageCommand = $command('UpdateImage', ctx => (payload: UpdateImageCommandPayload = {}) => (state, dispatch) => {
|
|
118
|
+
const nodeWithPos = findSelectedNodeOfType(state.selection, imageSchema.type(ctx))
|
|
119
119
|
if (!nodeWithPos)
|
|
120
120
|
return false
|
|
121
121
|
|
|
@@ -142,12 +142,12 @@ withMeta(updateImageCommand, {
|
|
|
142
142
|
/// This input rule will insert a image node.
|
|
143
143
|
/// You can input `` to insert a image node.
|
|
144
144
|
/// The `title` is optional.
|
|
145
|
-
export const insertImageInputRule = $inputRule(
|
|
145
|
+
export const insertImageInputRule = $inputRule(ctx => new InputRule(
|
|
146
146
|
/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
|
|
147
147
|
(state, match, start, end) => {
|
|
148
148
|
const [matched, alt, src = '', title] = match
|
|
149
149
|
if (matched)
|
|
150
|
-
return state.tr.replaceWith(start, end, imageSchema.type().create({ src, alt, title }))
|
|
150
|
+
return state.tr.replaceWith(start, end, imageSchema.type(ctx).create({ src, alt, title }))
|
|
151
151
|
|
|
152
152
|
return null
|
|
153
153
|
},
|
package/src/node/list-item.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { expectDomTypeError } from '@milkdown/exception'
|
|
|
4
4
|
import { liftListItem, sinkListItem, splitListItem } from '@milkdown/prose/schema-list'
|
|
5
5
|
import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
|
|
6
6
|
import { type Command, TextSelection } from '@milkdown/prose/state'
|
|
7
|
+
import type { Ctx } from '@milkdown/ctx'
|
|
7
8
|
import { withMeta } from '../__internal__'
|
|
8
9
|
|
|
9
10
|
/// HTML attributes for list item node.
|
|
@@ -98,7 +99,7 @@ withMeta(listItemSchema.ctx, {
|
|
|
98
99
|
/// * List item 1
|
|
99
100
|
/// * List item 2
|
|
100
101
|
/// ```
|
|
101
|
-
export const sinkListItemCommand = $command('SinkListItem',
|
|
102
|
+
export const sinkListItemCommand = $command('SinkListItem', ctx => () => sinkListItem(listItemSchema.type(ctx)))
|
|
102
103
|
|
|
103
104
|
withMeta(sinkListItemCommand, {
|
|
104
105
|
displayName: 'Command<sinkListItemCommand>',
|
|
@@ -117,7 +118,7 @@ withMeta(sinkListItemCommand, {
|
|
|
117
118
|
/// * List item 1
|
|
118
119
|
/// * List item 2
|
|
119
120
|
/// ```
|
|
120
|
-
export const liftListItemCommand = $command('SplitListItem',
|
|
121
|
+
export const liftListItemCommand = $command('SplitListItem', ctx => () => liftListItem(listItemSchema.type(ctx)))
|
|
121
122
|
|
|
122
123
|
withMeta(liftListItemCommand, {
|
|
123
124
|
displayName: 'Command<liftListItemCommand>',
|
|
@@ -137,14 +138,14 @@ withMeta(liftListItemCommand, {
|
|
|
137
138
|
/// * List item 2
|
|
138
139
|
/// * <- cursor here
|
|
139
140
|
/// ```
|
|
140
|
-
export const splitListItemCommand = $command('SplitListItem',
|
|
141
|
+
export const splitListItemCommand = $command('SplitListItem', ctx => () => splitListItem(listItemSchema.type(ctx)))
|
|
141
142
|
|
|
142
143
|
withMeta(splitListItemCommand, {
|
|
143
144
|
displayName: 'Command<splitListItemCommand>',
|
|
144
145
|
group: 'ListItem',
|
|
145
146
|
})
|
|
146
147
|
|
|
147
|
-
const liftFirstListItem: Command
|
|
148
|
+
const liftFirstListItem = (ctx: Ctx): Command => (state, dispatch, view) => {
|
|
148
149
|
const { selection } = state
|
|
149
150
|
if (!(selection instanceof TextSelection))
|
|
150
151
|
return false
|
|
@@ -157,7 +158,7 @@ const liftFirstListItem: Command = (state, dispatch, view) => {
|
|
|
157
158
|
|
|
158
159
|
const parentItem = $from.node(-1)
|
|
159
160
|
// selection should be in list item and list item should be the first child of the list
|
|
160
|
-
if (parentItem.type !== listItemSchema.type() || parentItem.firstChild !== $from.node())
|
|
161
|
+
if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
|
|
161
162
|
return false
|
|
162
163
|
|
|
163
164
|
const list = $from.node(-2)
|
|
@@ -165,7 +166,7 @@ const liftFirstListItem: Command = (state, dispatch, view) => {
|
|
|
165
166
|
if (list.childCount > 1)
|
|
166
167
|
return false
|
|
167
168
|
|
|
168
|
-
return liftListItem(listItemSchema.type())(state, dispatch, view)
|
|
169
|
+
return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
/// The command to remove list item **only if**:
|
|
@@ -174,7 +175,7 @@ const liftFirstListItem: Command = (state, dispatch, view) => {
|
|
|
174
175
|
/// - List item is the only child of the list.
|
|
175
176
|
///
|
|
176
177
|
/// Most of the time, you shouldn't use this command directly.
|
|
177
|
-
export const liftFirstListItemCommand = $command('LiftFirstListItem',
|
|
178
|
+
export const liftFirstListItemCommand = $command('LiftFirstListItem', ctx => () => liftFirstListItem(ctx))
|
|
178
179
|
|
|
179
180
|
withMeta(liftFirstListItemCommand, {
|
|
180
181
|
displayName: 'Command<liftFirstListItemCommand>',
|
package/src/node/ordered-list.ts
CHANGED
|
@@ -77,9 +77,9 @@ withMeta(orderedListSchema.ctx, {
|
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
/// Input rule for wrapping a block in ordered list node.
|
|
80
|
-
export const wrapInOrderedListInputRule = $inputRule(
|
|
80
|
+
export const wrapInOrderedListInputRule = $inputRule(ctx => wrappingInputRule(
|
|
81
81
|
/^\s*(\d+)\.\s$/,
|
|
82
|
-
orderedListSchema.type(),
|
|
82
|
+
orderedListSchema.type(ctx),
|
|
83
83
|
match => ({ order: Number(match[1]) }),
|
|
84
84
|
(match, node) => node.childCount + node.attrs.order === Number(match[1]),
|
|
85
85
|
))
|
|
@@ -90,7 +90,7 @@ withMeta(wrapInOrderedListInputRule, {
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
/// Command for wrapping a block in ordered list node.
|
|
93
|
-
export const wrapInOrderedListCommand = $command('WrapInOrderedList',
|
|
93
|
+
export const wrapInOrderedListCommand = $command('WrapInOrderedList', ctx => () => wrapIn(orderedListSchema.type(ctx)))
|
|
94
94
|
|
|
95
95
|
withMeta(wrapInOrderedListCommand, {
|
|
96
96
|
displayName: 'Command<wrapInOrderedListCommand>',
|
package/src/node/paragraph.ts
CHANGED
|
@@ -51,7 +51,7 @@ withMeta(paragraphSchema.ctx, {
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
/// This command can turn the selected block into paragraph.
|
|
54
|
-
export const turnIntoTextCommand = $command('TurnIntoText',
|
|
54
|
+
export const turnIntoTextCommand = $command('TurnIntoText', ctx => () => setBlockType(paragraphSchema.type(ctx)))
|
|
55
55
|
|
|
56
56
|
withMeta(turnIntoTextCommand, {
|
|
57
57
|
displayName: 'Command<turnIntoTextCommand>',
|
|
@@ -6,7 +6,7 @@ import { hardbreakSchema } from '../node'
|
|
|
6
6
|
import { withMeta } from '../__internal__'
|
|
7
7
|
|
|
8
8
|
/// This plugin is used to clear the marks around the hardbreak node.
|
|
9
|
-
export const hardbreakClearMarkPlugin = $prose(() => {
|
|
9
|
+
export const hardbreakClearMarkPlugin = $prose((ctx) => {
|
|
10
10
|
return new Plugin({
|
|
11
11
|
key: new PluginKey('MILKDOWN_HARDBREAK_MARKS'),
|
|
12
12
|
appendTransaction: (trs, _oldState, newState) => {
|
|
@@ -25,7 +25,7 @@ export const hardbreakClearMarkPlugin = $prose(() => {
|
|
|
25
25
|
return
|
|
26
26
|
|
|
27
27
|
const { from } = step as unknown as { from: number }
|
|
28
|
-
return newState.tr.setNodeMarkup(from, hardbreakSchema.type(), undefined, [])
|
|
28
|
+
return newState.tr.setNodeMarkup(from, hardbreakSchema.type(ctx), undefined, [])
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const isAddMarkStep = step instanceof AddMarkStep
|
|
@@ -33,8 +33,8 @@ export const hardbreakClearMarkPlugin = $prose(() => {
|
|
|
33
33
|
let _tr = newState.tr
|
|
34
34
|
const { from, to } = step as unknown as { from: number; to: number }
|
|
35
35
|
newState.doc.nodesBetween(from, to, (node, pos) => {
|
|
36
|
-
if (node.type === hardbreakSchema.type())
|
|
37
|
-
_tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(), undefined, [])
|
|
36
|
+
if (node.type === hardbreakSchema.type(ctx))
|
|
37
|
+
_tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(ctx), undefined, [])
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
return _tr
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { $remark } from '@milkdown/utils'
|
|
3
3
|
import type { Node } from 'unist'
|
|
4
|
-
import type { VFile } from 'vfile'
|
|
5
4
|
import { visit } from 'unist-util-visit'
|
|
6
5
|
import { withMeta } from '../__internal__'
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
/// This plugin is used to keep the marker (`_` and `*`) of emphasis and strong nodes.
|
|
8
|
+
export const remarkMarker = $remark(() => () => (tree, file) => {
|
|
9
9
|
const getMarker = (node: Node) => {
|
|
10
10
|
return (file.value as string).charAt(node.position!.start.offset!)
|
|
11
11
|
}
|
|
@@ -20,7 +20,7 @@ export const syncHeadingIdPlugin = $prose((ctx) => {
|
|
|
20
20
|
let found = false
|
|
21
21
|
|
|
22
22
|
view.state.doc.descendants((node, pos) => {
|
|
23
|
-
if (node.type === headingSchema.type()) {
|
|
23
|
+
if (node.type === headingSchema.type(ctx)) {
|
|
24
24
|
if (node.textContent.trim().length === 0)
|
|
25
25
|
return
|
|
26
26
|
|
|
@@ -9,14 +9,14 @@ import { bulletListSchema } from '../node'
|
|
|
9
9
|
import { withMeta } from '../__internal__'
|
|
10
10
|
|
|
11
11
|
/// This plugin is used to keep the label of list item up to date in ordered list.
|
|
12
|
-
export const syncListOrderPlugin = $prose(() => {
|
|
12
|
+
export const syncListOrderPlugin = $prose((ctx) => {
|
|
13
13
|
const syncOrderLabel = (view: EditorView) => {
|
|
14
14
|
if (view.composing || !view.editable)
|
|
15
15
|
return
|
|
16
16
|
|
|
17
|
-
const orderedListType = orderedListSchema.type()
|
|
18
|
-
const bulletListType = bulletListSchema.type()
|
|
19
|
-
const listItemType = listItemSchema.type()
|
|
17
|
+
const orderedListType = orderedListSchema.type(ctx)
|
|
18
|
+
const bulletListType = bulletListSchema.type(ctx)
|
|
19
|
+
const listItemType = listItemSchema.type(ctx)
|
|
20
20
|
const state = view.state
|
|
21
21
|
const handleNodeItem = (attrs: Record<string, any>, index: number): boolean => {
|
|
22
22
|
let changed = false
|