@milkdown/preset-commonmark 7.0.0-next.4 → 7.0.0-next.6
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/index.es.js +160 -134
- package/lib/index.es.js.map +1 -1
- package/lib/plugin/index.d.ts +1 -0
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/plugin/remark-html-filter.d.ts +2 -0
- package/lib/plugin/remark-html-filter.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/composed/plugins.ts +2 -1
- package/src/plugin/index.ts +1 -0
- package/src/plugin/remark-html-filter.ts +43 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-next.
|
|
4
|
+
"version": "7.0.0-next.6",
|
|
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.0-next.
|
|
34
|
-
"@milkdown/utils": "7.0.0-next.
|
|
33
|
+
"@milkdown/exception": "7.0.0-next.6",
|
|
34
|
+
"@milkdown/utils": "7.0.0-next.6"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/unist": "^2.0.6",
|
|
38
|
-
"@milkdown/core": "7.0.0-next.
|
|
39
|
-
"@milkdown/ctx": "7.0.0-next.
|
|
40
|
-
"@milkdown/prose": "7.0.0-next.
|
|
38
|
+
"@milkdown/core": "7.0.0-next.6",
|
|
39
|
+
"@milkdown/ctx": "7.0.0-next.6",
|
|
40
|
+
"@milkdown/prose": "7.0.0-next.6"
|
|
41
41
|
},
|
|
42
42
|
"nx": {
|
|
43
43
|
"targets": {
|
package/src/composed/plugins.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
3
|
import type { MilkdownPlugin } from '@milkdown/ctx'
|
|
4
|
-
import { hardbreakClearMarkPlugin, hardbreakFilterNodes, hardbreakFilterPlugin, inlineNodesCursorPlugin, inlineSyncConfig, inlineSyncPlugin, remarkAddOrderInListPlugin, remarkInlineLinkPlugin, remarkLineBreak, syncHeadingIdPlugin, syncListOrderPlugin } from '../plugin'
|
|
4
|
+
import { hardbreakClearMarkPlugin, hardbreakFilterNodes, hardbreakFilterPlugin, inlineNodesCursorPlugin, inlineSyncConfig, inlineSyncPlugin, remarkAddOrderInListPlugin, remarkHTMLFilter, remarkInlineLinkPlugin, remarkLineBreak, syncHeadingIdPlugin, syncListOrderPlugin } from '../plugin'
|
|
5
5
|
|
|
6
6
|
/// @internal
|
|
7
7
|
export const plugins: MilkdownPlugin[] = [
|
|
@@ -17,6 +17,7 @@ export const plugins: MilkdownPlugin[] = [
|
|
|
17
17
|
remarkAddOrderInListPlugin,
|
|
18
18
|
remarkInlineLinkPlugin,
|
|
19
19
|
remarkLineBreak,
|
|
20
|
+
remarkHTMLFilter,
|
|
20
21
|
|
|
21
22
|
syncHeadingIdPlugin,
|
|
22
23
|
syncListOrderPlugin,
|
package/src/plugin/index.ts
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { $remark } from '@milkdown/utils'
|
|
3
|
+
import type { Literal, Node, Parent } from 'unist'
|
|
4
|
+
|
|
5
|
+
const isParent = (node: Node): node is Parent => !!(node as Parent).children
|
|
6
|
+
const isHTML = (node: Node): node is Literal<string> => node.type === 'html'
|
|
7
|
+
|
|
8
|
+
function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
|
|
9
|
+
return transform(ast, 0, null)[0]
|
|
10
|
+
|
|
11
|
+
function transform(node: Node, index: number, parent: Node | null) {
|
|
12
|
+
if (isParent(node)) {
|
|
13
|
+
const out = []
|
|
14
|
+
for (let i = 0, n = node.children.length; i < n; i++) {
|
|
15
|
+
const nthChild = node.children[i]
|
|
16
|
+
if (nthChild) {
|
|
17
|
+
const xs = transform(nthChild, i, node)
|
|
18
|
+
if (xs) {
|
|
19
|
+
for (let j = 0, m = xs.length; j < m; j++) {
|
|
20
|
+
const item = xs[j]
|
|
21
|
+
if (item)
|
|
22
|
+
out.push(item)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
node.children = out
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return fn(node, index, parent)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// @internal
|
|
35
|
+
/// This plugin should be deprecated after we support HTML.
|
|
36
|
+
export const remarkHTMLFilter = $remark(() => () => (tree: Node) => {
|
|
37
|
+
flatMapWithDepth(tree, (node) => {
|
|
38
|
+
if (!isHTML(node))
|
|
39
|
+
return [node]
|
|
40
|
+
|
|
41
|
+
return []
|
|
42
|
+
})
|
|
43
|
+
})
|