feat(extension-link): add validate option to link extension

#2779
This commit is contained in:
Dominik Biedebach
2022-05-13 11:36:46 +02:00
committed by Dominik
parent ccc37d5f24
commit 23e67adfa7
10 changed files with 276 additions and 9 deletions

View File

@@ -0,0 +1,32 @@
import './styles.scss'
import React from 'react'
import Link from '@tiptap/extension-link'
import { EditorContent, useEditor } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
export default () => {
const editor = useEditor({
extensions: [
StarterKit,
Link.configure({
validate: link => /^https?:\/\//.test(link),
}),
],
content: `
<p>Hey! Try to type in url with and without a http/s protocol. - Links without a protocol should not get auto linked</p>
`,
editorProps: {
attributes: {
spellcheck: 'false',
},
},
})
return (
<div>
<EditorContent editor={editor} />
</div>
)
}