fix(link): Prevent auto-linking when typing URL inside inline code mark (#4160)

This commit is contained in:
Ricardo Amaral 2023-07-07 10:05:34 +01:00 committed by GitHub
parent 18946b1e35
commit b24df3aa4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,18 +112,27 @@ export function autolink(options: AutolinkOptions): Plugin {
find(lastWordBeforeSpace) find(lastWordBeforeSpace)
.filter(link => link.isLink) .filter(link => link.isLink)
.filter(link => {
if (options.validate) {
return options.validate(link.value)
}
return true
})
// Calculate link position. // Calculate link position.
.map(link => ({ .map(link => ({
...link, ...link,
from: lastWordAndBlockOffset + link.start + 1, from: lastWordAndBlockOffset + link.start + 1,
to: lastWordAndBlockOffset + link.end + 1, to: lastWordAndBlockOffset + link.end + 1,
})) }))
// ignore link inside code mark
.filter(link => {
return !newState.doc.rangeHasMark(
link.from,
link.to,
newState.schema.marks.code,
)
})
// validate link
.filter(link => {
if (options.validate) {
return options.validate(link.value)
}
return true
})
// Add link mark. // Add link mark.
.forEach(link => { .forEach(link => {
if (getMarksBetween(link.from, link.to, newState.doc).some(item => item.mark.type === options.type)) { if (getMarksBetween(link.from, link.to, newState.doc).some(item => item.mark.type === options.type)) {