This generic plugin lets you register attributes, that are meant to be bound to links only. It will take care to register corresponding up- and downcast, as well as listening to selection changes, similar as CKEditor's link feature does.

To benefit from CKEditor's link feature, it is highly recommended that all model attributes start with link in their names.

Configuration API

To register attributes to handle as being part of links, you may call registerAttribute. To ease this process, a utility method getLinkAttributes exists, that may be invoked like this:

getLinkAttributes(editor)?.registerAttribute({
model: "linkCustomAttribute",
view: "data-custom-attribute",
});

CKEditor Configuration

As an alternative to configuring these attributes via API, you may also define corresponding attributes as part of the CKEditor Link Feature configuration – with an extended section attributes:

const linkAttributesConfig: LinkAttributesConfig = {
attributes: [
{ view: "title", model: "linkTitle" },
{ view: "data-xlink-actuate", model: "linkActuate" },
],
};

ClassicEditor.create(sourceElement, {
plugins: [
LinkAttributes,
Link,
// ...
],
link: {
defaultProtocol: "https://",
...linkAttributesConfig,
},
};

Declaring this as a constant is recommended to get IDE support regarding the available fields and valid values. You will note that the type of the field model requires, that the value starts with link. This automatically triggers some behavior in the Link Plugin.

Configuration as part of the CKEditor 5 Configuration section is highly recommended, when it is about attributes that are not yet handled by any dedicated plugin, that provides editing features for that attribute. If a plugin gets added, that handles the corresponding attribute, the configuration needs to be adapted accordingly.

While this plugin does not depend on LinkEditing explicitly, it is best used with LinkEditing to be available. Otherwise, some clean-up tasks we implicitly rely on (like for all model attributes prefixed with link) won't work.

Hierarchy (view full)

Constructors

Properties

Methods

Constructors

  • Parameters

    • editor: default

    Returns LinkAttributes

    Inherit Doc

Properties

pluginName: "LinkAttributes" = ...
requires: (typeof default | typeof LinkCleanup)[] = ...

Methods

  • Register an attribute as being bound to links.

    This method automatically registers the corresponding up- and downcast configuration and extends the model schema.

    It also registers the attribute for clean-up, when a link gets removed (via LinkCleanup plugin).

    Parameters

    Returns void