Skip to content

Commit b88ea6b

Browse files
committed
Fix link nodes always including target and rel attributes
1 parent 5504ab8 commit b88ea6b

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/marks/Link.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ class Link extends Mark
1919
// =========================================================================
2020

2121
public function getTag()
22-
{
22+
{
23+
// Reset
24+
$this->attrs['rel'] = null;
25+
2326
if (isset($this->attrs['target'])) {
2427
if ($this->attrs['target'] === '_blank') {
25-
$this->attrs['rel'] = 'noopener noreferrer nofollow';
28+
$this->attrs['rel'] = 'noopener noreferrer';
2629
}
2730
}
2831

src/web/assets/field/dist/js/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/field/src/js/components/input/link/Link.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
import { Plugin, PluginKey } from 'prosemirror-state';
2+
import { mergeAttributes } from '@tiptap/core';
23
import Link from '@tiptap/extension-link';
34

45
export default Link.extend({
6+
addOptions() {
7+
return {
8+
...this.parent?.(),
9+
10+
// Reset the default attributes to not assume `target="_blank"`
11+
HTMLAttributes: {
12+
target: null,
13+
rel: null,
14+
class: null,
15+
},
16+
};
17+
},
18+
19+
renderHTML({ HTMLAttributes }) {
20+
const attrs = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes);
21+
22+
// Only output `rel` if setting a target
23+
if (attrs.target === '_blank') {
24+
attrs.rel = 'noopener noreferrer';
25+
}
26+
27+
return ['a', attrs, 0];
28+
},
29+
530
addProseMirrorPlugins() {
631
return [
732
new Plugin({

src/web/assets/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"/field/dist/js/main.js": "/field/dist/js/main.js?id=fdbb173d1db25aad3a8e",
2+
"/field/dist/js/main.js": "/field/dist/js/main.js?id=98f3aba287b37a296d4c",
33
"/field/dist/css/style.css": "/field/dist/css/style.css?id=4d44c86feaaeeb9b55b0"
44
}

0 commit comments

Comments
 (0)