Skip to content

Commit

Permalink
fix(link): Prevent auto-linking when typing URL inside inline code ma…
Browse files Browse the repository at this point in the history
…rk (#4160)
  • Loading branch information
rfgamaral committed Jul 7, 2023
1 parent 18946b1 commit b24df3a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/extension-link/src/helpers/autolink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,27 @@ export function autolink(options: AutolinkOptions): Plugin {

find(lastWordBeforeSpace)
.filter(link => link.isLink)
.filter(link => {
if (options.validate) {
return options.validate(link.value)
}
return true
})
// Calculate link position.
.map(link => ({
...link,
from: lastWordAndBlockOffset + link.start + 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.
.forEach(link => {
if (getMarksBetween(link.from, link.to, newState.doc).some(item => item.mark.type === options.type)) {
Expand Down

0 comments on commit b24df3a

Please sign in to comment.