Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions packages/core/src/editor/managers/ExtensionManager/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AnyExtension as AnyTiptapExtension,
extensions,
getAttributes,
mergeAttributes,
Node,
Extension as TiptapExtension,
} from "@tiptap/core";
Expand Down Expand Up @@ -117,7 +118,13 @@ export function getDefaultTiptapExtensions(

let link: HTMLAnchorElement | null = null;

if (event.target instanceof HTMLAnchorElement) {
if (
event.target instanceof HTMLAnchorElement &&
// Differentiate between link inline content and read-only links.
event.target.hasAttribute("data-inline-content-type") &&
event.target.getAttribute("data-inline-content-type") ===
"link"
) {
link = event.target;
} else {
const target = event.target as HTMLElement | null;
Expand All @@ -127,9 +134,11 @@ export function getDefaultTiptapExtensions(

const root = tiptapEditor.view.dom;

// Tntentionally limit the lookup to the editor root.
// Intentionally limit the lookup to the editor root.
// Using tag names like DIV as boundaries breaks with custom NodeViews,
link = target.closest<HTMLAnchorElement>("a");
link = target.closest<HTMLAnchorElement>(
'a[data-inline-content-type="link"]',
);

if (link && !root.contains(link)) {
link = null;
Expand Down Expand Up @@ -177,7 +186,13 @@ export function getDefaultTiptapExtensions(
defaultProtocol: DEFAULT_LINK_PROTOCOL,
// only call this once if we have multiple editors installed. Or fix https://github.com/ueberdosis/tiptap/issues/5450
protocols: LINKIFY_INITIALIZED ? [] : VALID_LINK_PROTOCOLS,
HTMLAttributes: options.links?.HTMLAttributes ?? {},
HTMLAttributes: mergeAttributes(
{
className: "bn-inline-content-section",
"data-inline-content-type": "link",
},
options.links?.HTMLAttributes ?? {},
),
// Always false as we handle clicks ourselves above.
openOnClick: false,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Link1</a>
<br />
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website2.com"
>Link2</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Link1</a>
<br />
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Link1</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Website</a>
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website2.com"
>Website2</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Website</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Web</a>
</strong>
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>site</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Link1</a>
<br />
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website2.com"
>Link2</a>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Link1</a>
<br />
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Link1</a>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Website</a>
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website2.com"
>Website2</a>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Website</a>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>Web</a>
</strong>
<a
target="_blank"
rel="noopener noreferrer nofollow"
classname="bn-inline-content-section"
data-inline-content-type="link"
href="https://www.website.com"
>site</a>
</p>
Loading