diff --git a/src/marks/Link.ts b/src/marks/Link.ts index e506553cc85..5d19151548d 100644 --- a/src/marks/Link.ts +++ b/src/marks/Link.ts @@ -14,6 +14,7 @@ import { domHref, parseHref } from '../helpers/links.js' import { linkClicking } from '../plugins/links' const PROTOCOLS_TO_LINK_TO = ['http:', 'https:', 'mailto:', 'tel:'] +export const linkInputRegex = /(?:^|\s)\[([^\[\]]+)\]\((?.+?)\)$/gm const extractHrefFromMatch = (match: ExtendedRegExpMatchArray) => { return { href: match.groups?.href } @@ -161,7 +162,6 @@ const Link = TipTapLink.extend({ }, addInputRules() { - const linkInputRegex = /(?:^|\s)\[([\w|\s|-]+)\]\((?.+?)\)$/gm return [ markInputRule({ find: linkInputRegex, diff --git a/src/tests/marks/Link.spec.js b/src/tests/marks/Link.spec.js index bd1acd66620..ef6755b3ae6 100644 --- a/src/tests/marks/Link.spec.js +++ b/src/tests/marks/Link.spec.js @@ -4,7 +4,19 @@ */ import Underline from '../../marks/Underline.js' import createCustomEditor from '../testHelpers/createCustomEditor.ts' -import Link from './../../marks/Link.ts' +import Link, { linkInputRegex } from './../../marks/Link.ts' + +describe('Link extension unit', () => { + it('matches markdown links with dots in the link text', () => { + linkInputRegex.lastIndex = 0 + const match = linkInputRegex.exec( + '[something.cloud](https://something.cloud/page)', + ) + + expect(match?.[1]).toBe('something.cloud') + expect(match?.groups?.href).toBe('https://something.cloud/page') + }) +}) describe('Link extension integrated in the editor', () => { it('should have link available in commands', () => {