From a9e8f48b3492404da25f0610afb6fb53d6f308d3 Mon Sep 17 00:00:00 2001 From: Ken van der Eerden Date: Thu, 5 May 2022 11:07:08 +0200 Subject: [PATCH] Allow class attribute through setLink() While you can set a default value for the Link extensions class attribute using ```javascript Link.configure({ HTMLAttributes: { class: 'my-custom-class', }, }) ``` It is currently not possible to dynamically set the class attribute when calling setLink() e.g. ```javascript this.editor.chain().focus().extendMarkRange('link').setLink({href: url, class: 'this class should be added'}).run(); ``` This change allows for that by default, without needing to extend the Link extension. --- packages/extension-link/src/link.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index 0ea72dffa..40bd1c932 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -61,6 +61,7 @@ export const Link = Mark.create({ HTMLAttributes: { target: '_blank', rel: 'noopener noreferrer nofollow', + class: null, }, } }, @@ -73,6 +74,9 @@ export const Link = Mark.create({ target: { default: this.options.HTMLAttributes.target, }, + class: { + default: this.options.HTMLAttributes.class, + }, } },