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.
This commit is contained in:
Ken van der Eerden 2022-05-05 11:07:08 +02:00 committed by bdbch
parent 43611ea2e7
commit a9e8f48b34

View File

@ -61,6 +61,7 @@ export const Link = Mark.create<LinkOptions>({
HTMLAttributes: { HTMLAttributes: {
target: '_blank', target: '_blank',
rel: 'noopener noreferrer nofollow', rel: 'noopener noreferrer nofollow',
class: null,
}, },
} }
}, },
@ -73,6 +74,9 @@ export const Link = Mark.create<LinkOptions>({
target: { target: {
default: this.options.HTMLAttributes.target, default: this.options.HTMLAttributes.target,
}, },
class: {
default: this.options.HTMLAttributes.class,
},
} }
}, },