@milkdown/preset-commonmark 6.1.4 → 6.3.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/index.d.ts +2 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +1012 -1065
- package/lib/index.es.js.map +1 -1
- package/lib/mark/code-inline.d.ts +1 -5
- package/lib/mark/code-inline.d.ts.map +1 -1
- package/lib/mark/em.d.ts +1 -5
- package/lib/mark/em.d.ts.map +1 -1
- package/lib/mark/index.d.ts +1 -1
- package/lib/mark/index.d.ts.map +1 -1
- package/lib/mark/link.d.ts +1 -5
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +1 -5
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts +1 -5
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts +1 -5
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-fence.d.ts +1 -5
- package/lib/node/code-fence.d.ts.map +1 -1
- package/lib/node/doc.d.ts +1 -5
- package/lib/node/doc.d.ts.map +1 -1
- package/lib/node/hardbreak.d.ts +1 -5
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts +8 -6
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/hr.d.ts +1 -5
- package/lib/node/hr.d.ts.map +1 -1
- package/lib/node/image.d.ts +1 -5
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/index.d.ts +2 -3
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/list-item.d.ts +1 -5
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts +1 -5
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts +1 -5
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/node/text.d.ts +1 -5
- package/lib/node/text.d.ts.map +1 -1
- package/lib/plugin/add-order-in-list.d.ts +3 -0
- package/lib/plugin/add-order-in-list.d.ts.map +1 -0
- package/lib/plugin/index.d.ts +1 -1
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -0
- package/lib/supported-keys.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/mark/link.ts +55 -9
- package/src/node/code-fence.ts +7 -6
- package/src/node/hardbreak.ts +16 -2
- package/src/node/heading.ts +264 -117
- package/src/node/hr.ts +4 -2
- package/src/node/image.ts +4 -3
- package/src/node/index.ts +3 -1
- package/src/node/list-item.ts +93 -3
- package/src/node/ordered-list.ts +2 -1
- package/src/node/paragraph.ts +12 -2
- package/src/plugin/add-order-in-list.ts +19 -0
- package/src/plugin/index.ts +2 -1
- package/src/plugin/inline-nodes-cursor.ts +1 -1
- package/src/supported-keys.ts +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Node } from 'unist';
|
|
3
|
+
import { Parent, visit } from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
export const addOrderInList = () => {
|
|
6
|
+
function transformer(ast: Node) {
|
|
7
|
+
visit(ast, 'list', (node: Parent & { ordered?: boolean; start?: number }) => {
|
|
8
|
+
if (node.ordered) {
|
|
9
|
+
const start = node.start ?? 1;
|
|
10
|
+
node.children.forEach((child, index) => {
|
|
11
|
+
(child as Node & { label: number }).label = index + start;
|
|
12
|
+
});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return transformer;
|
|
19
|
+
};
|
package/src/plugin/index.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { createPlugin } from '@milkdown/utils';
|
|
3
3
|
import links from 'remark-inline-links';
|
|
4
4
|
|
|
5
|
+
import { addOrderInList } from './add-order-in-list';
|
|
5
6
|
import { filterHTMLPlugin } from './filter-html';
|
|
6
7
|
import { inlineNodesCursorPlugin } from './inline-nodes-cursor';
|
|
7
8
|
|
|
8
9
|
export const commonmarkPlugins = [
|
|
9
10
|
createPlugin(() => ({
|
|
10
11
|
prosePlugins: () => [inlineNodesCursorPlugin],
|
|
11
|
-
remarkPlugins: () => [links, filterHTMLPlugin],
|
|
12
|
+
remarkPlugins: () => [links, filterHTMLPlugin, addOrderInList],
|
|
12
13
|
}))(),
|
|
13
14
|
];
|
|
@@ -32,7 +32,7 @@ export const inlineNodesCursorPlugin: Plugin = new Plugin({
|
|
|
32
32
|
handleDOMEvents: {
|
|
33
33
|
beforeinput: (view, e) => {
|
|
34
34
|
const active = inlineNodesCursorPlugin.getState(view.state);
|
|
35
|
-
if (active) {
|
|
35
|
+
if (active && e instanceof InputEvent) {
|
|
36
36
|
const from = view.state.selection.from;
|
|
37
37
|
e.preventDefault();
|
|
38
38
|
view.dispatch(view.state.tr.insertText(e.data || '', from));
|