@milkdown/preset-commonmark 6.3.0 → 6.3.1
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 +379 -360
- package/lib/index.es.js.map +1 -1
- package/lib/node/hardbreak.d.ts +5 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/node/hardbreak.ts +30 -1
package/src/node/hardbreak.ts
CHANGED
|
@@ -10,7 +10,15 @@ type Keys = SupportedKeys['HardBreak'];
|
|
|
10
10
|
|
|
11
11
|
export const InsertHardbreak = createCmdKey('InsertHardbreak');
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const HardbreakFilterPluginKey = new PluginKey('MILKDOWN_HARDBREAK_FILTER');
|
|
14
|
+
|
|
15
|
+
export const hardbreak = createNode<
|
|
16
|
+
Keys,
|
|
17
|
+
{
|
|
18
|
+
notIn: string[];
|
|
19
|
+
}
|
|
20
|
+
>((utils, options) => {
|
|
21
|
+
const notIn = options?.notIn ?? ['table', 'fence'];
|
|
14
22
|
return {
|
|
15
23
|
id: 'hardbreak',
|
|
16
24
|
schema: () => ({
|
|
@@ -56,6 +64,27 @@ export const hardbreak = createNode<Keys>((utils) => {
|
|
|
56
64
|
[SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, 'Shift-Enter'),
|
|
57
65
|
},
|
|
58
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
|
+
}),
|
|
59
88
|
new Plugin({
|
|
60
89
|
key: new PluginKey('MILKDOWN_HARDBREAK_MARKS'),
|
|
61
90
|
appendTransaction: (trs, _oldState, newState) => {
|