@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.
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 +17 -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,59 +1,63 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx, editorViewCtx } from '@milkdown/core';
3
- import { Plugin, PluginKey } from '@milkdown/prose/state';
2
+ import type { Ctx } from '@milkdown/core'
3
+ import { editorViewCtx } from '@milkdown/core'
4
+ import { Plugin, PluginKey } from '@milkdown/prose/state'
4
5
 
5
- import { inlineSyncConfigCtx } from './config';
6
- import { getContextByState } from './context';
7
- import { runReplacer } from './replacer';
6
+ import { inlineSyncConfigCtx } from './config'
7
+ import { getContextByState } from './context'
8
+ import { runReplacer } from './replacer'
8
9
 
9
- export * from './config';
10
+ export * from './config'
10
11
 
11
- export const inlineSyncPluginKey = new PluginKey('MILKDOWN_INLINE_SYNC');
12
+ export const inlineSyncPluginKey = new PluginKey('MILKDOWN_INLINE_SYNC')
12
13
  export const getInlineSyncPlugin = (ctx: Ctx) => {
13
- let requestId: number | null = null;
14
- const inlineSyncPlugin = new Plugin<null>({
15
- key: inlineSyncPluginKey,
16
- state: {
17
- init: () => {
18
- return null;
19
- },
20
- apply: (tr, _value, _oldState, newState) => {
21
- const view = ctx.get(editorViewCtx);
22
- if (!view.hasFocus?.() || !view.editable) return null;
14
+ let requestId: number | null = null
15
+ const inlineSyncPlugin = new Plugin<null>({
16
+ key: inlineSyncPluginKey,
17
+ state: {
18
+ init: () => {
19
+ return null
20
+ },
21
+ apply: (tr, _value, _oldState, newState) => {
22
+ const view = ctx.get(editorViewCtx)
23
+ if (!view.hasFocus?.() || !view.editable)
24
+ return null
23
25
 
24
- if (!tr.docChanged) return null;
26
+ if (!tr.docChanged)
27
+ return null
25
28
 
26
- const meta = tr.getMeta(inlineSyncPluginKey);
27
- if (meta) {
28
- return null;
29
- }
29
+ const meta = tr.getMeta(inlineSyncPluginKey)
30
+ if (meta)
31
+ return null
30
32
 
31
- const context = getContextByState(ctx, newState);
32
- if (!context) return null;
33
+ const context = getContextByState(ctx, newState)
34
+ if (!context)
35
+ return null
33
36
 
34
- if (requestId) {
35
- cancelAnimationFrame(requestId);
36
- requestId = null;
37
- }
37
+ if (requestId) {
38
+ cancelAnimationFrame(requestId)
39
+ requestId = null
40
+ }
38
41
 
39
- const { prevNode, nextNode, text } = context;
42
+ const { prevNode, nextNode, text } = context
40
43
 
41
- const { shouldSyncNode } = ctx.get(inlineSyncConfigCtx);
44
+ const { shouldSyncNode } = ctx.get(inlineSyncConfigCtx)
42
45
 
43
- if (!shouldSyncNode({ prevNode, nextNode, ctx, tr, text })) return null;
46
+ if (!shouldSyncNode({ prevNode, nextNode, ctx, tr, text }))
47
+ return null
44
48
 
45
- requestId = requestAnimationFrame(() => {
46
- requestId = null;
49
+ requestId = requestAnimationFrame(() => {
50
+ requestId = null
47
51
 
48
- const { dispatch, state } = ctx.get(editorViewCtx);
52
+ const { dispatch, state } = ctx.get(editorViewCtx)
49
53
 
50
- runReplacer(ctx, inlineSyncPluginKey, state, dispatch, prevNode.attrs);
51
- });
54
+ runReplacer(ctx, inlineSyncPluginKey, state, dispatch, prevNode.attrs)
55
+ })
52
56
 
53
- return null;
54
- },
55
- },
56
- });
57
+ return null
58
+ },
59
+ },
60
+ })
57
61
 
58
- return inlineSyncPlugin;
59
- };
62
+ return inlineSyncPlugin
63
+ }
@@ -1,6 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- export const linkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/;
3
+ export const linkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
4
4
 
5
5
  export const punctuationRegexp = (holePlaceholder: string) =>
6
- new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g');
6
+ new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
@@ -1,43 +1,45 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx } from '@milkdown/core';
3
- import { Attrs } from '@milkdown/prose/model';
4
- import { EditorState, PluginKey, TextSelection, Transaction } from '@milkdown/prose/state';
2
+ import type { Ctx } from '@milkdown/core'
3
+ import type { Attrs } from '@milkdown/prose/model'
4
+ import type { EditorState, PluginKey, Transaction } from '@milkdown/prose/state'
5
+ import { TextSelection } from '@milkdown/prose/state'
5
6
 
