@milkdown/preset-commonmark 6.5.2 → 6.5.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.
Files changed (88) hide show
  1. package/lib/index.d.ts +1 -1
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.es.js +228 -219
  4. package/lib/index.es.js.map +1 -1
  5. package/lib/mark/code-inline.d.ts +1 -1
  6. package/lib/mark/code-inline.d.ts.map +1 -1
  7. package/lib/mark/em.d.ts +1 -1
  8. package/lib/mark/em.d.ts.map +1 -1
  9. package/lib/mark/index.d.ts.map +1 -1
  10. package/lib/mark/link.d.ts +4 -3
  11. package/lib/mark/link.d.ts.map +1 -1
  12. package/lib/mark/strong.d.ts +1 -1
  13. package/lib/mark/strong.d.ts.map +1 -1
  14. package/lib/node/blockquote.d.ts +1 -1
  15. package/lib/node/blockquote.d.ts.map +1 -1
  16. package/lib/node/bullet-list.d.ts +1 -1
  17. package/lib/node/bullet-list.d.ts.map +1 -1
  18. package/lib/node/code-fence.d.ts.map +1 -1
  19. package/lib/node/doc.d.ts +1 -1
  20. package/lib/node/doc.d.ts.map +1 -1
  21. package/lib/node/hardbreak.d.ts.map +1 -1
  22. package/lib/node/heading.d.ts +2 -2
  23. package/lib/node/heading.d.ts.map +1 -1
  24. package/lib/node/hr.d.ts +1 -1
  25. package/lib/node/hr.d.ts.map +1 -1
  26. package/lib/node/image.d.ts +2 -2
  27. package/lib/node/image.d.ts.map +1 -1
  28. package/lib/node/index.d.ts +1 -1
  29. package/lib/node/index.d.ts.map +1 -1
  30. package/lib/node/list-item.d.ts +2 -2
  31. package/lib/node/list-item.d.ts.map +1 -1
  32. package/lib/node/ordered-list.d.ts +1 -1
  33. package/lib/node/ordered-list.d.ts.map +1 -1
  34. package/lib/node/paragraph.d.ts +1 -1
  35. package/lib/node/paragraph.d.ts.map +1 -1
  36. package/lib/node/text.d.ts +1 -1
  37. package/lib/node/text.d.ts.map +1 -1
  38. package/lib/plugin/add-order-in-list.d.ts +1 -1
  39. package/lib/plugin/add-order-in-list.d.ts.map +1 -1
  40. package/lib/plugin/filter-html.d.ts +1 -1
  41. package/lib/plugin/filter-html.d.ts.map +1 -1
  42. package/lib/plugin/index.d.ts +1 -1
  43. package/lib/plugin/index.d.ts.map +1 -1
  44. package/lib/plugin/inline-nodes-cursor.d.ts.map +1 -1
  45. package/lib/plugin/inline-sync/config.d.ts +8 -8
  46. package/lib/plugin/inline-sync/config.d.ts.map +1 -1
  47. package/lib/plugin/inline-sync/context.d.ts +5 -5
  48. package/lib/plugin/inline-sync/context.d.ts.map +1 -1
  49. package/lib/plugin/inline-sync/index.d.ts +1 -1
  50. package/lib/plugin/inline-sync/index.d.ts.map +1 -1
  51. package/lib/plugin/inline-sync/regexp.d.ts.map +1 -1
  52. package/lib/plugin/inline-sync/replacer.d.ts +3 -3
  53. package/lib/plugin/inline-sync/replacer.d.ts.map +1 -1
  54. package/lib/plugin/inline-sync/utils.d.ts +2 -2
  55. package/lib/plugin/inline-sync/utils.d.ts.map +1 -1
  56. package/lib/supported-keys.d.ts +1 -1
  57. package/lib/supported-keys.d.ts.map +1 -1
  58. package/package.json +22 -17
  59. package/src/index.ts +52 -52
  60. package/src/mark/code-inline.ts +56 -55
  61. package/src/mark/em.ts +36 -36
  62. package/src/mark/index.ts +9 -9
  63. package/src/mark/link.ts +250 -223
  64. package/src/mark/strong.ts +37 -37
  65. package/src/node/blockquote.ts +35 -35
  66. package/src/node/bullet-list.ts +65 -65
  67. package/src/node/code-fence.ts +236 -229
  68. package/src/node/doc.ts +21 -21
  69. package/src/node/hardbreak.ts +108 -107
  70. package/src/node/heading.ts +275 -272
  71. package/src/node/hr.ts +55 -55
  72. package/src/node/image.ts +216 -210
  73. package/src/node/index.ts +38 -38
  74. package/src/node/list-item.ts +139 -140
  75. package/src/node/ordered-list.ts +71 -71
  76. package/src/node/paragraph.ts +55 -53
  77. package/src/node/text.ts +18 -18
  78. package/src/plugin/add-order-in-list.ts +15 -15
  79. package/src/plugin/filter-html.ts +31 -33
  80. package/src/plugin/index.ts +13 -13
  81. package/src/plugin/inline-nodes-cursor.ts +78 -79
  82. package/src/plugin/inline-sync/config.ts +46 -45
  83. package/src/plugin/inline-sync/context.ts +88 -83
  84. package/src/plugin/inline-sync/index.ts +46 -42
  85. package/src/plugin/inline-sync/regexp.ts +2 -2
  86. package/src/plugin/inline-sync/replacer.ts +33 -31
  87. package/src/plugin/inline-sync/utils.ts +53 -55
  88. package/src/supported-keys.ts +22 -21
@@ -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
- notIn: string[];
18
+ notIn: string[]
19
19
  }
20
20
  >((utils, options) => {
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);
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
- 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) return;
92
- const [tr] = trs;
93
- if (!tr) return;
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
- const [step] = tr.steps;
97
+ const [step] = tr.steps
96
98
 
97
- const isInsertHr = tr.getMeta('hardbreak');
98
- if (isInsertHr) {
99
- if (!(step instanceof ReplaceStep)) {
100
- return;
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
- const isAddMarkStep = step instanceof AddMarkStep;
107
- if (isAddMarkStep) {
108
- let _tr = newState.tr;
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
- return _tr;
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
- return;
120
- },
121
- }),
122
- ],
123
- };
124
- });
117
+ return _tr
118
+ }
119
+
120
+ return undefined
121
+ },
122
+ }),
123
+ ],
124
+ }
125
+ })