Link

Create, edit, and remove hyperlinks.

Try this feature →

Import

typescript
import { linkPlugin } from 'halka/plugins/link';

Usage

  • Select text and call link.toggle to wrap in <a>
  • link.toggle with empty href removes the link
  • Use link.active state to populate an edit-link dialog

Commands

CommandDescription
link.toggleCreate, update, or remove link (empty href removes)
link.updateUpdate link attributes at cursor
link.unlinkRemove link, keep text

State

Read plugin state with editor.getState(name). Listen to formatChange to refresh UI when the selection moves.

StateDescription
link.activeActive link attributes or null
typescript
const link = editor.getState('link.active') as {
  href: string;
  target: string;
  rel: string;
} | null;

// null when the caret is not inside a link
if (link) {
  console.log(link.href);
}

// Refresh when selection changes (e.g. toolbar)
editor.on('formatChange', () => {
  const active = editor.getState('link.active');
});

Example

typescript
editor.execCommand('link.toggle', {
  href: 'https://example.com',
  target: '_blank'
});

MIT · Halka Editor