Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/marks/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)\[([^\[\]]+)\]\((?<href>.+?)\)$/gm

const extractHrefFromMatch = (match: ExtendedRegExpMatchArray) => {
return { href: match.groups?.href }
Expand Down Expand Up @@ -161,7 +162,6 @@ const Link = TipTapLink.extend<RelativePathLinkOptions>({
},

addInputRules() {
const linkInputRegex = /(?:^|\s)\[([\w|\s|-]+)\]\((?<href>.+?)\)$/gm
return [
markInputRule({
find: linkInputRegex,
Expand Down
14 changes: 13 additions & 1 deletion src/tests/marks/Link.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down