@milkdown/preset-commonmark 6.5.4 → 7.0.0-next.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/composed/commands.d.ts +3 -0
- package/lib/composed/commands.d.ts.map +1 -0
- package/lib/composed/index.d.ts +6 -0
- package/lib/composed/index.d.ts.map +1 -0
- package/lib/composed/inputrules.d.ts +3 -0
- package/lib/composed/inputrules.d.ts.map +1 -0
- package/lib/composed/keymap.d.ts +3 -0
- package/lib/composed/keymap.d.ts.map +1 -0
- package/lib/composed/plugins.d.ts +3 -0
- package/lib/composed/plugins.d.ts.map +1 -0
- package/lib/composed/schema.d.ts +3 -0
- package/lib/composed/schema.d.ts.map +1 -0
- package/lib/index.d.ts +4 -29
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +1099 -1386
- package/lib/index.es.js.map +1 -1
- package/lib/mark/emphasis.d.ts +5 -0
- package/lib/mark/emphasis.d.ts.map +1 -0
- package/lib/mark/index.d.ts +3 -4
- package/lib/mark/index.d.ts.map +1 -1
- package/lib/mark/inline-code.d.ts +5 -0
- package/lib/mark/inline-code.d.ts.map +1 -0
- package/lib/mark/link.d.ts +8 -10
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +4 -2
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts +6 -2
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts +5 -2
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-block.d.ts +10 -0
- package/lib/node/code-block.d.ts.map +1 -0
- package/lib/node/doc.d.ts +1 -1
- package/lib/node/doc.d.ts.map +1 -1
- package/lib/node/hardbreak.d.ts +4 -6
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/node/heading.d.ts +7 -12
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/hr.d.ts +4 -2
- package/lib/node/hr.d.ts.map +1 -1
- package/lib/node/image.d.ts +10 -11
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/index.d.ts +6 -8
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/list-item.d.ts +6 -7
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts +5 -2
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts +4 -2
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/node/text.d.ts +1 -1
- package/lib/node/text.d.ts.map +1 -1
- package/lib/plugin/hardbreak-clear-mark-plugin.d.ts +2 -0
- package/lib/plugin/hardbreak-clear-mark-plugin.d.ts.map +1 -0
- package/lib/plugin/hardbreak-filter-plugin.d.ts +3 -0
- package/lib/plugin/hardbreak-filter-plugin.d.ts.map +1 -0
- package/lib/plugin/index.d.ts +9 -3
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/plugin/inline-nodes-cursor-plugin.d.ts +2 -0
- package/lib/plugin/inline-nodes-cursor-plugin.d.ts.map +1 -0
- package/lib/plugin/{inline-sync → inline-sync-plugin}/config.d.ts +2 -2
- package/lib/plugin/inline-sync-plugin/config.d.ts.map +1 -0
- package/lib/plugin/{inline-sync → inline-sync-plugin}/context.d.ts +1 -2
- package/lib/plugin/inline-sync-plugin/context.d.ts.map +1 -0
- package/lib/plugin/inline-sync-plugin/index.d.ts +3 -0
- package/lib/plugin/inline-sync-plugin/index.d.ts.map +1 -0
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts +2 -0
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -0
- package/lib/plugin/{inline-sync → inline-sync-plugin}/regexp.d.ts +0 -0
- package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -0
- package/lib/plugin/{inline-sync → inline-sync-plugin}/replacer.d.ts +1 -1
- package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -0
- package/lib/plugin/{inline-sync → inline-sync-plugin}/utils.d.ts +0 -0
- package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -0
- package/lib/plugin/remark-add-order-in-list-plugin.d.ts +2 -0
- package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -0
- package/lib/plugin/remark-inline-link-plugin.d.ts +2 -0
- package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -0
- package/lib/plugin/remark-line-break.d.ts +2 -0
- package/lib/plugin/remark-line-break.d.ts.map +1 -0
- package/lib/plugin/sync-heading-id-plugin.d.ts +2 -0
- package/lib/plugin/sync-heading-id-plugin.d.ts.map +1 -0
- package/lib/plugin/sync-list-order-plugin.d.ts +2 -0
- package/lib/plugin/sync-list-order-plugin.d.ts.map +1 -0
- package/package.json +9 -7
- package/src/composed/commands.ts +31 -0
- package/src/composed/index.ts +6 -0
- package/src/composed/inputrules.ts +13 -0
- package/src/composed/keymap.ts +20 -0
- package/src/composed/plugins.ts +23 -0
- package/src/composed/schema.ts +55 -0
- package/src/index.ts +6 -52
- package/src/mark/emphasis.ts +47 -0
- package/src/mark/index.ts +3 -10
- package/src/mark/inline-code.ts +70 -0
- package/src/mark/link.ts +96 -247
- package/src/mark/strong.ts +41 -36
- package/src/node/blockquote.ts +39 -33
- package/src/node/bullet-list.ts +62 -55
- package/src/node/code-block.ts +103 -0
- package/src/node/doc.ts +18 -22
- package/src/node/hardbreak.ts +68 -117
- package/src/node/heading.ts +175 -284
- package/src/node/hr.ts +57 -57
- package/src/node/image.ts +113 -209
- package/src/node/index.ts +6 -35
- package/src/node/list-item.ts +125 -141
- package/src/node/ordered-list.ts +70 -65
- package/src/node/paragraph.ts +54 -50
- package/src/node/text.ts +14 -16
- package/src/plugin/hardbreak-clear-mark-plugin.ts +45 -0
- package/src/plugin/hardbreak-filter-plugin.ts +33 -0
- package/src/plugin/index.ts +12 -14
- package/src/plugin/{inline-nodes-cursor.ts → inline-nodes-cursor-plugin.ts} +5 -8
- package/src/plugin/{inline-sync → inline-sync-plugin}/config.ts +18 -3
- package/src/plugin/{inline-sync → inline-sync-plugin}/context.ts +4 -6
- package/src/plugin/inline-sync-plugin/index.ts +4 -0
- package/src/plugin/{inline-sync/index.ts → inline-sync-plugin/inline-sync-plugin.ts} +14 -11
- package/src/plugin/{inline-sync → inline-sync-plugin}/regexp.ts +0 -0
- package/src/plugin/{inline-sync → inline-sync-plugin}/replacer.ts +3 -3
- package/src/plugin/{inline-sync → inline-sync-plugin}/utils.ts +0 -0
- package/src/plugin/remark-add-order-in-list-plugin.ts +16 -0
- package/src/plugin/remark-inline-link-plugin.ts +6 -0
- package/src/plugin/remark-line-break.ts +44 -0
- package/src/plugin/sync-heading-id-plugin.ts +55 -0
- package/src/plugin/sync-list-order-plugin.ts +57 -0
- package/lib/mark/code-inline.d.ts +0 -3
- package/lib/mark/code-inline.d.ts.map +0 -1
- package/lib/mark/em.d.ts +0 -3
- package/lib/mark/em.d.ts.map +0 -1
- package/lib/node/code-fence.d.ts +0 -7
- package/lib/node/code-fence.d.ts.map +0 -1
- package/lib/plugin/add-order-in-list.d.ts +0 -3
- package/lib/plugin/add-order-in-list.d.ts.map +0 -1
- package/lib/plugin/filter-html.d.ts +0 -3
- package/lib/plugin/filter-html.d.ts.map +0 -1
- package/lib/plugin/inline-nodes-cursor.d.ts +0 -7
- package/lib/plugin/inline-nodes-cursor.d.ts.map +0 -1
- package/lib/plugin/inline-sync/config.d.ts.map +0 -1
- package/lib/plugin/inline-sync/context.d.ts.map +0 -1
- package/lib/plugin/inline-sync/index.d.ts +0 -6
- package/lib/plugin/inline-sync/index.d.ts.map +0 -1
- package/lib/plugin/inline-sync/regexp.d.ts.map +0 -1
- package/lib/plugin/inline-sync/replacer.d.ts.map +0 -1
- package/lib/plugin/inline-sync/utils.d.ts.map +0 -1
- package/lib/supported-keys.d.ts +0 -23
- package/lib/supported-keys.d.ts.map +0 -1
- package/src/mark/code-inline.ts +0 -66
- package/src/mark/em.ts +0 -42
- package/src/node/code-fence.ts +0 -245
- package/src/plugin/add-order-in-list.ts +0 -19
- package/src/plugin/filter-html.ts +0 -43
- package/src/supported-keys.ts +0 -25
- package/src/types.d.ts +0 -5
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { $remark } from '@milkdown/utils'
|
|
3
|
+
import type { Literal, Node, Parent } from 'unist'
|
|
4
|
+
import { visit } from 'unist-util-visit'
|
|
5
|
+
|
|
6
|
+
/// This plugin is used to add inline line break for remark AST.
|
|
7
|
+
/// The inline line break should be treated as a `space`.
|
|
8
|
+
/// And the normal line break should be treated as a `LF`.
|
|
9
|
+
export const remarkLineBreak = $remark(() => () => (tree: Node) => {
|
|
10
|
+
const find = /[\t ]*(?:\r?\n|\r)/g
|
|
11
|
+
visit(tree, 'text', (node: Literal, index: number, parent: Parent) => {
|
|
12
|
+
if (!node.value || typeof node.value !== 'string')
|
|
13
|
+
return
|
|
14
|
+
|
|
15
|
+
const result = []
|
|
16
|
+
let start = 0
|
|
17
|
+
|
|
18
|
+
find.lastIndex = 0
|
|
19
|
+
|
|
20
|
+
let match = find.exec(node.value)
|
|
21
|
+
|
|
22
|
+
while (match) {
|
|
23
|
+
const position = match.index
|
|
24
|
+
|
|
25
|
+
if (start !== position)
|
|
26
|
+
result.push({ type: 'text', value: node.value.slice(start, position) })
|
|
27
|
+
|
|
28
|
+
result.push({ type: 'break', data: { isInline: true } })
|
|
29
|
+
start = position + match[0].length
|
|
30
|
+
match = find.exec(node.value)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const hasResultAndIndex = result.length > 0 && parent && typeof index === 'number'
|
|
34
|
+
|
|
35
|
+
if (!hasResultAndIndex)
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
if (start < node.value.length)
|
|
39
|
+
result.push({ type: 'text', value: node.value.slice(start) })
|
|
40
|
+
|
|
41
|
+
parent.children.splice(index, 1, ...result)
|
|
42
|
+
return index + result.length
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
3
|
+
import type { EditorView } from '@milkdown/prose/view'
|
|
4
|
+
import { $prose } from '@milkdown/utils'
|
|
5
|
+
import { headingIdGenerator, headingSchema } from '../node/heading'
|
|
6
|
+
|
|
7
|
+
/// This plugin is used to sync the heading id when the heading content changes.
|
|
8
|
+
/// It will use the `headingIdGenerator` to generate the id.
|
|
9
|
+
export const syncHeadingIdPlugin = $prose((ctx) => {
|
|
10
|
+
const headingIdPluginKey = new PluginKey('MILKDOWN_HEADING_ID')
|
|
11
|
+
|
|
12
|
+
const updateId = (view: EditorView) => {
|
|
13
|
+
if (view.composing || !view.editable)
|
|
14
|
+
return
|
|
15
|
+
|
|
16
|
+
const getId = ctx.get(headingIdGenerator.key)
|
|
17
|
+
const tr = view.state.tr.setMeta('addToHistory', false)
|
|
18
|
+
|
|
19
|
+
let found = false
|
|
20
|
+
|
|
21
|
+
view.state.doc.descendants((node, pos) => {
|
|
22
|
+
if (node.type === headingSchema.type()) {
|
|
23
|
+
if (node.textContent.trim().length === 0)
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
const attrs = node.attrs
|
|
27
|
+
const id = getId(node)
|
|
28
|
+
|
|
29
|
+
if (attrs.id !== id) {
|
|
30
|
+
found = true
|
|
31
|
+
tr.setMeta(headingIdPluginKey, true).setNodeMarkup(pos, undefined, {
|
|
32
|
+
...attrs,
|
|
33
|
+
id,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
if (found)
|
|
40
|
+
view.dispatch(tr)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return new Plugin({
|
|
44
|
+
key: headingIdPluginKey,
|
|
45
|
+
view: (view) => {
|
|
46
|
+
updateId(view)
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
update: (view) => {
|
|
50
|
+
updateId(view)
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { EditorState, Transaction } from '@milkdown/prose/state'
|
|
3
|
+
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
4
|
+
import { $prose } from '@milkdown/utils'
|
|
5
|
+
import { listItemSchema } from '../node/list-item'
|
|
6
|
+
|
|
7
|
+
import { orderedListSchema } from '../node/ordered-list'
|
|
8
|
+
|
|
9
|
+
/// This plugin is used to keep the label of list item up to date in ordered list.
|
|
10
|
+
export const syncListOrderPlugin = $prose(() => {
|
|
11
|
+
const walkThrough = (state: EditorState, callback: (tr: Transaction) => void) => {
|
|
12
|
+
const orderedListType = orderedListSchema.type()
|
|
13
|
+
const listItemType = listItemSchema.type()
|
|
14
|
+
let tr = state.tr
|
|
15
|
+
state.doc.descendants((node, pos, parent, index) => {
|
|
16
|
+
if (node.type === listItemType && parent?.type === orderedListType) {
|
|
17
|
+
let changed = false
|
|
18
|
+
const attrs = { ...node.attrs }
|
|
19
|
+
if (node.attrs.listType !== 'ordered') {
|
|
20
|
+
attrs.listType = 'ordered'
|
|
21
|
+
changed = true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const base = parent?.maybeChild(0)
|
|
25
|
+
if (base === node) {
|
|
26
|
+
attrs.label = '1.'
|
|
27
|
+
changed = true
|
|
28
|
+
}
|
|
29
|
+
else if (base?.type === listItemType && base.attrs.listType === 'ordered') {
|
|
30
|
+
attrs.label = `${index + 1}.`
|
|
31
|
+
changed = true
|
|
32
|
+
}
|
|
33
|
+
else if (node.attrs.label === '•') {
|
|
34
|
+
attrs.label = `${index + 1}.`
|
|
35
|
+
changed = true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (changed)
|
|
39
|
+
tr = tr.setNodeMarkup(pos, undefined, attrs)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
callback(tr)
|
|
43
|
+
}
|
|
44
|
+
return new Plugin({
|
|
45
|
+
key: new PluginKey('MILKDOWN_KEEP_LIST_ORDER'),
|
|
46
|
+
appendTransaction: (transactions, _oldState, nextState) => {
|
|
47
|
+
let tr: Transaction | null = null
|
|
48
|
+
if (transactions.some(transaction => transaction.docChanged)) {
|
|
49
|
+
walkThrough(nextState, (t) => {
|
|
50
|
+
tr = t
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return tr
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-inline.d.ts","sourceRoot":"","sources":["../../src/mark/code-inline.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB,4CAAmC,CAAA;AAEhE,eAAO,MAAM,UAAU,mDAqDrB,CAAA"}
|
package/lib/mark/em.d.ts
DELETED
package/lib/mark/em.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"em.d.ts","sourceRoot":"","sources":["../../src/mark/em.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAA+B,CAAA;AACxD,eAAO,MAAM,EAAE,mDA6BZ,CAAA"}
|
package/lib/node/code-fence.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const backtickInputRegex: RegExp;
|
|
2
|
-
export declare const tildeInputRegex: RegExp;
|
|
3
|
-
export declare const TurnIntoCodeFence: import("@milkdown/core").CmdKey<undefined>;
|
|
4
|
-
export declare const codeFence: import("@milkdown/utils").NodeCreator<"CodeFence", {
|
|
5
|
-
languageList?: string[] | undefined;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=code-fence.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-fence.d.ts","sourceRoot":"","sources":["../../src/node/code-fence.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,kBAAkB,QAAoC,CAAA;AACnE,eAAO,MAAM,eAAe,QAAoC,CAAA;AAEhE,eAAO,MAAM,iBAAiB,4CAAoC,CAAA;AAGlE,eAAO,MAAM,SAAS;;EA6MpB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-order-in-list.d.ts","sourceRoot":"","sources":["../../src/plugin/add-order-in-list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAIjC,eAAO,MAAM,cAAc,cACC,IAAI,SAY/B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-html.d.ts","sourceRoot":"","sources":["../../src/plugin/filter-html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,IAAI,EAAU,MAAM,OAAO,CAAA;AA+BlD,eAAO,MAAM,gBAAgB,eACA,IAAI,SAShC,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@milkdown/prose/state';
|
|
2
|
-
/**
|
|
3
|
-
* This plugin is to solve the chrome 98 bug:
|
|
4
|
-
* https://discuss.prosemirror.net/t/cursor-jumps-at-the-end-of-line-when-it-betweens-two-inline-nodes/4641
|
|
5
|
-
*/
|
|
6
|
-
export declare const getInlineNodesCursorPlugin: () => Plugin;
|
|
7
|
-
//# sourceMappingURL=inline-nodes-cursor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inline-nodes-cursor.d.ts","sourceRoot":"","sources":["../../src/plugin/inline-nodes-cursor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAa,MAAM,uBAAuB,CAAA;AAKzD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAO,MAkF7C,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAIxD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE;IACrC,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,GAAG,EAAE,GAAG,CAAA;IACR,EAAE,EAAE,WAAW,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,KAAK,OAAO,CAAA;AAEb,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,mBAAmB,CAAA;IACtC,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAA;IACrC,eAAe,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACrE;AAED,eAAO,MAAM,aAAa,EAAE,gBAyB3B,CAAA;AAED,eAAO,MAAM,mBAAmB,sEAAuF,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAMxD,cAAc,UAAU,CAAA;AAExB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAmED,eAAO,MAAM,iBAAiB,QAAS,GAAG,SAAS,WAAW,KAAG,iBAAiB,GAAG,IAmCpF,CAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/core';
|
|
2
|
-
import { Plugin, PluginKey } from '@milkdown/prose/state';
|
|
3
|
-
export * from './config';
|
|
4
|
-
export declare const inlineSyncPluginKey: PluginKey<any>;
|
|
5
|
-
export declare const getInlineSyncPlugin: (ctx: Ctx) => Plugin<null>;
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAMzD,cAAc,UAAU,CAAA;AAExB,eAAO,MAAM,mBAAmB,gBAAwC,CAAA;AACxE,eAAO,MAAM,mBAAmB,QAAS,GAAG,iBAkD3C,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAAyE,CAAA;AAEhG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOhF,eAAO,MAAM,WAAW,QACjB,GAAG,OACH,SAAS,SACP,WAAW,iBACH,WAAW,KAAK,IAAI,SAC5B,KAAK,SA6Bb,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAGnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACtB,CAAA;AAEtD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAkBtF,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,WAkBvE,CAAA"}
|
package/lib/supported-keys.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare const SupportedKeys: {
|
|
2
|
-
readonly HardBreak: "HardBreak";
|
|
3
|
-
readonly Blockquote: "Blockquote";
|
|
4
|
-
readonly BulletList: "BulletList";
|
|
5
|
-
readonly OrderedList: "OrderedList";
|
|
6
|
-
readonly CodeFence: "CodeFence";
|
|
7
|
-
readonly H1: "H1";
|
|
8
|
-
readonly H2: "H2";
|
|
9
|
-
readonly H3: "H3";
|
|
10
|
-
readonly H4: "H4";
|
|
11
|
-
readonly H5: "H5";
|
|
12
|
-
readonly H6: "H6";
|
|
13
|
-
readonly DowngradeHeading: "DowngradeHeading";
|
|
14
|
-
readonly Text: "Text";
|
|
15
|
-
readonly CodeInline: "CodeInline";
|
|
16
|
-
readonly Em: "Em";
|
|
17
|
-
readonly Bold: "Bold";
|
|
18
|
-
readonly NextListItem: "NextListItem";
|
|
19
|
-
readonly SinkListItem: "SinkListItem";
|
|
20
|
-
readonly LiftListItem: "LiftListItem";
|
|
21
|
-
};
|
|
22
|
-
export type SupportedKeys = typeof SupportedKeys;
|
|
23
|
-
//# sourceMappingURL=supported-keys.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supported-keys.d.ts","sourceRoot":"","sources":["../src/supported-keys.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;CAoBhB,CAAA;AAGV,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA"}
|
package/src/mark/code-inline.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
-
import type { MarkType } from '@milkdown/prose/model'
|
|
4
|
-
import { createMark, createShortcut } from '@milkdown/utils'
|
|
5
|
-
|
|
6
|
-
import { SupportedKeys } from '../supported-keys'
|
|
7
|
-
|
|
8
|
-
type Keys = SupportedKeys['CodeInline']
|
|
9
|
-
const id = 'code_inline'
|
|
10
|
-
|
|
11
|
-
export const ToggleInlineCode = createCmdKey('ToggleInlineCode')
|
|
12
|
-
|
|
13
|
-
export const codeInline = createMark<Keys>((utils) => {
|
|
14
|
-
return {
|
|
15
|
-
id,
|
|
16
|
-
schema: () => ({
|
|
17
|
-
priority: 100,
|
|
18
|
-
code: true,
|
|
19
|
-
inclusive: false,
|
|
20
|
-
parseDOM: [{ tag: 'code' }],
|
|
21
|
-
toDOM: mark => ['code', { class: utils.getClassName(mark.attrs, 'code-inline') }],
|
|
22
|
-
parseMarkdown: {
|
|
23
|
-
match: node => node.type === 'inlineCode',
|
|
24
|
-
runner: (state, node, markType) => {
|
|
25
|
-
state.openMark(markType)
|
|
26
|
-
state.addText(node.value as string)
|
|
27
|
-
state.closeMark(markType)
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
toMarkdown: {
|
|
31
|
-
match: mark => mark.type.name === id,
|
|
32
|
-
runner: (state, mark, node) => {
|
|
33
|
-
state.withMark(mark, 'inlineCode', node.text || '')
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
}),
|
|
37
|
-
commands: markType => [
|
|
38
|
-
createCmd(ToggleInlineCode, () => (state, dispatch) => {
|
|
39
|
-
const { selection, tr } = state
|
|
40
|
-
if (selection.empty)
|
|
41
|
-
return false
|
|
42
|
-
const { from, to } = selection
|
|
43
|
-
|
|
44
|
-
const has = state.doc.rangeHasMark(from, to, markType)
|
|
45
|
-
if (has) {
|
|
46
|
-
dispatch?.(tr.removeMark(from, to, markType))
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const restMarksName = Object.keys(state.schema.marks).filter(x => x !== markType.name)
|
|
51
|
-
|
|
52
|
-
restMarksName
|
|
53
|
-
.map(name => state.schema.marks[name] as MarkType)
|
|
54
|
-
.forEach((t) => {
|
|
55
|
-
tr.removeMark(from, to, t)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
dispatch?.(tr.addMark(from, to, markType.create()))
|
|
59
|
-
return true
|
|
60
|
-
}),
|
|
61
|
-
],
|
|
62
|
-
shortcuts: {
|
|
63
|
-
[SupportedKeys.CodeInline]: createShortcut(ToggleInlineCode, 'Mod-e'),
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
})
|
package/src/mark/em.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
-
import { toggleMark } from '@milkdown/prose/commands'
|
|
4
|
-
import { createMark, createShortcut } from '@milkdown/utils'
|
|
5
|
-
|
|
6
|
-
import { SupportedKeys } from '../supported-keys'
|
|
7
|
-
|
|
8
|
-
type Keys = SupportedKeys['Em']
|
|
9
|
-
|
|
10
|
-
const id = 'em'
|
|
11
|
-
|
|
12
|
-
export const ToggleItalic = createCmdKey('ToggleItalic')
|
|
13
|
-
export const em = createMark<Keys>(utils => ({
|
|
14
|
-
id,
|
|
15
|
-
schema: () => ({
|
|
16
|
-
inclusive: false,
|
|
17
|
-
parseDOM: [
|
|
18
|
-
{ tag: 'i' },
|
|
19
|
-
{ tag: 'em' },
|
|
20
|
-
{ style: 'font-style', getAttrs: value => (value === 'italic') as false },
|
|
21
|
-
],
|
|
22
|
-
toDOM: mark => ['em', { class: utils.getClassName(mark.attrs, id) }],
|
|
23
|
-
parseMarkdown: {
|
|
24
|
-
match: node => node.type === 'emphasis',
|
|
25
|
-
runner: (state, node, markType) => {
|
|
26
|
-
state.openMark(markType)
|
|
27
|
-
state.next(node.children)
|
|
28
|
-
state.closeMark(markType)
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
toMarkdown: {
|
|
32
|
-
match: mark => mark.type.name === id,
|
|
33
|
-
runner: (state, mark) => {
|
|
34
|
-
state.withMark(mark, 'emphasis')
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
commands: markType => [createCmd(ToggleItalic, () => toggleMark(markType))],
|
|
39
|
-
shortcuts: {
|
|
40
|
-
[SupportedKeys.Em]: createShortcut(ToggleItalic, 'Mod-i'),
|
|
41
|
-
},
|
|
42
|
-
}))
|
package/src/node/code-fence.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { ThemeCodeFenceType } from '@milkdown/core'
|
|
3
|
-
import { createCmd, createCmdKey, editorViewCtx } from '@milkdown/core'
|
|
4
|
-
import { expectDomTypeError } from '@milkdown/exception'
|
|
5
|
-
import { setBlockType } from '@milkdown/prose/commands'
|
|
6
|
-
import { textblockTypeInputRule } from '@milkdown/prose/inputrules'
|
|
7
|
-
import { Fragment } from '@milkdown/prose/model'
|
|
8
|
-
import type { NodeView } from '@milkdown/prose/view'
|
|
9
|
-
import { createNode, createShortcut } from '@milkdown/utils'
|
|
10
|
-
|
|
11
|
-
import { SupportedKeys } from '../supported-keys'
|
|
12
|
-
|
|
13
|
-
type Keys = SupportedKeys['CodeFence']
|
|
14
|
-
|
|
15
|
-
const languageOptions = [
|
|
16
|
-
'',
|
|
17
|
-
'javascript',
|
|
18
|
-
'typescript',
|
|
19
|
-
'bash',
|
|
20
|
-
'sql',
|
|
21
|
-
'json',
|
|
22
|
-
'html',
|
|
23
|
-
'css',
|
|
24
|
-
'c',
|
|
25
|
-
'cpp',
|
|
26
|
-
'java',
|
|
27
|
-
'ruby',
|
|
28
|
-
'python',
|
|
29
|
-
'go',
|
|
30
|
-
'rust',
|
|
31
|
-
'markdown',
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
export const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/
|
|
35
|
-
export const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/
|
|
36
|
-
|
|
37
|
-
export const TurnIntoCodeFence = createCmdKey('TurnIntoCodeFence')
|
|
38
|
-
|
|
39
|
-
const id = 'fence'
|
|
40
|
-
export const codeFence = createNode<Keys, { languageList?: string[] }>((utils, options) => {
|
|
41
|
-
const languageList = options?.languageList || languageOptions
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
id,
|
|
45
|
-
schema: ctx => ({
|
|
46
|
-
content: 'text*',
|
|
47
|
-
group: 'block',
|
|
48
|
-
marks: '',
|
|
49
|
-
defining: true,
|
|
50
|
-
code: true,
|
|
51
|
-
attrs: {
|
|
52
|
-
language: {
|
|
53
|
-
default: '',
|
|
54
|
-
},
|
|
55
|
-
fold: {
|
|
56
|
-
default: true,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
parseDOM: [
|
|
60
|
-
{
|
|
61
|
-
tag: 'div.code-fence-container',
|
|
62
|
-
preserveWhitespace: 'full',
|
|
63
|
-
getAttrs: (dom) => {
|
|
64
|
-
if (!(dom instanceof HTMLElement))
|
|
65
|
-
throw expectDomTypeError(dom)
|
|
66
|
-
|
|
67
|
-
return { language: dom.querySelector('pre')?.dataset.language }
|
|
68
|
-
},
|
|
69
|
-
getContent: (dom, schema) => {
|
|
70
|
-
if (!(dom instanceof HTMLElement))
|
|
71
|
-
throw expectDomTypeError(dom)
|
|
72
|
-
|
|
73
|
-
const text = dom.querySelector('pre')?.textContent ?? ''
|
|
74
|
-
if (!text)
|
|
75
|
-
return Fragment.empty
|
|
76
|
-
|
|
77
|
-
const textNode = schema.text(text)
|
|
78
|
-
return Fragment.from(textNode)
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
tag: 'pre',
|
|
83
|
-
preserveWhitespace: 'full',
|
|
84
|
-
getAttrs: (dom) => {
|
|
85
|
-
if (!(dom instanceof HTMLElement))
|
|
86
|
-
throw expectDomTypeError(dom)
|
|
87
|
-
|
|
88
|
-
return { language: dom.dataset.language }
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
toDOM: (node) => {
|
|
93
|
-
const select = document.createElement('select')
|
|
94
|
-
languageList.forEach((lang) => {
|
|
95
|
-
const option = document.createElement('option')
|
|
96
|
-
option.value = lang
|
|
97
|
-
option.innerText = !lang ? '--' : lang
|
|
98
|
-
if (lang === node.attrs.language)
|
|
99
|
-
option.selected = true
|
|
100
|
-
|
|
101
|
-
select.appendChild(option)
|
|
102
|
-
})
|
|
103
|
-
select.onchange = (e) => {
|
|
104
|
-
const target = e.target
|
|
105
|
-
if (!(target instanceof HTMLSelectElement))
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
const view = ctx.get(editorViewCtx)
|
|
109
|
-
if (!view.editable) {
|
|
110
|
-
target.value = node.attrs.language
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const { top, left } = target.getBoundingClientRect()
|
|
115
|
-
const result = view.posAtCoords({ top, left })
|
|
116
|
-
if (!result)
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
const { tr } = view.state
|
|
120
|
-
|
|
121
|
-
view.dispatch(
|
|
122
|
-
tr.setNodeMarkup(result.inside, undefined, {
|
|
123
|
-
...node.attrs,
|
|
124
|
-
language: target.value,
|
|
125
|
-
}),
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
return [
|
|
129
|
-
'div',
|
|
130
|
-
{
|
|
131
|
-
class: 'code-fence-container',
|
|
132
|
-
},
|
|
133
|
-
select,
|
|
134
|
-
[
|
|
135
|
-
'pre',
|
|
136
|
-
{
|
|
137
|
-
'data-language': node.attrs.language,
|
|
138
|
-
'class': utils.getClassName(node.attrs, 'code-fence'),
|
|
139
|
-
},
|
|
140
|
-
['code', { spellCheck: 'false' }, 0],
|
|
141
|
-
],
|
|
142
|
-
]
|
|
143
|
-
},
|
|
144
|
-
parseMarkdown: {
|
|
145
|
-
match: ({ type }) => type === 'code',
|
|
146
|
-
runner: (state, node, type) => {
|
|
147
|
-
const language = node.lang as string
|
|
148
|
-
const value = node.value as string
|
|
149
|
-
state.openNode(type, { language })
|
|
150
|
-
if (value)
|
|
151
|
-
state.addText(value)
|
|
152
|
-
|
|
153
|
-
state.closeNode()
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
toMarkdown: {
|
|
157
|
-
match: node => node.type.name === id,
|
|
158
|
-
runner: (state, node) => {
|
|
159
|
-
state.addNode('code', undefined, node.content.firstChild?.text || '', {
|
|
160
|
-
lang: node.attrs.language,
|
|
161
|
-
})
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
}),
|
|
165
|
-
inputRules: nodeType => [
|
|
166
|
-
textblockTypeInputRule(backtickInputRegex, nodeType, (match) => {
|
|
167
|
-
const [ok, language] = match
|
|
168
|
-
if (!ok)
|
|
169
|
-
return
|
|
170
|
-
return { language }
|
|
171
|
-
}),
|
|
172
|
-
textblockTypeInputRule(tildeInputRegex, nodeType, (match) => {
|
|
173
|
-
const [ok, language] = match
|
|
174
|
-
if (!ok)
|
|
175
|
-
return
|
|
176
|
-
return { language }
|
|
177
|
-
}),
|
|
178
|
-
],
|
|
179
|
-
commands: nodeType => [createCmd(TurnIntoCodeFence, () => setBlockType(nodeType))],
|
|
180
|
-
shortcuts: {
|
|
181
|
-
[SupportedKeys.CodeFence]: createShortcut(TurnIntoCodeFence, 'Mod-Alt-c'),
|
|
182
|
-
},
|
|
183
|
-
view: () => (node, view, getPos) => {
|
|
184
|
-
let currNode = node
|
|
185
|
-
|
|
186
|
-
const onSelectLanguage = (language: string) => {
|
|
187
|
-
const { tr } = view.state
|
|
188
|
-
view.dispatch(
|
|
189
|
-
tr.setNodeMarkup(getPos(), undefined, {
|
|
190
|
-
fold: true,
|
|
191
|
-
language,
|
|
192
|
-
}),
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
const onBlur = () => {
|
|
196
|
-
const { tr } = view.state
|
|
197
|
-
|
|
198
|
-
view.dispatch(
|
|
199
|
-
tr.setNodeMarkup(getPos(), undefined, {
|
|
200
|
-
...currNode.attrs,
|
|
201
|
-
fold: true,
|
|
202
|
-
}),
|
|
203
|
-
)
|
|
204
|
-
}
|
|
205
|
-
const onFocus = () => {
|
|
206
|
-
const { tr } = view.state
|
|
207
|
-
|
|
208
|
-
view.dispatch(
|
|
209
|
-
tr.setNodeMarkup(getPos(), undefined, {
|
|
210
|
-
...currNode.attrs,
|
|
211
|
-
fold: false,
|
|
212
|
-
}),
|
|
213
|
-
)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const renderer = utils.themeManager.get<ThemeCodeFenceType>('code-fence', {
|
|
217
|
-
view,
|
|
218
|
-
onBlur,
|
|
219
|
-
onFocus,
|
|
220
|
-
onSelectLanguage,
|
|
221
|
-
editable: () => view.editable,
|
|
222
|
-
languageList,
|
|
223
|
-
})
|
|
224
|
-
if (!renderer)
|
|
225
|
-
return {} as NodeView
|
|
226
|
-
|
|
227
|
-
const { dom, contentDOM, onUpdate, onDestroy } = renderer
|
|
228
|
-
onUpdate(currNode)
|
|
229
|
-
|
|
230
|
-
return {
|
|
231
|
-
dom,
|
|
232
|
-
contentDOM,
|
|
233
|
-
update: (updatedNode) => {
|
|
234
|
-
if (updatedNode.type.name !== id)
|
|
235
|
-
return false
|
|
236
|
-
currNode = updatedNode
|
|
237
|
-
onUpdate(currNode)
|
|
238
|
-
|
|
239
|
-
return true
|
|
240
|
-
},
|
|
241
|
-
destroy: onDestroy,
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
}
|
|
245
|
-
})
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Node } from 'unist'
|
|
3
|
-
import type { Parent } from 'unist-util-visit'
|
|
4
|
-
import { visit } from 'unist-util-visit'
|
|
5
|
-
|
|
6
|
-
export const addOrderInList = () => {
|
|
7
|
-
function transformer(ast: Node) {
|
|
8
|
-
visit(ast, 'list', (node: Parent & { ordered?: boolean; start?: number }) => {
|
|
9
|
-
if (node.ordered) {
|
|
10
|
-
const start = node.start ?? 1
|
|
11
|
-
node.children.forEach((child, index) => {
|
|
12
|
-
(child as Node & { label: number }).label = index + start
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return transformer
|
|
19
|
-
}
|