Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error occurs when the link is purely numerical #5479

Merged
merged 2 commits into from Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions ui/packages/editor/src/extensions/link/index.ts
@@ -1,6 +1,7 @@
import TiptapLink from "@tiptap/extension-link";
import type { LinkOptions } from "@tiptap/extension-link";
import type { ExtensionOptions } from "@/types";
import { mergeAttributes } from "@/tiptap/vue-3";

const Link = TiptapLink.extend<ExtensionOptions & LinkOptions>({
addOptions() {
Expand All @@ -13,6 +14,28 @@ const Link = TiptapLink.extend<ExtensionOptions & LinkOptions>({
},
};
},

renderHTML({ HTMLAttributes }) {
const href = HTMLAttributes.href;
// False positive; we're explicitly checking for javascript: links to ignore them
// eslint-disable-next-line no-script-url
if (href?.toString().startsWith("javascript:")) {
// strip out the href
return [
"a",
mergeAttributes(this.options.HTMLAttributes, {
...HTMLAttributes,
href: "",
}),
0,
];
}
return [
"a",
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
0,
];
},
});

export default Link;