@milkdown/preset-commonmark 4.12.0 → 4.13.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.
@@ -0,0 +1,39 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { Literal, Node, Parent } from 'unist';
3
+
4
+ const isParent = (node: Node): node is Parent => !!(node as Parent).children;
5
+ const isHTML = (node: Node): node is Literal<string> => node.type === 'html';
6
+
7
+ function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
8
+ return transform(ast, 0, null)[0];
9
+
10
+ function transform(node: Node, index: number, parent: Node | null) {
11
+ if (isParent(node)) {
12
+ const out = [];
13
+ for (let i = 0, n = node.children.length; i < n; i++) {
14
+ const xs = transform(node.children[i], i, node);
15
+ if (xs) {
16
+ for (let j = 0, m = xs.length; j < m; j++) {
17
+ out.push(xs[j]);
18
+ }
19
+ }
20
+ }
21
+ node.children = out;
22
+ }
23
+
24
+ return fn(node, index, parent);
25
+ }
26
+ }
27
+
28
+ export const filterHTMLPlugin = () => {
29
+ function transformer(tree: Node) {
30
+ flatMapWithDepth(tree, (node) => {
31
+ if (!isHTML(node)) {
32
+ return [node];
33
+ }
34
+
35
+ return [];
36
+ });
37
+ }
38
+ return transformer;
39
+ };
@@ -0,0 +1,7 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { remarkPluginFactory } from '@milkdown/core';
3
+ import links from 'remark-inline-links';
4
+
5
+ import { filterHTMLPlugin } from './filter-html';
6
+
7
+ export const commonmarkPlugins = [remarkPluginFactory([links, filterHTMLPlugin])];
@@ -0,0 +1,23 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
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
+ Text: 'Text',
15
+ CodeInline: 'CodeInline',
16
+ Em: 'Em',
17
+ Bold: 'Bold',
18
+ NextListItem: 'NextListItem',
19
+ SinkListItem: 'SinkListItem',
20
+ LiftListItem: 'LiftListItem',
21
+ } as const;
22
+
23
+ export type SupportedKeys = typeof SupportedKeys;
package/src/types.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ declare module 'remark-inline-links' {
3
+ let a: never;
4
+ export = a;
5
+ }