NEWCKEditor AI on your premises: Hook your LLM and register MCP tools. Webinar coming soon!
Sign up (with export icon)

LinkDecoratorAutomaticDefinition

Api-interface iconinterface

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'
	}
}
Copy code

Note: If there is a conflict between the active manual decorator and automatic decorator (e.g. both try to manage the same attribute), the manual decorator takes precedence and the automatic one is ignored. It's also highly discouraged to have multiple automatic decorators managing the same attribute.

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.

Properties