@milkdown/preset-commonmark 6.5.2 → 6.5.3
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.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +228 -219
- package/lib/index.es.js.map +1 -1
- package/lib/mark/code-inline.d.ts +1 -1
- package/lib/mark/code-inline.d.ts.map +1 -1
- package/lib/mark/em.d.ts +1 -1
- package/lib/mark/em.d.ts.map +1 -1
- package/lib/mark/index.d.ts.map +1 -1
- package/lib/mark/link.d.ts +4 -3
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +1 -1
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts +1 -1
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts +1 -1
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-fence.d.ts.map +1 -1
- package/lib/node/doc.d.ts +1 -1
- package/lib/node/doc.d.ts.map +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts +2 -2
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/hr.d.ts +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/index.d.ts +1 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/list-item.d.ts +2 -2
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts +1 -1
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/node/text.d.ts +1 -1
- package/lib/node/text.d.ts.map +1 -1
- package/lib/plugin/add-order-in-list.d.ts +1 -1
- package/lib/plugin/add-order-in-list.d.ts.map +1 -1
- package/lib/plugin/filter-html.d.ts +1 -1
- package/lib/plugin/filter-html.d.ts.map +1 -1
- package/lib/plugin/index.d.ts +1 -1
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/plugin/inline-nodes-cursor.d.ts.map +1 -1
- package/lib/plugin/inline-sync/config.d.ts +8 -8
- package/lib/plugin/inline-sync/config.d.ts.map +1 -1
- package/lib/plugin/inline-sync/context.d.ts +5 -5
- package/lib/plugin/inline-sync/context.d.ts.map +1 -1
- package/lib/plugin/inline-sync/index.d.ts +1 -1
- package/lib/plugin/inline-sync/index.d.ts.map +1 -1
- package/lib/plugin/inline-sync/regexp.d.ts.map +1 -1
- package/lib/plugin/inline-sync/replacer.d.ts +3 -3
- package/lib/plugin/inline-sync/replacer.d.ts.map +1 -1
- package/lib/plugin/inline-sync/utils.d.ts +2 -2
- package/lib/plugin/inline-sync/utils.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -1
- package/lib/supported-keys.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/index.ts +52 -52
- package/src/mark/code-inline.ts +56 -55
- package/src/mark/em.ts +36 -36
- package/src/mark/index.ts +9 -9
- package/src/mark/link.ts +250 -223
- package/src/mark/strong.ts +37 -37
- package/src/node/blockquote.ts +35 -35
- package/src/node/bullet-list.ts +65 -65
- package/src/node/code-fence.ts +236 -229
- package/src/node/doc.ts +21 -21
- package/src/node/hardbreak.ts +108 -107
- package/src/node/heading.ts +275 -272
- package/src/node/hr.ts +55 -55
- package/src/node/image.ts +216 -210
- package/src/node/index.ts +38 -38
- package/src/node/list-item.ts +139 -140
- package/src/node/ordered-list.ts +71 -71
- package/src/node/paragraph.ts +55 -53
- package/src/node/text.ts +18 -18
- package/src/plugin/add-order-in-list.ts +15 -15
- package/src/plugin/filter-html.ts +31 -33
- package/src/plugin/index.ts +13 -13
- package/src/plugin/inline-nodes-cursor.ts +78 -79
- package/src/plugin/inline-sync/config.ts +46 -45
- package/src/plugin/inline-sync/context.ts +88 -83
- package/src/plugin/inline-sync/index.ts +46 -42
- package/src/plugin/inline-sync/regexp.ts +2 -2
- package/src/plugin/inline-sync/replacer.ts +33 -31
- package/src/plugin/inline-sync/utils.ts +53 -55
- package/src/supported-keys.ts +22 -21
package/src/node/hardbreak.ts
CHANGED
|
@@ -1,124 +1,125 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
-
import { Plugin, PluginKey, Selection } from '@milkdown/prose/state'
|
|
4
|
-
import { AddMarkStep, ReplaceStep } from '@milkdown/prose/transform'
|
|
5
|
-
import { createNode, createShortcut } from '@milkdown/utils'
|
|
2
|
+
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
+
import { Plugin, PluginKey, Selection } from '@milkdown/prose/state'
|
|
4
|
+
import { AddMarkStep, ReplaceStep } from '@milkdown/prose/transform'
|
|
5
|
+
import { createNode, createShortcut } from '@milkdown/utils'
|
|
6
6
|
|
|
7
|
-
import { SupportedKeys } from '../supported-keys'
|
|
7
|
+
import { SupportedKeys } from '../supported-keys'
|
|
8
8
|
|
|
9
|
-
type Keys = SupportedKeys['HardBreak']
|
|
9
|
+
type Keys = SupportedKeys['HardBreak']
|
|
10
10
|
|
|
11
|
-
export const InsertHardbreak = createCmdKey('InsertHardbreak')
|
|
11
|
+
export const InsertHardbreak = createCmdKey('InsertHardbreak')
|
|
12
12
|
|
|
13
|
-
export const HardbreakFilterPluginKey = new PluginKey('MILKDOWN_HARDBREAK_FILTER')
|
|
13
|
+
export const HardbreakFilterPluginKey = new PluginKey('MILKDOWN_HARDBREAK_FILTER')
|
|
14
14
|
|
|
15
15
|
export const hardbreak = createNode<
|
|
16
16
|
Keys,
|
|
17
17
|
{
|
|
18
|
-
|
|
18
|
+
notIn: string[]
|
|
19
19
|
}
|
|
20
20
|
>((utils, options) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
toMarkdown: {
|
|
37
|
-
match: (node) => node.type.name === 'hardbreak',
|
|
38
|
-
runner: (state) => {
|
|
39
|
-
state.addNode('break');
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
commands: (type) => [
|
|
44
|
-
createCmd(InsertHardbreak, () => (state, dispatch) => {
|
|
45
|
-
const { selection, tr } = state;
|
|
46
|
-
if (selection.empty) {
|
|
47
|
-
// Transform two successive hardbreak into a new line
|
|
48
|
-
const node = selection.$from.node();
|
|
49
|
-
if (node.childCount > 0 && node.lastChild?.type.name === 'hardbreak') {
|
|
50
|
-
dispatch?.(
|
|
51
|
-
tr
|
|
52
|
-
.replaceRangeWith(selection.to - 1, selection.to, state.schema.node('paragraph'))
|
|
53
|
-
.setSelection(Selection.near(tr.doc.resolve(selection.to)))
|
|
54
|
-
.scrollIntoView(),
|
|
55
|
-
);
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
dispatch?.(tr.setMeta('hardbreak', true).replaceSelectionWith(type.create()).scrollIntoView());
|
|
60
|
-
return true;
|
|
61
|
-
}),
|
|
62
|
-
],
|
|
63
|
-
shortcuts: {
|
|
64
|
-
[SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, 'Shift-Enter'),
|
|
21
|
+
const notIn = options?.notIn ?? ['table', 'fence']
|
|
22
|
+
return {
|
|
23
|
+
id: 'hardbreak',
|
|
24
|
+
schema: () => ({
|
|
25
|
+
inline: true,
|
|
26
|
+
group: 'inline',
|
|
27
|
+
selectable: false,
|
|
28
|
+
parseDOM: [{ tag: 'br' }],
|
|
29
|
+
toDOM: node => ['br', { class: utils.getClassName(node.attrs, 'hardbreak') }],
|
|
30
|
+
parseMarkdown: {
|
|
31
|
+
match: ({ type }) => type === 'break',
|
|
32
|
+
runner: (state, _, type) => {
|
|
33
|
+
state.addNode(type)
|
|
65
34
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
35
|
+
},
|
|
36
|
+
toMarkdown: {
|
|
37
|
+
match: node => node.type.name === 'hardbreak',
|
|
38
|
+
runner: (state) => {
|
|
39
|
+
state.addNode('break')
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
commands: type => [
|
|
44
|
+
createCmd(InsertHardbreak, () => (state, dispatch) => {
|
|
45
|
+
const { selection, tr } = state
|
|
46
|
+
if (selection.empty) {
|
|
47
|
+
// Transform two successive hardbreak into a new line
|
|
48
|
+
const node = selection.$from.node()
|
|
49
|
+
if (node.childCount > 0 && node.lastChild?.type.name === 'hardbreak') {
|
|
50
|
+
dispatch?.(
|
|
51
|
+
tr
|
|
52
|
+
.replaceRangeWith(selection.to - 1, selection.to, state.schema.node('paragraph'))
|
|
53
|
+
.setSelection(Selection.near(tr.doc.resolve(selection.to)))
|
|
54
|
+
.scrollIntoView(),
|
|
55
|
+
)
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
dispatch?.(tr.setMeta('hardbreak', true).replaceSelectionWith(type.create()).scrollIntoView())
|
|
60
|
+
return true
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
shortcuts: {
|
|
64
|
+
[SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, 'Shift-Enter'),
|
|
65
|
+
},
|
|
66
|
+
prosePlugins: type => [
|
|
67
|
+
new Plugin({
|
|
68
|
+
key: HardbreakFilterPluginKey,
|
|
69
|
+
filterTransaction: (tr, state) => {
|
|
70
|
+
const isInsertHr = tr.getMeta('hardbreak')
|
|
71
|
+
const [step] = tr.steps
|
|
72
|
+
if (isInsertHr && step) {
|
|
73
|
+
const { from } = step as unknown as { from: number }
|
|
74
|
+
const $from = state.doc.resolve(from)
|
|
75
|
+
let curDepth = $from.depth
|
|
76
|
+
let canApply = true
|
|
77
|
+
while (curDepth > 0) {
|
|
78
|
+
if (notIn.includes($from.node(curDepth).type.name))
|
|
79
|
+
canApply = false
|
|
80
|
+
|
|
81
|
+
curDepth--
|
|
82
|
+
}
|
|
83
|
+
return canApply
|
|
84
|
+
}
|
|
85
|
+
return true
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
new Plugin({
|
|
89
|
+
key: new PluginKey('MILKDOWN_HARDBREAK_MARKS'),
|
|
90
|
+
appendTransaction: (trs, _oldState, newState) => {
|
|
91
|
+
if (!trs.length)
|
|
92
|
+
return
|
|
93
|
+
const [tr] = trs
|
|
94
|
+
if (!tr)
|
|
95
|
+
return
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
const [step] = tr.steps
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
const { from } = step as unknown as { from: number };
|
|
103
|
-
return newState.tr.setNodeMarkup(from, type, undefined, []);
|
|
104
|
-
}
|
|
99
|
+
const isInsertHr = tr.getMeta('hardbreak')
|
|
100
|
+
if (isInsertHr) {
|
|
101
|
+
if (!(step instanceof ReplaceStep))
|
|
102
|
+
return
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const { from, to } = step as unknown as { from: number; to: number };
|
|
110
|
-
newState.doc.nodesBetween(from, to, (node, pos) => {
|
|
111
|
-
if (node.type === type) {
|
|
112
|
-
_tr = _tr.setNodeMarkup(pos, type, undefined, []);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
104
|
+
const { from } = step as unknown as { from: number }
|
|
105
|
+
return newState.tr.setNodeMarkup(from, type, undefined, [])
|
|
106
|
+
}
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
const isAddMarkStep = step instanceof AddMarkStep
|
|
109
|
+
if (isAddMarkStep) {
|
|
110
|
+
let _tr = newState.tr
|
|
111
|
+
const { from, to } = step as unknown as { from: number; to: number }
|
|
112
|
+
newState.doc.nodesBetween(from, to, (node, pos) => {
|
|
113
|
+
if (node.type === type)
|
|
114
|
+
_tr = _tr.setNodeMarkup(pos, type, undefined, [])
|
|
115
|
+
})
|
|
118
116
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
117
|
+
return _tr
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return undefined
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
],
|
|
124
|
+
}
|
|
125
|
+
})
|