6
- import { inlineSyncConfigCtx } from './config';
7
- import { getContextByState } from './context';
8
- import { calcOffset } from './utils';
7
+ import { inlineSyncConfigCtx } from './config'
8
+ import { getContextByState } from './context'
9
+ import { calcOffset } from './utils'
9
10
 
10
11
  export const runReplacer = (
11
- ctx: Ctx,
12
- key: PluginKey,
13
- state: EditorState,
14
- dispatch: (tr: Transaction) => void,
15
- attrs: Attrs,
12
+ ctx: Ctx,
13
+ key: PluginKey,
14
+ state: EditorState,
15
+ dispatch: (tr: Transaction) => void,
16
+ attrs: Attrs,
16
17
  ) => {
17
- const { placeholderConfig } = ctx.get(inlineSyncConfigCtx);
18
- const holePlaceholder = placeholderConfig.hole;
19
- // insert a placeholder to restore the selection
20
- let tr = state.tr.setMeta(key, true).insertText(holePlaceholder, state.selection.from);
18
+ const { placeholderConfig } = ctx.get(inlineSyncConfigCtx)
19
+ const holePlaceholder = placeholderConfig.hole
20
+ // insert a placeholder to restore the selection
21
+ let tr = state.tr.setMeta(key, true).insertText(holePlaceholder, state.selection.from)
21
22
 
22
- const nextState = state.apply(tr);
23
- const context = getContextByState(ctx, nextState);
23
+ const nextState = state.apply(tr)
24
+ const context = getContextByState(ctx, nextState)
24
25
 
25
- if (!context) return;
26
+ if (!context)
27
+ return
26
28
 
27
- const { $from } = nextState.selection;
28
- const from = $from.before();
29
- const to = $from.after();
29
+ const { $from } = nextState.selection
30
+ const from = $from.before()
31
+ const to = $from.after()
30
32
 
31
- const offset = calcOffset(context.nextNode, from, context.placeholder);
33
+ const offset = calcOffset(context.nextNode, from, context.placeholder)
32
34
 
33
- tr = tr
34
- .replaceWith(from, to, context.nextNode)
35
- .setNodeMarkup(from, undefined, attrs)
36
- // delete the placeholder
37
- .delete(offset + 1, offset + 2);
35
+ tr = tr
36
+ .replaceWith(from, to, context.nextNode)
37
+ .setNodeMarkup(from, undefined, attrs)
38
+ // delete the placeholder
39
+ .delete(offset + 1, offset + 2)
38
40
 
39
- // restore the selection
40
- tr = tr.setSelection(TextSelection.near(tr.doc.resolve(offset + 1)));
41
+ // restore the selection
42
+ tr = tr.setSelection(TextSelection.near(tr.doc.resolve(offset + 1)))
41
43
 
42
- dispatch(tr);
43
- };
44
+ dispatch(tr)
45
+ }
@@ -1,73 +1,71 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- import { Node } from '@milkdown/prose/model';
3
+ import type { Node } from '@milkdown/prose/model'
4
4
 
5
- import { SyncNodePlaceholder } from './config';
6
- import { linkRegexp, punctuationRegexp } from './regexp';
5
+ import type { SyncNodePlaceholder } from './config'
6
+ import { linkRegexp, punctuationRegexp } from './regexp'
7
7
 
8
8
  export const keepLink = (str: string) => {
9
- let text = str;
10
- let match = text.match(linkRegexp);
11
- while (match && match.groups) {
12
- const { span } = match.groups;
13
- text = text.replace(linkRegexp, span as string);
9
+ let text = str
10
+ let match = text.match(linkRegexp)
11
+ while (match && match.groups) {
12
+ const { span } = match.groups
13
+ text = text.replace(linkRegexp, span as string)
14
14
 
15
- match = text.match(linkRegexp);
16
- }
17
- return text;
18
- };
15
+ match = text.match(linkRegexp)
16
+ }
17
+ return text
18
+ }
19
19
 
20
20
  export const swap = (text: string, first: number, last: number) => {
21
- const arr = text.split('');
22
- const temp = arr[first];
23
- if (arr[first] && arr[last]) {
24
- arr[first] = arr[last] as string;
25
- arr[last] = temp as string;
26
- }
27
- return arr.join('').toString();
28
- };
21
+ const arr = text.split('')
22
+ const temp = arr[first]
23
+ if (arr[first] && arr[last]) {
24
+ arr[first] = arr[last] as string
25
+ arr[last] = temp as string
26
+ }
27
+ return arr.join('').toString()
28
+ }
29
29
 
