@milkdown/preset-commonmark 7.1.0 → 7.1.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 +512 -515
- package/lib/index.es.js.map +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -1
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/package.json +11 -8
- package/src/node/hardbreak.ts +1 -0
- package/src/node/heading.ts +4 -20
- package/src/node/paragraph.ts +2 -16
- package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +2 -0
- package/src/utils/index.ts +22 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAejD,eAAO,MAAM,kBAAkB,wCALU,IAAI,kCAK0C,CAAA;AAGvF,eAAO,MAAM,WAAW,qCAAuB,CAAA;AAG/C,eAAO,MAAM,aAAa,kDAmDxB,CAAA;AAIF,eAAO,MAAM,sBAAsB,sCAgBjC,CAAA;AAKF,eAAO,MAAM,oBAAoB,4CAS/B,CAAA;AAKF,eAAO,MAAM,uBAAuB,6CAkBhC,CAAA;AAKJ,eAAO,MAAM,aAAa,sKAkDxB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../src/node/paragraph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../src/node/paragraph.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,qCAAyB,CAAA;AAGnD,eAAO,MAAM,eAAe,oDA0BzB,CAAA;AAGH,eAAO,MAAM,mBAAmB,6CAA6E,CAAA;AAI7G,eAAO,MAAM,eAAe,0EAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-sync-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/inline-sync-plugin.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"inline-sync-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/inline-sync-plugin.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,kCAoD3B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAGjD,eAAO,MAAM,aAAa,UAAW,eAAe,QAAQ,IAAI,SAe/D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.1.
|
|
4
|
+
"version": "7.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,20 +24,23 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@milkdown/core": "^7.0.0-next.0",
|
|
26
26
|
"@milkdown/ctx": "^7.0.0-next.0",
|
|
27
|
-
"@milkdown/prose": "^7.0.0-next.0"
|
|
27
|
+
"@milkdown/prose": "^7.0.0-next.0",
|
|
28
|
+
"@milkdown/transformer": "^7.0.0-next.0"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
31
|
+
"@sindresorhus/slugify": "^2.2.0",
|
|
30
32
|
"remark-inline-links": "^6.0.0",
|
|
31
|
-
"tslib": "^2.
|
|
33
|
+
"tslib": "^2.5.0",
|
|
32
34
|
"unist-util-visit": "^4.0.0",
|
|
33
|
-
"@milkdown/exception": "7.1.
|
|
34
|
-
"@milkdown/utils": "7.1.
|
|
35
|
+
"@milkdown/exception": "7.1.1",
|
|
36
|
+
"@milkdown/utils": "7.1.1"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"@types/unist": "^2.0.6",
|
|
38
|
-
"@milkdown/core": "7.1.
|
|
39
|
-
"@milkdown/ctx": "7.1.
|
|
40
|
-
"@milkdown/prose": "7.1.
|
|
40
|
+
"@milkdown/core": "7.1.1",
|
|
41
|
+
"@milkdown/ctx": "7.1.1",
|
|
42
|
+
"@milkdown/prose": "7.1.1",
|
|
43
|
+
"@milkdown/transformer": "7.1.1"
|
|
41
44
|
},
|
|
42
45
|
"nx": {
|
|
43
46
|
"targets": {
|
package/src/node/hardbreak.ts
CHANGED
|
@@ -31,6 +31,7 @@ export const hardbreakSchema = $nodeSchema('hardbreak', ctx => ({
|
|
|
31
31
|
state.addNode(type, { isInline: Boolean(node.data?.isInline) })
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
|
+
leafText: () => '\n',
|
|
34
35
|
toMarkdown: {
|
|
35
36
|
match: node => node.type.name === 'hardbreak',
|
|
36
37
|
runner: (state, node) => {
|
package/src/node/heading.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { expectDomTypeError } from '@milkdown/exception'
|
|
|
4
4
|
import { setBlockType } from '@milkdown/prose/commands'
|
|
5
5
|
import { textblockTypeInputRule } from '@milkdown/prose/inputrules'
|
|
6
6
|
import type { Node } from '@milkdown/prose/model'
|
|
7
|
-
import { Fragment } from '@milkdown/prose/model'
|
|
8
7
|
import { $command, $ctx, $inputRule, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
|
|
8
|
+
import slugify from '@sindresorhus/slugify'
|
|
9
|
+
import { serializeText } from '../utils'
|
|
9
10
|
import { paragraphSchema } from './paragraph'
|
|
10
11
|
|
|
11
12
|
const headingIndex = Array(6)
|
|
@@ -13,11 +14,7 @@ const headingIndex = Array(6)
|
|
|
13
14
|
.map((_, i) => i + 1)
|
|
14
15
|
|
|
15
16
|
const defaultHeadingIdGenerator = (node: Node) =>
|
|
16
|
-
node.textContent
|
|
17
|
-
.replace(/[\p{P}\p{S}]/gu, '')
|
|
18
|
-
.replace(/\s/g, '-')
|
|
19
|
-
.toLowerCase()
|
|
20
|
-
.trim()
|
|
17
|
+
slugify(node.textContent)
|
|
21
18
|
|
|
22
19
|
/// This is a slice contains a function to generate heading id.
|
|
23
20
|
/// You can configure it to generate id in your own way.
|
|
@@ -73,20 +70,7 @@ export const headingSchema = $nodeSchema('heading', (ctx) => {
|
|
|
73
70
|
match: node => node.type.name === 'heading',
|
|
74
71
|
runner: (state, node) => {
|
|
75
72
|
state.openNode('heading', undefined, { depth: node.attrs.level })
|
|
76
|
-
|
|
77
|
-
if (lastIsHardbreak) {
|
|
78
|
-
const contentArr: Node[] = []
|
|
79
|
-
node.content.forEach((n, _, i) => {
|
|
80
|
-
if (i === node.childCount - 1)
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
contentArr.push(n)
|
|
84
|
-
})
|
|
85
|
-
state.next(Fragment.fromArray(contentArr))
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
state.next(node.content)
|
|
89
|
-
}
|
|
73
|
+
serializeText(state, node)
|
|
90
74
|
state.closeNode()
|
|
91
75
|
},
|
|
92
76
|
},
|
package/src/node/paragraph.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx } from '@milkdown/core'
|
|
3
3
|
import { setBlockType } from '@milkdown/prose/commands'
|
|
4
|
-
import type { Node } from '@milkdown/prose/model'
|
|
5
|
-
import { Fragment } from '@milkdown/prose/model'
|
|
6
4
|
import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
|
|
5
|
+
import { serializeText } from '../utils'
|
|
7
6
|
|
|
8
7
|
/// HTML attributes for paragraph node.
|
|
9
8
|
export const paragraphAttr = $nodeAttr('paragraph')
|
|
@@ -31,20 +30,7 @@ export const paragraphSchema = $nodeSchema('paragraph', ctx => ({
|
|
|
31
30
|
match: node => node.type.name === 'paragraph',
|
|
32
31
|
runner: (state, node) => {
|
|
33
32
|
state.openNode('paragraph')
|
|
34
|
-
|
|
35
|
-
if (lastIsHardbreak) {
|
|
36
|
-
const contentArr: Node[] = []
|
|
37
|
-
node.content.forEach((n, _, i) => {
|
|
38
|
-
if (i === node.childCount - 1)
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
contentArr.push(n)
|
|
42
|
-
})
|
|
43
|
-
state.next(Fragment.fromArray(contentArr))
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
state.next(node.content)
|
|
47
|
-
}
|
|
33
|
+
serializeText(state, node)
|
|
48
34
|
state.closeNode()
|
|
49
35
|
},
|
|
50
36
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { SerializerState } from '@milkdown/transformer'
|
|
3
|
+
import { Fragment } from '@milkdown/prose/model'
|
|
4
|
+
import type { Node } from '@milkdown/prose/model'
|
|
5
|
+
import { hardbreakSchema } from '../node'
|
|
6
|
+
|
|
7
|
+
export const serializeText = (state: SerializerState, node: Node) => {
|
|
8
|
+
const lastIsHardBreak = node.childCount >= 1 && node.lastChild?.type === hardbreakSchema.type()
|
|
9
|
+
if (!lastIsHardBreak) {
|
|
10
|
+
state.next(node.content)
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const contentArr: Node[] = []
|
|
15
|
+
node.content.forEach((n, _, i) => {
|
|
16
|
+
if (i === node.childCount - 1)
|
|
17
|
+
return
|
|
18
|
+
|
|
19
|
+
contentArr.push(n)
|
|
20
|
+
})
|
|
21
|
+
state.next(Fragment.fromArray(contentArr))
|
|
22
|
+
}
|