@milkdown/preset-commonmark 7.0.1 → 7.1.0
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/composed/plugins.d.ts.map +1 -1
- package/lib/composed/schema.d.ts.map +1 -1
- package/lib/index.es.js +493 -457
- package/lib/index.es.js.map +1 -1
- package/lib/node/html.d.ts +3 -0
- package/lib/node/html.d.ts.map +1 -0
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.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/remark-html-transformer.d.ts +2 -0
- package/lib/plugin/remark-html-transformer.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/composed/plugins.ts +15 -2
- package/src/composed/schema.ts +29 -1
- package/src/node/html.ts +47 -0
- package/src/node/index.ts +2 -0
- package/src/plugin/index.ts +1 -1
- package/src/plugin/inline-sync-plugin/context.ts +6 -6
- package/src/plugin/inline-sync-plugin/replacer.ts +1 -1
- package/src/plugin/{remark-html-filter.ts → remark-html-transformer.ts} +9 -3
- package/lib/plugin/remark-html-filter.d.ts +0 -2
- package/lib/plugin/remark-html-filter.d.ts.map +0 -1
package/lib/node/index.d.ts
CHANGED
package/lib/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,MAAM,CAAA;AACpB,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,MAAM,CAAA;AACpB,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA;AAEtB,cAAc,QAAQ,CAAA"}
|
package/lib/plugin/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from './inline-sync-plugin';
|
|
|
2
2
|
export * from './remark-add-order-in-list-plugin';
|
|
3
3
|
export * from './remark-line-break';
|
|
4
4
|
export * from './remark-inline-link-plugin';
|
|
5
|
-
export * from './remark-html-
|
|
5
|
+
export * from './remark-html-transformer';
|
|
6
6
|
export * from './inline-nodes-cursor-plugin';
|
|
7
7
|
export * from './hardbreak-clear-mark-plugin';
|
|
8
8
|
export * from './hardbreak-filter-plugin';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAA;AAEpC,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAA;AAEpC,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AAEzC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AAEzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remark-html-transformer.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-html-transformer.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,qBAAqB,mCAahC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0
|
|
4
|
+
"version": "7.1.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"remark-inline-links": "^6.0.0",
|
|
31
31
|
"tslib": "^2.4.0",
|
|
32
32
|
"unist-util-visit": "^4.0.0",
|
|
33
|
-
"@milkdown/exception": "7.0
|
|
34
|
-
"@milkdown/utils": "7.0
|
|
33
|
+
"@milkdown/exception": "7.1.0",
|
|
34
|
+
"@milkdown/utils": "7.1.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/unist": "^2.0.6",
|
|
38
|
-
"@milkdown/core": "7.0
|
|
39
|
-
"@milkdown/ctx": "7.0
|
|
40
|
-
"@milkdown/prose": "7.0
|
|
38
|
+
"@milkdown/core": "7.1.0",
|
|
39
|
+
"@milkdown/ctx": "7.1.0",
|
|
40
|
+
"@milkdown/prose": "7.1.0"
|
|
41
41
|
},
|
|
42
42
|
"nx": {
|
|
43
43
|
"targets": {
|
package/src/composed/plugins.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
3
|
import type { MilkdownPlugin } from '@milkdown/ctx'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
hardbreakClearMarkPlugin,
|
|
6
|
+
hardbreakFilterNodes,
|
|
7
|
+
hardbreakFilterPlugin,
|
|
8
|
+
inlineNodesCursorPlugin,
|
|
9
|
+
inlineSyncConfig,
|
|
10
|
+
inlineSyncPlugin,
|
|
11
|
+
remarkAddOrderInListPlugin,
|
|
12
|
+
remarkHtmlTransformer,
|
|
13
|
+
remarkInlineLinkPlugin,
|
|
14
|
+
remarkLineBreak,
|
|
15
|
+
syncHeadingIdPlugin,
|
|
16
|
+
syncListOrderPlugin,
|
|
17
|
+
} from '../plugin'
|
|
5
18
|
|
|
6
19
|
/// @internal
|
|
7
20
|
export const plugins: MilkdownPlugin[] = [
|
|
@@ -17,7 +30,7 @@ export const plugins: MilkdownPlugin[] = [
|
|
|
17
30
|
remarkAddOrderInListPlugin,
|
|
18
31
|
remarkInlineLinkPlugin,
|
|
19
32
|
remarkLineBreak,
|
|
20
|
-
|
|
33
|
+
remarkHtmlTransformer,
|
|
21
34
|
|
|
22
35
|
syncHeadingIdPlugin,
|
|
23
36
|
syncListOrderPlugin,
|
package/src/composed/schema.ts
CHANGED
|
@@ -2,7 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
import type { MilkdownPlugin } from '@milkdown/ctx'
|
|
4
4
|
import { emphasisAttr, emphasisSchema, inlineCodeAttr, inlineCodeSchema, linkAttr, linkSchema, strongAttr, strongSchema } from '../mark'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
blockquoteAttr,
|
|
7
|
+
blockquoteSchema,
|
|
8
|
+
bulletListAttr,
|
|
9
|
+
bulletListSchema,
|
|
10
|
+
codeBlockAttr,
|
|
11
|
+
codeBlockSchema,
|
|
12
|
+
docSchema,
|
|
13
|
+
hardbreakAttr,
|
|
14
|
+
hardbreakSchema,
|
|
15
|
+
headingAttr,
|
|
16
|
+
headingIdGenerator,
|
|
17
|
+
headingSchema,
|
|
18
|
+
hrAttr,
|
|
19
|
+
hrSchema, htmlAttr,
|
|
20
|
+
htmlSchema,
|
|
21
|
+
imageAttr,
|
|
22
|
+
imageSchema,
|
|
23
|
+
listItemAttr,
|
|
24
|
+
listItemSchema,
|
|
25
|
+
orderedListAttr,
|
|
26
|
+
orderedListSchema,
|
|
27
|
+
paragraphAttr,
|
|
28
|
+
paragraphSchema,
|
|
29
|
+
textSchema,
|
|
30
|
+
} from '../node'
|
|
6
31
|
|
|
7
32
|
/// @internal
|
|
8
33
|
export const schema: MilkdownPlugin[] = [
|
|
@@ -51,5 +76,8 @@ export const schema: MilkdownPlugin[] = [
|
|
|
51
76
|
linkAttr,
|
|
52
77
|
linkSchema,
|
|
53
78
|
|
|
79
|
+
htmlAttr,
|
|
80
|
+
htmlSchema,
|
|
81
|
+
|
|
54
82
|
textSchema,
|
|
55
83
|
].flat()
|
package/src/node/html.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { $nodeAttr, $nodeSchema } from '@milkdown/utils'
|
|
3
|
+
|
|
4
|
+
export const htmlAttr = $nodeAttr('html')
|
|
5
|
+
|
|
6
|
+
export const htmlSchema = $nodeSchema('html', (ctx) => {
|
|
7
|
+
return {
|
|
8
|
+
atom: true,
|
|
9
|
+
group: 'inline',
|
|
10
|
+
inline: true,
|
|
11
|
+
attrs: {
|
|
12
|
+
value: {
|
|
13
|
+
default: '',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
toDOM: (node) => {
|
|
17
|
+
const span = document.createElement('span')
|
|
18
|
+
const attr = {
|
|
19
|
+
...ctx.get(htmlAttr.key)(node),
|
|
20
|
+
'data-value': node.attrs.value,
|
|
21
|
+
'data-type': 'html',
|
|
22
|
+
}
|
|
23
|
+
span.textContent = node.attrs.value
|
|
24
|
+
return ['span', attr, node.attrs.value]
|
|
25
|
+
},
|
|
26
|
+
parseDOM: [{
|
|
27
|
+
tag: 'span[data-type="html"]',
|
|
28
|
+
getAttrs: (dom) => {
|
|
29
|
+
return {
|
|
30
|
+
value: (dom as HTMLElement).dataset.value ?? '',
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
}],
|
|
34
|
+
parseMarkdown: {
|
|
35
|
+
match: ({ type }) => Boolean(type === 'html'),
|
|
36
|
+
runner: (state, node, type) => {
|
|
37
|
+
state.addNode(type, { value: node.value as string })
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
toMarkdown: {
|
|
41
|
+
match: node => node.type.name === 'html',
|
|
42
|
+
runner: (state, node) => {
|
|
43
|
+
state.addNode('html', undefined, node.attrs.value)
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
})
|
package/src/node/index.ts
CHANGED
package/src/plugin/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './inline-sync-plugin'
|
|
|
5
5
|
export * from './remark-add-order-in-list-plugin'
|
|
6
6
|
export * from './remark-line-break'
|
|
7
7
|
export * from './remark-inline-link-plugin'
|
|
8
|
-
export * from './remark-html-
|
|
8
|
+
export * from './remark-html-transformer'
|
|
9
9
|
|
|
10
10
|
export * from './inline-nodes-cursor-plugin'
|
|
11
11
|
|
|
@@ -16,11 +16,7 @@ export interface InlineSyncContext {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const getNodeFromSelection = (state: EditorState) => {
|
|
19
|
-
|
|
20
|
-
const { $from } = selection
|
|
21
|
-
const node = $from.node()
|
|
22
|
-
|
|
23
|
-
return node
|
|
19
|
+
return state.selection.$from.node()
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
const getMarkdown = (ctx: Ctx, state: EditorState, node: Node, globalNode: Node[]) => {
|
|
@@ -80,6 +76,10 @@ const collectGlobalNodes = (ctx: Ctx, state: EditorState) => {
|
|
|
80
76
|
|
|
81
77
|
const removeGlobalFromText = (text: string) => text.split('\n\n')[0] || ''
|
|
82
78
|
|
|
79
|
+
const onlyHTML = (node: Node) => {
|
|
80
|
+
return node.childCount === 1 && node.child(0).type.name === 'html'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
83
|
export const getContextByState = (ctx: Ctx, state: EditorState): InlineSyncContext | null => {
|
|
84
84
|
try {
|
|
85
85
|
const globalNode = collectGlobalNodes(ctx, state)
|
|
@@ -90,7 +90,7 @@ export const getContextByState = (ctx: Ctx, state: EditorState): InlineSyncConte
|
|
|
90
90
|
|
|
91
91
|
const newNode = getNewNode(ctx, text)
|
|
92
92
|
|
|
93
|
-
if (!newNode || node.type !== newNode.type)
|
|
93
|
+
if (!newNode || node.type !== newNode.type || onlyHTML(newNode))
|
|
94
94
|
return null
|
|
95
95
|
|
|
96
96
|
// @ts-expect-error hijack the node attribute
|
|
@@ -33,11 +33,17 @@ function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Nod
|
|
|
33
33
|
|
|
34
34
|
/// @internal
|
|
35
35
|
/// This plugin should be deprecated after we support HTML.
|
|
36
|
-
export const
|
|
37
|
-
flatMapWithDepth(tree, (node) => {
|
|
36
|
+
export const remarkHtmlTransformer = $remark(() => () => (tree: Node) => {
|
|
37
|
+
flatMapWithDepth(tree, (node, _index, parent) => {
|
|
38
38
|
if (!isHTML(node))
|
|
39
39
|
return [node]
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
if (parent?.type === 'root') {
|
|
42
|
+
(node as Literal & { children: Literal[] }).children = [{ ...node }]
|
|
43
|
+
delete (node as Literal).value
|
|
44
|
+
node.type = 'paragraph'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return [node]
|
|
42
48
|
})
|
|
43
49
|
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remark-html-filter.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-html-filter.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,gBAAgB,mCAO3B,CAAA"}
|