<a> HTML elements with support for various attributes including href, target, rel, class, and title.
Installation
Usage
Configuration Options
boolean
default:"true"
If enabled, the extension will automatically add links as you type.
Array<LinkProtocolOptions | string>
default:"[]"
An array of custom protocols to be registered with linkifyjs.
string
default:"'http'"
Default protocol to use when no protocol is specified.
boolean
default:"true"
If enabled, links will be opened on click.
boolean
default:"false"
If enabled, the link will be selected when clicked.
boolean
default:"true"
Adds a link to the current selection if the pasted content only contains a URL.
Record<string, any>
HTML attributes to add to the link element.
function
A validation function used for configuring link verification to prevent XSS attacks. Only modify this if you know what you’re doing.
function
Determines whether a valid link should be automatically linked in the content.
Commands
setLink(attributes)
Set a link mark with the specified attributes. Supportshref, target, rel, class, and title attributes.
toggleLink(attributes)
Toggle a link mark with the specified attributes.unsetLink()
Remove the link mark from the current selection.Link Attributes
The Link extension supports the following attributes:- href - The URL the link points to
- target - Where to open the link (e.g.,
_blank) - rel - The relationship between the current document and the linked document
- class - CSS class name(s) for the link
- title - Tooltip text displayed when hovering over the link (added in v3.19.0)
Security
The Link extension includes built-in XSS protection. By default, it only allows safe protocols:- http, https
- ftp, ftps
- mailto, tel, callto, sms
- cid, xmpp
isAllowedUri option, but be careful to maintain security when doing so.
Autolink Behavior
When autolink is enabled (default), the extension will automatically create links when you:- Type or paste a URL with an explicit protocol (e.g.,
https://example.com) - Type a domain with a TLD (e.g.,
example.com)
- IP addresses without a protocol
- Single-word hostnames without a TLD (e.g.,
localhost) - URLs typed inside inline code marks