Overview
The Link extension enables hyperlink support in your editor with automatic URL detection, paste handling, and interactive link creation. It automatically detects and converts URLs as you type or paste them.Installation
Basic Usage
Link Attributes
Links support standard HTML anchor attributes:Commands
addLink
Applies a link mark to the current selection.href: The URL (required)target: Where to open the link (optional)rel: Link relationship attributes (optional)
removeLink
Removes the link mark from the current selection.toggleLink
Toggles a link on or off. If a link exists, it removes it. Otherwise, it adds a new link.expandLink
Expands the selection to encompass the entire link.Automatic URL Detection
The Link extension includes several automatic detection features:Input Rule
Automatically converts URLs when you type a space after them:Enter Rule
Automatically converts URLs when you press Enter:Mark Rule
Automatically applies and removes link marks as you type, providing real-time feedback.Paste Rule
Automatically converts pasted URLs into clickable links:Usage Examples
Creating Links Programmatically
Editing Existing Links
Interactive Link Creation
Complete Example
Link Detection Patterns
The extension detects various URL formats:http://example.comhttps://example.comwww.example.comexample.com(in some contexts)
Accessibility
For external links, it’s recommended to include appropriaterel attributes:
Recommended Attributes
- noopener: Prevents the new page from accessing
window.opener - noreferrer: Prevents passing referrer information
- nofollow: Indicates the link should not be followed by search engines (for user-generated content)
Styling Links
Links render as standard HTML anchor elements and can be styled with CSS:Advanced Usage
Custom Link Handling
You can implement custom link click handlers:Validating URLs
Related Extensions
- Combine with text formatting extensions like
defineBold()anddefineItalic() - Use with
defineCode()for inline code that shouldn’t be linkified - Works within lists created with
defineList()