Skip to content

Link Plugin

The LinkPlugin adds hyperlink support with a toolbar button that opens a URL input popup.

Link plugin with URL popup

import { LinkPlugin } from '@notectl/core';
new LinkPlugin()
// or:
new LinkPlugin({ openInNewTab: true })
interface LinkConfig {
/** Whether links open in a new tab (adds target="_blank"). Default: true */
readonly openInNewTab: boolean;
/** Render separator after toolbar item. */
readonly separatorAfter?: boolean;
}
CommandDescriptionReturns
toggleLinkAdd or remove a link on the selectionboolean
setLinkSet a link mark on the selectionboolean
removeLinkRemove link mark from selectionboolean

The toolbar button is only enabled when there is a text range selection (not a collapsed cursor).

editor.executeCommand('toggleLink');
editor.executeCommand('removeLink');
ShortcutAction
Ctrl+K / Cmd+KToggle link (opens URL popup if adding)

The link button opens a custom popup with:

  • A URL input field with placeholder text
  • An Apply button to confirm the link
  • When the cursor is inside an existing link: pre-filled URL and a “Remove” button
MarkHTML TagAttributesRenders As
link<a>href: string<a href="..."> with optional target="_blank"

When openInNewTab is true, the toDOM method adds target="_blank" and rel="noopener noreferrer" to the rendered <a> element.

To add a link programmatically without the popup:

import { markType } from '@notectl/core';
// Select text first, then apply the link mark
const state = editor.getState();
const { anchor, head } = state.selection;
const tr = state.transaction('api')
.addMark(
anchor.blockId,
anchor.offset,
head.offset,
{ type: markType('link'), attrs: { href: 'https://example.com' } }
)
.build();
editor.dispatch(tr);