@milkdown/preset-commonmark 4.14.2 → 5.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.d.ts +5 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/mark/code-inline.d.ts +5 -1
- package/lib/mark/code-inline.d.ts.map +1 -1
- package/lib/mark/code-inline.js +16 -16
- package/lib/mark/code-inline.js.map +1 -1
- package/lib/mark/em.d.ts +5 -1
- package/lib/mark/em.d.ts.map +1 -1
- package/lib/mark/em.js +15 -15
- package/lib/mark/em.js.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 +5 -1
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/link.js +23 -23
- package/lib/mark/link.js.map +1 -1
- package/lib/mark/strong.d.ts +5 -1
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/mark/strong.js +15 -15
- package/lib/mark/strong.js.map +1 -1
- package/lib/node/blockquote.d.ts +5 -1
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/blockquote.js +13 -13
- package/lib/node/blockquote.js.map +1 -1
- package/lib/node/bullet-list.d.ts +5 -1
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/bullet-list.js +14 -14
- package/lib/node/bullet-list.js.map +1 -1
- package/lib/node/code-fence.d.ts +6 -2
- package/lib/node/code-fence.d.ts.map +1 -1
- package/lib/node/code-fence.js +22 -20
- package/lib/node/code-fence.js.map +1 -1
- package/lib/node/doc.d.ts +5 -1
- package/lib/node/doc.d.ts.map +1 -1
- package/lib/node/doc.js +21 -19
- package/lib/node/doc.js.map +1 -1
- package/lib/node/hardbreak.d.ts +5 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/hardbreak.js +50 -31
- package/lib/node/hardbreak.js.map +1 -1
- package/lib/node/heading.d.ts +5 -1
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/heading.js +20 -20
- package/lib/node/heading.js.map +1 -1
- package/lib/node/hr.d.ts +5 -1
- package/lib/node/hr.d.ts.map +1 -1
- package/lib/node/hr.js +19 -19
- package/lib/node/hr.js.map +1 -1
- package/lib/node/image.d.ts +5 -1
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/image.js +32 -32
- package/lib/node/image.js.map +1 -1
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/list-item.d.ts +5 -1
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/list-item.js +17 -17
- package/lib/node/list-item.js.map +1 -1
- package/lib/node/ordered-list.d.ts +5 -1
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/ordered-list.js +15 -15
- package/lib/node/ordered-list.js.map +1 -1
- package/lib/node/paragraph.d.ts +5 -1
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/node/paragraph.js +22 -22
- package/lib/node/paragraph.js.map +1 -1
- package/lib/node/text.d.ts +5 -1
- package/lib/node/text.d.ts.map +1 -1
- package/lib/node/text.js +12 -12
- package/lib/node/text.js.map +1 -1
- package/lib/plugin/index.d.ts +1 -1
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/plugin/index.js +6 -2
- package/lib/plugin/index.js.map +1 -1
- package/package.json +3 -3
- package/src/mark/code-inline.ts +16 -16
- package/src/mark/em.ts +15 -15
- package/src/mark/link.ts +23 -23
- package/src/mark/strong.ts +15 -15
- package/src/node/blockquote.ts +13 -13
- package/src/node/bullet-list.ts +14 -14
- package/src/node/code-fence.ts +21 -19
- package/src/node/doc.ts +21 -19
- package/src/node/hardbreak.ts +48 -32
- package/src/node/heading.ts +21 -21
- package/src/node/hr.ts +19 -19
- package/src/node/image.ts +32 -32
- package/src/node/list-item.ts +17 -17
- package/src/node/ordered-list.ts +15 -15
- package/src/node/paragraph.ts +21 -21
- package/src/node/text.ts +12 -12
- package/src/plugin/index.ts +6 -2
package/src/node/image.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type ImageOptions = {
|
|
|
16
16
|
failed: string;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export const image = createNode<string, ImageOptions>((
|
|
19
|
+
export const image = createNode<string, ImageOptions>((utils, options) => {
|
|
20
20
|
const placeholder = {
|
|
21
21
|
loading: 'Loading...',
|
|
22
22
|
empty: 'Add an Image',
|
|
@@ -123,8 +123,8 @@ export const image = createNode<string, ImageOptions>((options, utils) => {
|
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
return {
|
|
126
|
-
id,
|
|
127
|
-
schema: {
|
|
126
|
+
id: 'image',
|
|
127
|
+
schema: () => ({
|
|
128
128
|
inline: true,
|
|
129
129
|
group: 'inline',
|
|
130
130
|
draggable: true,
|
|
@@ -173,35 +173,35 @@ export const image = createNode<string, ImageOptions>((options, utils) => {
|
|
|
173
173
|
},
|
|
174
174
|
];
|
|
175
175
|
},
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
176
|
+
parseMarkdown: {
|
|
177
|
+
match: ({ type }) => type === id,
|
|
178
|
+
runner: (state, node, type) => {
|
|
179
|
+
const url = node.url as string;
|
|
180
|
+
const alt = node.alt as string;
|
|
181
|
+
const title = node.title as string;
|
|
182
|
+
state.addNode(type, {
|
|
183
|
+
src: url,
|
|
184
|
+
alt,
|
|
185
|
+
title,
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
188
|
},
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
189
|
+
toMarkdown: {
|
|
190
|
+
match: (node) => node.type.name === id,
|
|
191
|
+
runner: (state, node) => {
|
|
192
|
+
state.addNode('image', undefined, undefined, {
|
|
193
|
+
title: node.attrs.title,
|
|
194
|
+
url: node.attrs.src,
|
|
195
|
+
alt: node.attrs.alt,
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
198
|
},
|
|
199
|
-
},
|
|
200
|
-
commands: (
|
|
199
|
+
}),
|
|
200
|
+
commands: (type) => [
|
|
201
201
|
createCmd(InsertImage, (src = '') => (state, dispatch) => {
|
|
202
202
|
if (!dispatch) return true;
|
|
203
203
|
const { tr } = state;
|
|
204
|
-
const node =
|
|
204
|
+
const node = type.create({ src });
|
|
205
205
|
if (!node) {
|
|
206
206
|
return true;
|
|
207
207
|
}
|
|
@@ -210,7 +210,7 @@ export const image = createNode<string, ImageOptions>((options, utils) => {
|
|
|
210
210
|
return true;
|
|
211
211
|
}),
|
|
212
212
|
createCmd(ModifyImage, (src = '') => (state, dispatch) => {
|
|
213
|
-
const node = findSelectedNodeOfType(state.selection,
|
|
213
|
+
const node = findSelectedNodeOfType(state.selection, type);
|
|
214
214
|
if (!node) return false;
|
|
215
215
|
|
|
216
216
|
const { tr } = state;
|
|
@@ -221,23 +221,23 @@ export const image = createNode<string, ImageOptions>((options, utils) => {
|
|
|
221
221
|
return true;
|
|
222
222
|
}),
|
|
223
223
|
],
|
|
224
|
-
inputRules: (
|
|
224
|
+
inputRules: (type) => [
|
|
225
225
|
new InputRule(
|
|
226
226
|
/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
|
|
227
227
|
(state, match, start, end) => {
|
|
228
228
|
const [okay, alt, src = '', title] = match;
|
|
229
229
|
const { tr } = state;
|
|
230
230
|
if (okay) {
|
|
231
|
-
tr.replaceWith(start, end,
|
|
231
|
+
tr.replaceWith(start, end, type.create({ src, alt, title }));
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
return tr;
|
|
235
235
|
},
|
|
236
236
|
),
|
|
237
237
|
],
|
|
238
|
-
view: (node, view, getPos) => {
|
|
238
|
+
view: (ctx) => (node, view, getPos) => {
|
|
239
239
|
const nodeType = node.type;
|
|
240
|
-
const createIcon =
|
|
240
|
+
const createIcon = ctx.get(themeToolCtx).slots.icon;
|
|
241
241
|
const container = document.createElement('span');
|
|
242
242
|
container.className = utils.getClassName(node.attrs, id, containerStyle);
|
|
243
243
|
container.contentEditable = 'false';
|
package/src/node/list-item.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const SplitListItem = createCmdKey();
|
|
|
15
15
|
export const SinkListItem = createCmdKey();
|
|
16
16
|
export const LiftListItem = createCmdKey();
|
|
17
17
|
|
|
18
|
-
export const listItem = createNode<Keys>((
|
|
18
|
+
export const listItem = createNode<Keys>((utils) => {
|
|
19
19
|
const style = utils.getStyle(
|
|
20
20
|
(themeTool) =>
|
|
21
21
|
css`
|
|
@@ -35,29 +35,29 @@ export const listItem = createNode<Keys>((_, utils) => {
|
|
|
35
35
|
|
|
36
36
|
return {
|
|
37
37
|
id,
|
|
38
|
-
schema: {
|
|
38
|
+
schema: () => ({
|
|
39
39
|
group: 'listItem',
|
|
40
40
|
content: 'paragraph block*',
|
|
41
41
|
defining: true,
|
|
42
42
|
parseDOM: [{ tag: 'li' }],
|
|
43
43
|
toDOM: (node) => ['li', { class: utils.getClassName(node.attrs, 'list-item', style) }, 0],
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
parseMarkdown: {
|
|
45
|
+
match: ({ type, checked }) => type === 'listItem' && checked === null,
|
|
46
|
+
runner: (state, node, type) => {
|
|
47
|
+
state.openNode(type);
|
|
48
|
+
state.next(node.children);
|
|
49
|
+
state.closeNode();
|
|
50
|
+
},
|
|
51
51
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
toMarkdown: {
|
|
53
|
+
match: (node) => node.type.name === id,
|
|
54
|
+
runner: (state, node) => {
|
|
55
|
+
state.openNode('listItem');
|
|
56
|
+
state.next(node.content);
|
|
57
|
+
state.closeNode();
|
|
58
|
+
},
|
|
59
59
|
},
|
|
60
|
-
},
|
|
60
|
+
}),
|
|
61
61
|
inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
|
|
62
62
|
commands: (nodeType) => [
|
|
63
63
|
createCmd(SplitListItem, () => splitListItem(nodeType)),
|
package/src/node/ordered-list.ts
CHANGED
|
@@ -10,9 +10,9 @@ type Keys = SupportedKeys['OrderedList'];
|
|
|
10
10
|
export const WrapInOrderedList = createCmdKey();
|
|
11
11
|
|
|
12
12
|
const id = 'ordered_list';
|
|
13
|
-
export const orderedList = createNode<Keys>((
|
|
13
|
+
export const orderedList = createNode<Keys>((utils) => ({
|
|
14
14
|
id,
|
|
15
|
-
schema: {
|
|
15
|
+
schema: () => ({
|
|
16
16
|
content: 'listItem+',
|
|
17
17
|
group: 'block',
|
|
18
18
|
attrs: {
|
|
@@ -39,21 +39,21 @@ export const orderedList = createNode<Keys>((_, utils) => ({
|
|
|
39
39
|
},
|
|
40
40
|
0,
|
|
41
41
|
],
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
parseMarkdown: {
|
|
43
|
+
match: ({ type, ordered }) => type === 'list' && !!ordered,
|
|
44
|
+
runner: (state, node, type) => {
|
|
45
|
+
state.openNode(type).next(node.children).closeNode();
|
|
46
|
+
},
|
|
47
47
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
toMarkdown: {
|
|
49
|
+
match: (node) => node.type.name === id,
|
|
50
|
+
runner: (state, node) => {
|
|
51
|
+
state.openNode('list', undefined, { ordered: true, start: 1 });
|
|
52
|
+
state.next(node.content);
|
|
53
|
+
state.closeNode();
|
|
54
|
+
},
|
|
55
55
|
},
|
|
56
|
-
},
|
|
56
|
+
}),
|
|
57
57
|
inputRules: (nodeType) => [
|
|
58
58
|
wrappingInputRule(
|
|
59
59
|
/^(\d+)\.\s$/,
|
package/src/node/paragraph.ts
CHANGED
|
@@ -11,7 +11,7 @@ type Keys = SupportedKeys['Text'];
|
|
|
11
11
|
export const TurnIntoText = createCmdKey();
|
|
12
12
|
|
|
13
13
|
const id = 'paragraph';
|
|
14
|
-
export const paragraph = createNode<Keys>((
|
|
14
|
+
export const paragraph = createNode<Keys>((utils, options) => {
|
|
15
15
|
const style = options?.headless
|
|
16
16
|
? null
|
|
17
17
|
: css`
|
|
@@ -22,32 +22,32 @@ export const paragraph = createNode<Keys>((options, utils) => {
|
|
|
22
22
|
|
|
23
23
|
return {
|
|
24
24
|
id,
|
|
25
|
-
schema: {
|
|
25
|
+
schema: () => ({
|
|
26
26
|
content: 'inline*',
|
|
27
27
|
group: 'block',
|
|
28
28
|
parseDOM: [{ tag: 'p' }],
|
|
29
29
|
toDOM: (node) => ['p', { class: utils.getClassName(node.attrs, id, style) }, 0],
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
parseMarkdown: {
|
|
31
|
+
match: (node) => node.type === 'paragraph',
|
|
32
|
+
runner: (state, node, type) => {
|
|
33
|
+
state.openNode(type);
|
|
34
|
+
if (node.children) {
|
|
35
|
+
state.next(node.children);
|
|
36
|
+
} else {
|
|
37
|
+
state.addText(node.value as string);
|
|
38
|
+
}
|
|
39
|
+
state.closeNode();
|
|
40
|
+
},
|
|
41
41
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
toMarkdown: {
|
|
43
|
+
match: (node) => node.type.name === 'paragraph',
|
|
44
|
+
runner: (state, node) => {
|
|
45
|
+
state.openNode('paragraph');
|
|
46
|
+
state.next(node.content);
|
|
47
|
+
state.closeNode();
|
|
48
|
+
},
|
|
49
49
|
},
|
|
50
|
-
},
|
|
50
|
+
}),
|
|
51
51
|
commands: (nodeType) => [createCmd(TurnIntoText, () => setBlockType(nodeType))],
|
|
52
52
|
shortcuts: {
|
|
53
53
|
[SupportedKeys.Text]: createShortcut(TurnIntoText, 'Mod-Alt-0'),
|
package/src/node/text.ts
CHANGED
|
@@ -3,19 +3,19 @@ import { createNode } from '@milkdown/utils';
|
|
|
3
3
|
|
|
4
4
|
export const text = createNode(() => ({
|
|
5
5
|
id: 'text',
|
|
6
|
-
schema: {
|
|
6
|
+
schema: () => ({
|
|
7
7
|
group: 'inline',
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
parseMarkdown: {
|
|
9
|
+
match: ({ type }) => type === 'text',
|
|
10
|
+
runner: (state, node) => {
|
|
11
|
+
state.addText(node.value as string);
|
|
12
|
+
},
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
toMarkdown: {
|
|
15
|
+
match: (node) => node.type.name === 'text',
|
|
16
|
+
runner: (state, node) => {
|
|
17
|
+
state.addNode('text', undefined, node.text as string);
|
|
18
|
+
},
|
|
19
19
|
},
|
|
20
|
-
},
|
|
20
|
+
}),
|
|
21
21
|
}));
|
package/src/plugin/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import {
|
|
2
|
+
import { createPlugin } from '@milkdown/utils';
|
|
3
3
|
import links from 'remark-inline-links';
|
|
4
4
|
|
|
5
5
|
import { filterHTMLPlugin } from './filter-html';
|
|
6
6
|
|
|
7
|
-
export const commonmarkPlugins = [
|
|
7
|
+
export const commonmarkPlugins = [
|
|
8
|
+
createPlugin(() => ({
|
|
9
|
+
remarkPlugins: () => [links, filterHTMLPlugin],
|
|
10
|
+
}))(),
|
|
11
|
+
];
|