check exclued marks in markInputRule
This commit is contained in:
@@ -1,5 +1,19 @@
|
|||||||
import { InputRule } from 'prosemirror-inputrules'
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
|
|
||||||
|
function getMarksBetween(start, end, state) {
|
||||||
|
let marks = []
|
||||||
|
|
||||||
|
state.doc.nodesBetween(start, end, (node, pos) => {
|
||||||
|
marks = [...marks, ...node.marks.map(mark => ({
|
||||||
|
start: pos,
|
||||||
|
end: pos + node.nodeSize,
|
||||||
|
mark,
|
||||||
|
}))]
|
||||||
|
})
|
||||||
|
|
||||||
|
return marks
|
||||||
|
}
|
||||||
|
|
||||||
export default function (regexp, markType, getAttrs) {
|
export default function (regexp, markType, getAttrs) {
|
||||||
return new InputRule(regexp, (state, match, start, end) => {
|
return new InputRule(regexp, (state, match, start, end) => {
|
||||||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
||||||
@@ -16,6 +30,17 @@ export default function (regexp, markType, getAttrs) {
|
|||||||
const textStart = matchStart + match[m - 1].lastIndexOf(match[m])
|
const textStart = matchStart + match[m - 1].lastIndexOf(match[m])
|
||||||
const textEnd = textStart + match[m].length
|
const textEnd = textStart + match[m].length
|
||||||
|
|
||||||
|
const excludedMarks = getMarksBetween(start, end, state)
|
||||||
|
.filter(item => {
|
||||||
|
const { excluded } = item.mark.type
|
||||||
|
return excluded.find(type => type.name === markType.name)
|
||||||
|
})
|
||||||
|
.filter(item => item.end > matchStart)
|
||||||
|
|
||||||
|
if (excludedMarks.length) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (textEnd < matchEnd) {
|
if (textEnd < matchEnd) {
|
||||||
tr.delete(textEnd, matchEnd)
|
tr.delete(textEnd, matchEnd)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user