@milkdown/preset-commonmark 7.2.2 → 7.2.4
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 +675 -648
- package/lib/index.es.js.map +1 -1
- package/lib/mark/emphasis.d.ts.map +1 -1
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/node/blockquote.d.ts.map +1 -1
- package/lib/node/bullet-list.d.ts.map +1 -1
- package/lib/node/code-block.d.ts.map +1 -1
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/node/paragraph.d.ts.map +1 -1
- package/lib/plugin/index.d.ts +1 -0
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/regexp.d.ts +1 -0
- package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -1
- package/lib/plugin/remark-marker-plugin.d.ts +2 -0
- package/lib/plugin/remark-marker-plugin.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/composed/plugins.ts +2 -1
- package/src/mark/emphasis.ts +14 -6
- package/src/mark/inline-code.ts +4 -4
- package/src/mark/link.ts +5 -5
- package/src/mark/strong.ts +14 -6
- package/src/node/blockquote.ts +2 -2
- package/src/node/bullet-list.ts +2 -2
- package/src/node/code-block.ts +2 -2
- package/src/node/hardbreak.ts +2 -2
- package/src/node/heading.ts +10 -10
- package/src/node/hr.ts +5 -5
- package/src/node/image.ts +6 -6
- package/src/node/list-item.ts +8 -7
- package/src/node/ordered-list.ts +3 -3
- package/src/node/paragraph.ts +1 -1
- package/src/plugin/hardbreak-clear-mark-plugin.ts +4 -4
- package/src/plugin/index.ts +1 -0
- package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +0 -2
- package/src/plugin/inline-sync-plugin/regexp.ts +3 -1
- package/src/plugin/inline-sync-plugin/replacer.ts +11 -0
- package/src/plugin/inline-sync-plugin/utils.ts +4 -4
- package/src/plugin/remark-marker-plugin.ts +20 -0
- package/src/plugin/sync-heading-id-plugin.ts +1 -1
- package/src/plugin/sync-list-order-plugin.ts +4 -4
package/src/node/paragraph.ts
CHANGED
|
@@ -51,7 +51,7 @@ withMeta(paragraphSchema.ctx, {
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
/// This command can turn the selected block into paragraph.
|
|
54
|
-
export const turnIntoTextCommand = $command('TurnIntoText',
|
|
54
|
+
export const turnIntoTextCommand = $command('TurnIntoText', ctx => () => setBlockType(paragraphSchema.type(ctx)))
|
|
55
55
|
|
|
56
56
|
withMeta(turnIntoTextCommand, {
|
|
57
57
|
displayName: 'Command<turnIntoTextCommand>',
|
|
@@ -6,7 +6,7 @@ import { hardbreakSchema } from '../node'
|
|
|
6
6
|
import { withMeta } from '../__internal__'
|
|
7
7
|
|
|
8
8
|
/// This plugin is used to clear the marks around the hardbreak node.
|
|
9
|
-
export const hardbreakClearMarkPlugin = $prose(() => {
|
|
9
|
+
export const hardbreakClearMarkPlugin = $prose((ctx) => {
|
|
10
10
|
return new Plugin({
|
|
11
11
|
key: new PluginKey('MILKDOWN_HARDBREAK_MARKS'),
|
|
12
12
|
appendTransaction: (trs, _oldState, newState) => {
|
|
@@ -25,7 +25,7 @@ export const hardbreakClearMarkPlugin = $prose(() => {
|
|
|
25
25
|
return
|
|
26
26
|
|
|
27
27
|
const { from } = step as unknown as { from: number }
|
|
28
|
-
return newState.tr.setNodeMarkup(from, hardbreakSchema.type(), undefined, [])
|
|
28
|
+
return newState.tr.setNodeMarkup(from, hardbreakSchema.type(ctx), undefined, [])
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const isAddMarkStep = step instanceof AddMarkStep
|
|
@@ -33,8 +33,8 @@ export const hardbreakClearMarkPlugin = $prose(() => {
|
|
|
33
33
|
let _tr = newState.tr
|
|
34
34
|
const { from, to } = step as unknown as { from: number; to: number }
|
|
35
35
|
newState.doc.nodesBetween(from, to, (node, pos) => {
|
|
36
|
-
if (node.type === hardbreakSchema.type())
|
|
37
|
-
_tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(), undefined, [])
|
|
36
|
+
if (node.type === hardbreakSchema.type(ctx))
|
|
37
|
+
_tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(ctx), undefined, [])
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
return _tr
|
package/src/plugin/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './remark-add-order-in-list-plugin'
|
|
|
6
6
|
export * from './remark-line-break'
|
|
7
7
|
export * from './remark-inline-link-plugin'
|
|
8
8
|
export * from './remark-html-transformer'
|
|
9
|
+
export * from './remark-marker-plugin'
|
|
9
10
|
|
|
10
11
|
export * from './inline-nodes-cursor-plugin'
|
|
11
12
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
export const linkRegexp = /\[(
|
|
3
|
+
export const linkRegexp = /\[([^\]]+)]\([^\s\]]+\)/
|
|
4
|
+
|
|
5
|
+
export const keepLinkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
|
|
4
6
|
|
|
5
7
|
export const punctuationRegexp = (holePlaceholder: string) =>
|
|
6
8
|
new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
|
|
@@ -7,6 +7,7 @@ import { TextSelection } from '@milkdown/prose/state'
|
|
|
7
7
|
import { inlineSyncConfig } from './config'
|
|
8
8
|
import { getContextByState } from './context'
|
|
9
9
|
import { calcOffset } from './utils'
|
|
10
|
+
import { linkRegexp } from './regexp'
|
|
10
11
|
|
|
11
12
|
export const runReplacer = (
|
|
12
13
|
ctx: Ctx,
|
|
@@ -26,6 +27,8 @@ export const runReplacer = (
|
|
|
26
27
|
if (!context)
|
|
27
28
|
return
|
|
28
29
|
|
|
30
|
+
const lastUserInput = context.text.slice(0, context.text.indexOf(context.placeholder))
|
|
31
|
+
|
|
29
32
|
const { $from } = nextState.selection
|
|
30
33
|
const from = $from.before()
|
|
31
34
|
const to = $from.after()
|
|
@@ -41,5 +44,13 @@ export const runReplacer = (
|
|
|
41
44
|
// restore the selection
|
|
42
45
|
tr = tr.setSelection(TextSelection.near(tr.doc.resolve(offset + 1)))
|
|
43
46
|
|
|
47
|
+
const needsRestoreMark = linkRegexp.test(lastUserInput) || ['*', '_', '~'].includes(lastUserInput.at(-1) || '')
|
|
48
|
+
if (needsRestoreMark && tr.selection instanceof TextSelection) {
|
|
49
|
+
const marks = tr.selection.$cursor?.marks() ?? []
|
|
50
|
+
marks.forEach((mark) => {
|
|
51
|
+
tr = tr.removeStoredMark(mark.type)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
dispatch(tr)
|
|
45
56
|
}
|
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
import type { Node } from '@milkdown/prose/model'
|
|
4
4
|
|
|
5
5
|
import type { SyncNodePlaceholder } from './config'
|
|
6
|
-
import {
|
|
6
|
+
import { keepLinkRegexp, punctuationRegexp } from './regexp'
|
|
7
7
|
|
|
8
8
|
export const keepLink = (str: string) => {
|
|
9
9
|
let text = str
|
|
10
|
-
let match = text.match(
|
|
10
|
+
let match = text.match(keepLinkRegexp)
|
|
11
11
|
while (match && match.groups) {
|
|
12
12
|
const { span } = match.groups
|
|
13
|
-
text = text.replace(
|
|
13
|
+
text = text.replace(keepLinkRegexp, span as string)
|
|
14
14
|
|
|
15
|
-
match = text.match(
|
|
15
|
+
match = text.match(keepLinkRegexp)
|
|
16
16
|
}
|
|
17
17
|
return text
|
|
18
18
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { $remark } from '@milkdown/utils'
|
|
3
|
+
import type { Node } from 'unist'
|
|
4
|
+
import { visit } from 'unist-util-visit'
|
|
5
|
+
import { withMeta } from '../__internal__'
|
|
6
|
+
|
|
7
|
+
/// This plugin is used to keep the marker (`_` and `*`) of emphasis and strong nodes.
|
|
8
|
+
export const remarkMarker = $remark(() => () => (tree, file) => {
|
|
9
|
+
const getMarker = (node: Node) => {
|
|
10
|
+
return (file.value as string).charAt(node.position!.start.offset!)
|
|
11
|
+
}
|
|
12
|
+
visit(tree, node => ['strong', 'emphasis'].includes(node.type), (node: Node) => {
|
|
13
|
+
(node as Node & { marker: string }).marker = getMarker(node)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
withMeta(remarkMarker, {
|
|
18
|
+
displayName: 'Remark<remarkMarker>',
|
|
19
|
+
group: 'Remark',
|
|
20
|
+
})
|
|
@@ -20,7 +20,7 @@ export const syncHeadingIdPlugin = $prose((ctx) => {
|
|
|
20
20
|
let found = false
|
|
21
21
|
|
|
22
22
|
view.state.doc.descendants((node, pos) => {
|
|
23
|
-
if (node.type === headingSchema.type()) {
|
|
23
|
+
if (node.type === headingSchema.type(ctx)) {
|
|
24
24
|
if (node.textContent.trim().length === 0)
|
|
25
25
|
return
|
|
26
26
|
|
|
@@ -9,14 +9,14 @@ import { bulletListSchema } from '../node'
|
|
|
9
9
|
import { withMeta } from '../__internal__'
|
|
10
10
|
|
|
11
11
|
/// This plugin is used to keep the label of list item up to date in ordered list.
|
|
12
|
-
export const syncListOrderPlugin = $prose(() => {
|
|
12
|
+
export const syncListOrderPlugin = $prose((ctx) => {
|
|
13
13
|
const syncOrderLabel = (view: EditorView) => {
|
|
14
14
|
if (view.composing || !view.editable)
|
|
15
15
|
return
|
|
16
16
|
|
|
17
|
-
const orderedListType = orderedListSchema.type()
|
|
18
|
-
const bulletListType = bulletListSchema.type()
|
|
19
|
-
const listItemType = listItemSchema.type()
|
|
17
|
+
const orderedListType = orderedListSchema.type(ctx)
|
|
18
|
+
const bulletListType = bulletListSchema.type(ctx)
|
|
19
|
+
const listItemType = listItemSchema.type(ctx)
|
|
20
20
|
const state = view.state
|
|
21
21
|
const handleNodeItem = (attrs: Record<string, any>, index: number): boolean => {
|
|
22
22
|
let changed = false
|