Link extension for tiptap rich text editor providing automatic link detection, paste handling, click behavior, and XSS protection.
88
Build a custom Tiptap extension that integrates the link functionality with proper lifecycle management and state tracking. Your extension should wrap the link extension and maintain statistics about link usage within the editor.
Create a LinkManagerExtension that:
Extends the base link functionality: Configure and include the link extension with automatic link detection enabled and links opening on click.
Tracks link statistics: Maintain a count of total links currently in the document. This count should update whenever links are added or removed through any means (commands, typing, pasting, etc.).
Provides lifecycle integration:
Exposes a command: Provide a getLinkCount command that returns the current number of links in the document.
Exports the count: Make the current link count accessible from outside the editor instance so it can be displayed in a UI component.
LinkManagerExtensionImplement test cases in link-manager.test.ts to verify:
const editor = new Editor({
extensions: [Document, Paragraph, Text, LinkManagerExtension],
content: '<p>Hello world</p>'
})
editor.chain().focus().setTextSelection({ from: 1, to: 6 }).setLink({ href: 'https://example.com' }).run()
// Link count should be 1
expect(editor.commands.getLinkCount()).toBe(1)const editor = new Editor({
extensions: [Document, Paragraph, Text, LinkManagerExtension],
content: '<p>First link and second link</p>'
})
editor.chain().focus().setTextSelection({ from: 1, to: 6 }).setLink({ href: 'https://first.com' }).run()
editor.chain().focus().setTextSelection({ from: 16, to: 22 }).setLink({ href: 'https://second.com' }).run()
// Link count should be 2
expect(editor.commands.getLinkCount()).toBe(2)const editor = new Editor({
extensions: [Document, Paragraph, Text, LinkManagerExtension],
content: '<p><a href="https://example.com">link text</a> and plain text</p>'
})
// Initial count should be 1
expect(editor.commands.getLinkCount()).toBe(1)
editor.chain().focus().setTextSelection({ from: 1, to: 10 }).unsetLink().run()
// After removal, count should be 0
expect(editor.commands.getLinkCount()).toBe(0)Core Tiptap editor framework providing the extension system, editor lifecycle, and command infrastructure.
Provides link mark functionality including commands for creating, toggling, and removing links, with automatic link detection and paste handling.
Required document node for Tiptap editor schema.
Required paragraph node for Tiptap editor schema.
Required text node for Tiptap editor schema.
Install with Tessl CLI
npx tessl i tessl/npm-tiptap--extension-linkdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10