@milkdown/preset-commonmark 7.3.2 → 7.3.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/inputrules.d.ts +2 -1
- package/lib/composed/inputrules.d.ts.map +1 -1
- package/lib/composed/plugins.d.ts.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +599 -728
- package/lib/index.es.js.map +1 -1
- package/lib/mark/emphasis.d.ts +2 -0
- package/lib/mark/emphasis.d.ts.map +1 -1
- package/lib/mark/inline-code.d.ts +1 -0
- package/lib/mark/inline-code.d.ts.map +1 -1
- package/lib/mark/strong.d.ts +1 -0
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/plugin/index.d.ts +0 -1
- package/lib/plugin/index.d.ts.map +1 -1
- package/package.json +15 -9
- package/src/composed/inputrules.ts +10 -1
- package/src/composed/plugins.ts +0 -5
- package/src/index.ts +3 -2
- package/src/mark/emphasis.ts +28 -1
- package/src/mark/inline-code.ts +12 -1
- package/src/mark/strong.ts +12 -1
- package/src/plugin/index.ts +0 -2
- package/lib/plugin/inline-sync-plugin/config.d.ts +0 -24
- package/lib/plugin/inline-sync-plugin/config.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/context.d.ts +0 -11
- package/lib/plugin/inline-sync-plugin/context.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/index.d.ts +0 -3
- package/lib/plugin/inline-sync-plugin/index.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts +0 -2
- package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/regexp.d.ts +0 -9
- package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/replacer.d.ts +0 -5
- package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +0 -1
- package/lib/plugin/inline-sync-plugin/utils.d.ts +0 -9
- package/lib/plugin/inline-sync-plugin/utils.d.ts.map +0 -1
- package/src/plugin/inline-sync-plugin/config.ts +0 -78
- package/src/plugin/inline-sync-plugin/context.ts +0 -121
- package/src/plugin/inline-sync-plugin/index.ts +0 -4
- package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +0 -72
- package/src/plugin/inline-sync-plugin/regexp.ts +0 -16
- package/src/plugin/inline-sync-plugin/replacer.ts +0 -50
- package/src/plugin/inline-sync-plugin/utils.ts +0 -96
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
|
|
3
|
-
export const linkRegexp = /\[([^\]]+)]\([^\s\]]+\)/
|
|
4
|
-
|
|
5
|
-
export const keepLinkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
|
|
6
|
-
|
|
7
|
-
export function punctuationRegexp(holePlaceholder: string) {
|
|
8
|
-
return new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const ZERO_WIDTH_SPACE = '\u200B'
|
|
12
|
-
|
|
13
|
-
export const asterisk = `${ZERO_WIDTH_SPACE}*`
|
|
14
|
-
export const asteriskHolder = `${ZERO_WIDTH_SPACE}*`
|
|
15
|
-
export const underline = `${ZERO_WIDTH_SPACE}_`
|
|
16
|
-
export const underlineHolder = `${ZERO_WIDTH_SPACE}⎽`
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Ctx } from '@milkdown/ctx'
|
|
3
|
-
import type { Attrs } from '@milkdown/prose/model'
|
|
4
|
-
import type { EditorState, PluginKey, Transaction } from '@milkdown/prose/state'
|
|
5
|
-
import { TextSelection } from '@milkdown/prose/state'
|
|
6
|
-
|
|
7
|
-
import { inlineSyncConfig } from './config'
|
|
8
|
-
import { getContextByState } from './context'
|
|
9
|
-
import { calcOffset } from './utils'
|
|
10
|
-
import { linkRegexp } from './regexp'
|
|
11
|
-
|
|
12
|
-
export function runReplacer(ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs) {
|
|
13
|
-
const { placeholderConfig } = ctx.get(inlineSyncConfig.key)
|
|
14
|
-
const holePlaceholder = placeholderConfig.hole
|
|
15
|
-
// insert a placeholder to restore the selection
|
|
16
|
-
let tr = state.tr.setMeta(key, true).insertText(holePlaceholder, state.selection.from)
|
|
17
|
-
|
|
18
|
-
const nextState = state.apply(tr)
|
|
19
|
-
const context = getContextByState(ctx, nextState)
|
|
20
|
-
|
|
21
|
-
if (!context)
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
const lastUserInput = context.text.slice(0, context.text.indexOf(context.placeholder))
|
|
25
|
-
|
|
26
|
-
const { $from } = nextState.selection
|
|
27
|
-
const from = $from.before()
|
|
28
|
-
const to = $from.after()
|
|
29
|
-
|
|
30
|
-
const offset = calcOffset(context.nextNode, from, context.placeholder)
|
|
31
|
-
|
|
32
|
-
tr = tr
|
|
33
|
-
.replaceWith(from, to, context.nextNode)
|
|
34
|
-
.setNodeMarkup(from, undefined, attrs)
|
|
35
|
-
// delete the placeholder
|
|
36
|
-
.delete(offset + 1, offset + 2)
|
|
37
|
-
|
|
38
|
-
// restore the selection
|
|
39
|
-
tr = tr.setSelection(TextSelection.near(tr.doc.resolve(offset + 1)))
|
|
40
|
-
|
|
41
|
-
const needsRestoreMark = linkRegexp.test(lastUserInput) || ['*', '_', '~'].includes(lastUserInput.at(-1) || '')
|
|
42
|
-
if (needsRestoreMark && tr.selection instanceof TextSelection) {
|
|
43
|
-
const marks = tr.selection.$cursor?.marks() ?? []
|
|
44
|
-
marks.forEach((mark) => {
|
|
45
|
-
tr = tr.removeStoredMark(mark.type)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
dispatch(tr)
|
|
50
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
|
|
3
|
-
import type { Node } from '@milkdown/prose/model'
|
|
4
|
-
|
|
5
|
-
import type { SyncNodePlaceholder } from './config'
|
|
6
|
-
import {
|
|
7
|
-
asterisk,
|
|
8
|
-
asteriskHolder,
|
|
9
|
-
keepLinkRegexp,
|
|
10
|
-
punctuationRegexp,
|
|
11
|
-
underline,
|
|
12
|
-
underlineHolder,
|
|
13
|
-
} from './regexp'
|
|
14
|
-
|
|
15
|
-
export function keepLink(str: string) {
|
|
16
|
-
let text = str
|
|
17
|
-
let match = text.match(keepLinkRegexp)
|
|
18
|
-
while (match && match.groups) {
|
|
19
|
-
const { span } = match.groups
|
|
20
|
-
text = text.replace(keepLinkRegexp, span as string)
|
|
21
|
-
|
|
22
|
-
match = text.match(keepLinkRegexp)
|
|
23
|
-
}
|
|
24
|
-
return text
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function mergeSlash(str: string) {
|
|
28
|
-
return str
|
|
29
|
-
.replaceAll(/\\\\\*/g, asterisk)
|
|
30
|
-
.replaceAll(/\\\\_/g, underline)
|
|
31
|
-
.replaceAll(asterisk, asteriskHolder)
|
|
32
|
-
.replaceAll(underline, underlineHolder)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function swap(text: string, first: number, last: number) {
|
|
36
|
-
const arr = text.split('')
|
|
37
|
-
const temp = arr[first]
|
|
38
|
-
if (arr[first] && arr[last]) {
|
|
39
|
-
arr[first] = arr[last] as string
|
|
40
|
-
arr[last] = temp as string
|
|
41
|
-
}
|
|
42
|
-
return arr.join('').toString()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function replacePunctuation(holePlaceholder: string) {
|
|
46
|
-
return (text: string) =>
|
|
47
|
-
text.replace(punctuationRegexp(holePlaceholder), '')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function calculatePlaceholder(placeholder: SyncNodePlaceholder) {
|
|
51
|
-
return (text: string) => {
|
|
52
|
-
const index = text.indexOf(placeholder.hole)
|
|
53
|
-
const left = text.charAt(index - 1)
|
|
54
|
-
const right = text.charAt(index + 1)
|
|
55
|
-
const notAWord = /[^\w]|_/
|
|
56
|
-
|
|
57
|
-
// cursor on the right
|
|
58
|
-
if (!right)
|
|
59
|
-
return placeholder.punctuation
|
|
60
|
-
|
|
61
|
-
// cursor on the left
|
|
62
|
-
if (!left)
|
|
63
|
-
return placeholder.char
|
|
64
|
-
|
|
65
|
-
if (notAWord.test(left) && notAWord.test(right))
|
|
66
|
-
return placeholder.punctuation
|
|
67
|
-
|
|
68
|
-
return placeholder.char
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function calcOffset(node: Node, from: number, placeholder: string) {
|
|
73
|
-
let offset = from
|
|
74
|
-
let find = false
|
|
75
|
-
node.descendants((n) => {
|
|
76
|
-
if (find)
|
|
77
|
-
return false
|
|
78
|
-
if (!n.textContent.includes(placeholder)) {
|
|
79
|
-
offset += n.nodeSize
|
|
80
|
-
return false
|
|
81
|
-
}
|
|
82
|
-
if (n.isText) {
|
|
83
|
-
const i = n.text?.indexOf(placeholder)
|
|
84
|
-
if (i != null && i >= 0) {
|
|
85
|
-
find = true
|
|
86
|
-
offset += i
|
|
87
|
-
return false
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// enter the node
|
|
92
|
-
offset += 1
|
|
93
|
-
return true
|
|
94
|
-
})
|
|
95
|
-
return offset
|
|
96
|
-
}
|