@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.
- 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 +22 -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/mark/code-inline.ts
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
-
import { MarkType } from '@milkdown/prose/model'
|
|
4
|
-
import { createMark, createShortcut } from '@milkdown/utils'
|
|
2
|
+
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
+
import type { MarkType } from '@milkdown/prose/model'
|
|
4
|
+
import { createMark, createShortcut } from '@milkdown/utils'
|
|
5
5
|
|
|
6
|
-
import { SupportedKeys } from '../supported-keys'
|
|
6
|
+
import { SupportedKeys } from '../supported-keys'
|
|
7
7
|
|
|
8
|
-
type Keys = SupportedKeys['CodeInline']
|
|
9
|
-
const id = 'code_inline'
|
|
8
|
+
type Keys = SupportedKeys['CodeInline']
|
|
9
|
+
const id = 'code_inline'
|
|
10
10
|
|
|
11
|
-
export const ToggleInlineCode = createCmdKey('ToggleInlineCode')
|
|
11
|
+
export const ToggleInlineCode = createCmdKey('ToggleInlineCode')
|
|
12
12
|
|
|
13
13
|
export const codeInline = createMark<Keys>((utils) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
return {
|
|
15
|
+
id,
|
|
16
|
+
schema: () => ({
|
|
17
|
+
priority: 100,
|
|
18
|
+
code: true,
|
|
19
|
+
inclusive: false,
|
|
20
|
+
parseDOM: [{ tag: 'code' }],
|
|
21
|
+
toDOM: mark => ['code', { class: utils.getClassName(mark.attrs, 'code-inline') }],
|
|
22
|
+
parseMarkdown: {
|
|
23
|
+
match: node => node.type === 'inlineCode',
|
|
24
|
+
runner: (state, node, markType) => {
|
|
25
|
+
state.openMark(markType)
|
|
26
|
+
state.addText(node.value as string)
|
|
27
|
+
state.closeMark(markType)
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
toMarkdown: {
|
|
31
|
+
match: mark => mark.type.name === id,
|
|
32
|
+
runner: (state, mark, node) => {
|
|
33
|
+
state.withMark(mark, 'inlineCode', node.text || '')
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
commands: markType => [
|
|
38
|
+
createCmd(ToggleInlineCode, () => (state, dispatch) => {
|
|
39
|
+
const { selection, tr } = state
|
|
40
|
+
if (selection.empty)
|
|
41
|
+
return false
|
|
42
|
+
const { from, to } = selection
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const has = state.doc.rangeHasMark(from, to, markType)
|
|
45
|
+
if (has) {
|
|
46
|
+
dispatch?.(tr.removeMark(from, to, markType))
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
const restMarksName = Object.keys(state.schema.marks).filter(x => x !== markType.name)
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
restMarksName
|
|
53
|
+
.map(name => state.schema.marks[name] as MarkType)
|
|
54
|
+
.forEach((t) => {
|
|
55
|
+
tr.removeMark(from, to, t)
|
|
56
|
+
})
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
58
|
+
dispatch?.(tr.addMark(from, to, markType.create()))
|
|
59
|
+
return true
|
|
60
|
+
}),
|
|
61
|
+
],
|
|
62
|
+
shortcuts: {
|
|
63
|
+
[SupportedKeys.CodeInline]: createShortcut(ToggleInlineCode, 'Mod-e'),
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
})
|
package/src/mark/em.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
-
import { toggleMark } from '@milkdown/prose/commands'
|
|
4
|
-
import { createMark, createShortcut } from '@milkdown/utils'
|
|
2
|
+
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
+
import { toggleMark } from '@milkdown/prose/commands'
|
|
4
|
+
import { createMark, createShortcut } from '@milkdown/utils'
|
|
5
5
|
|
|
6
|
-
import { SupportedKeys } from '../supported-keys'
|
|
6
|
+
import { SupportedKeys } from '../supported-keys'
|
|
7
7
|
|
|
8
|
-
type Keys = SupportedKeys['Em']
|
|
8
|
+
type Keys = SupportedKeys['Em']
|
|
9
9
|
|
|
10
|
-
const id = 'em'
|
|
10
|
+
const id = 'em'
|
|
11
11
|
|
|
12
|
-
export const ToggleItalic = createCmdKey('ToggleItalic')
|
|
13
|
-
export const em = createMark<Keys>(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
toMarkdown: {
|
|
32
|
-
match: (mark) => mark.type.name === id,
|
|
33
|
-
runner: (state, mark) => {
|
|
34
|
-
state.withMark(mark, 'emphasis');
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
commands: (markType) => [createCmd(ToggleItalic, () => toggleMark(markType))],
|
|
39
|
-
shortcuts: {
|
|
40
|
-
[SupportedKeys.Em]: createShortcut(ToggleItalic, 'Mod-i'),
|
|
12
|
+
export const ToggleItalic = createCmdKey('ToggleItalic')
|
|
13
|
+
export const em = createMark<Keys>(utils => ({
|
|
14
|
+
id,
|
|
15
|
+
schema: () => ({
|
|
16
|
+
inclusive: false,
|
|
17
|
+
parseDOM: [
|
|
18
|
+
{ tag: 'i' },
|
|
19
|
+
{ tag: 'em' },
|
|
20
|
+
{ style: 'font-style', getAttrs: value => (value === 'italic') as false },
|
|
21
|
+
],
|
|
22
|
+
toDOM: mark => ['em', { class: utils.getClassName(mark.attrs, id) }],
|
|
23
|
+
parseMarkdown: {
|
|
24
|
+
match: node => node.type === 'emphasis',
|
|
25
|
+
runner: (state, node, markType) => {
|
|
26
|
+
state.openMark(markType)
|
|
27
|
+
state.next(node.children)
|
|
28
|
+
state.closeMark(markType)
|
|
29
|
+
},
|
|
41
30
|
},
|
|
42
|
-
|
|
31
|
+
toMarkdown: {
|
|
32
|
+
match: mark => mark.type.name === id,
|
|
33
|
+
runner: (state, mark) => {
|
|
34
|
+
state.withMark(mark, 'emphasis')
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
commands: markType => [createCmd(ToggleItalic, () => toggleMark(markType))],
|
|
39
|
+
shortcuts: {
|
|
40
|
+
[SupportedKeys.Em]: createShortcut(ToggleItalic, 'Mod-i'),
|
|
41
|
+
},
|
|
42
|
+
}))
|
package/src/mark/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { codeInline } from './code-inline'
|
|
3
|
-
import { em } from './em'
|
|
4
|
-
import { link } from './link'
|
|
5
|
-
import { strong } from './strong'
|
|
2
|
+
import { codeInline } from './code-inline'
|
|
3
|
+
import { em } from './em'
|
|
4
|
+
import { link } from './link'
|
|
5
|
+
import { strong } from './strong'
|
|
6
6
|
|
|
7
|
-
export const marks = [codeInline(), em(), strong(), link()]
|
|
7
|
+
export const marks = [codeInline(), em(), strong(), link()]
|
|
8
8
|
|
|
9
|
-
export * from './code-inline'
|
|
10
|
-
export * from './em'
|
|
11
|
-
export * from './link'
|
|
12
|
-
export * from './strong'
|
|
9
|
+
export * from './code-inline'
|
|
10
|
+
export * from './em'
|
|
11
|
+
export * from './link'
|
|
12
|
+
export * from './strong'
|