Skip to content

Commit

Permalink
Allow class attribute through setLink()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ken-vdE authored May 5, 2022
1 parent 43611ea commit 352a66c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/extension-link/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const Link = Mark.create<LinkOptions>({
HTMLAttributes: {
target: '_blank',
rel: 'noopener noreferrer nofollow',
class: null,
},
}
},
Expand All @@ -73,6 +74,9 @@ export const Link = Mark.create<LinkOptions>({
target: {
default: this.options.HTMLAttributes.target,
},
class: {
default: this.options.HTMLAttributes.class,
},
}
},

Expand Down

0 comments on commit 352a66c

Please sign in to comment.