30
30
  export const replacePunctuation = (holePlaceholder: string) => (text: string) =>
31
- text.replace(punctuationRegexp(holePlaceholder), '');
31
+ text.replace(punctuationRegexp(holePlaceholder), '')
32
32
 
33
33
  export const calculatePlaceholder = (placeholder: SyncNodePlaceholder) => (text: string) => {
34
- const index = text.indexOf(placeholder.hole);
35
- const left = text.charAt(index - 1);
36
- const right = text.charAt(index + 1);
37
- const notAWord = /[^\w]|_/;
34
+ const index = text.indexOf(placeholder.hole)
35
+ const left = text.charAt(index - 1)
36
+ const right = text.charAt(index + 1)
37
+ const notAWord = /[^\w]|_/
38
38
 
39
- // cursor on the right
40
- if (!right) {
41
- return placeholder.punctuation;
42
- }
39
+ // cursor on the right
40
+ if (!right)
41
+ return placeholder.punctuation
43
42
 
44
- // cursor on the left
45
- if (!left) {
46
- return placeholder.char;
47
- }
43
+ // cursor on the left
44
+ if (!left)
45
+ return placeholder.char
48
46
 
49
- if (notAWord.test(left) && notAWord.test(right)) {
50
- return placeholder.punctuation;
51
- }
47
+ if (notAWord.test(left) && notAWord.test(right))
48
+ return placeholder.punctuation
52
49
 
53
- return placeholder.char;
54
- };
50
+ return placeholder.char
51
+ }
55
52
 
56
53
  export const calcOffset = (node: Node, from: number, placeholder: string) => {
57
- let offset = from;
58
- let find = false;
59
- node.descendants((n) => {
60
- if (find) return false;
61
- if (n.isText) {
62
- const i = n.text?.indexOf(placeholder);
63
- if (i != null && i >= 0) {
64
- find = true;
65
- offset += i;
66
- return false;
67
- }
68
- }
69
- offset += n.nodeSize;
70
- return;
71
- });
72
- return offset;
73
- };
54
+ let offset = from
55
+ let find = false
56
+ node.descendants((n) => {
57
+ if (find)
58
+ return false
59
+ if (n.isText) {
60
+ const i = n.text?.indexOf(placeholder)
61
+ if (i != null && i >= 0) {
62
+ find = true
63
+ offset += i
64
+ return false
65
+ }
66
+ }
67
+ offset += n.nodeSize
68
+ return undefined
69
+ })
70
+ return offset
71
+ }
@@ -1,24 +1,25 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  export const SupportedKeys = {
3
- HardBreak: 'HardBreak',
4
- Blockquote: 'Blockquote',
5
- BulletList: 'BulletList',
6
- OrderedList: 'OrderedList',
7
- CodeFence: 'CodeFence',
8
- H1: 'H1',
9
- H2: 'H2',
10
- H3: 'H3',
11
- H4: 'H4',
12
- H5: 'H5',
13
- H6: 'H6',
14
- DowngradeHeading: 'DowngradeHeading',
15
- Text: 'Text',
16
- CodeInline: 'CodeInline',
17
- Em: 'Em',
18
- Bold: 'Bold',
19
- NextListItem: 'NextListItem',
20
- SinkListItem: 'SinkListItem',
21
- LiftListItem: 'LiftListItem',
22
- } as const;
3
+ HardBreak: 'HardBreak',
4
+ Blockquote: 'Blockquote',
5
+ BulletList: 'BulletList',
6
+ OrderedList: 'OrderedList',
7
+ CodeFence: 'CodeFence',
8
+ H1: 'H1',
9
+ H2: 'H2',
10
+ H3: 'H3',
11
+ H4: 'H4',
12
+ H5: 'H5',
13
+ H6: 'H6',
14
+ DowngradeHeading: 'DowngradeHeading',
15
+ Text: 'Text',
16
+ CodeInline: 'CodeInline',
17
+ Em: 'Em',
18
+ Bold: 'Bold',
19
+ NextListItem: 'NextListItem',
20
+ SinkListItem: 'SinkListItem',
21
+ LiftListItem: 'LiftListItem',
22
+ } as const
23
23
 
24
- export type SupportedKeys = typeof SupportedKeys;
24
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
25
+ export type SupportedKeys = typeof SupportedKeys