LinkDecoratorAutomaticDefinition (link)
@ckeditor/ckeditor5-link/src/link
Describes an automatic link decorator. This decorator type matches all links in the editor content against a function that decides whether the link should receive a pre–defined set of attributes.
It takes an object with key-value pairs of attributes and a callback function that must return a Boolean value based on the link's
href
(URL). When the callback returns true
, attributes are applied to the link.
For example, to add the target="_blank"
attribute to all links in the editor starting with http://
, the
configuration could look like this:
{
mode: 'automatic',
callback: url => url.startsWith( 'http://' ),
attributes: {
target: '_blank'
}
}
Note: Since the target
attribute management for external links is a common use case, there is a predefined automatic decorator
dedicated for that purpose that can be enabled by turning a single option on. Check out the
config.link.addTargetToExternalLinks
configuration description to learn more.
Filtering
Properties
-
attributes : Object | undefined
module:link/link~LinkDecoratorAutomaticDefinition#attributes
Key-value pairs used as link attributes added to the output during the downcasting. Attributes should follow the
ElementDefinition
syntax. -
callback : function
module:link/link~LinkDecoratorAutomaticDefinition#callback
Takes a
url
as a parameter and returnstrue
if theattributes
should be applied to the link. -
classes : String | Array.<String> | undefined
module:link/link~LinkDecoratorAutomaticDefinition#classes
Class names used as link classes added to the output during the downcasting. Classes should follow the
ElementDefinition
syntax. -
mode : 'automatic'
module:link/link~LinkDecoratorAutomaticDefinition#mode
Link decorator type. It is
'automatic'
for all automatic decorators. -
styles : Object | undefined
module:link/link~LinkDecoratorAutomaticDefinition#styles
Key-value pairs used as link styles added to the output during the downcasting. Styles should follow the
ElementDefinition
syntax.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.