# Hyperlink

- Human documentation: [https://docs.univer.ai/guides/docs/features/hyper-link](https://docs.univer.ai/guides/docs/features/hyper-link)

- Agent Markdown: [https://docs.univer.ai/guides/docs/features/hyper-link.md](https://docs.univer.ai/guides/docs/features/hyper-link.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [docs/features/hyper-link.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/features/hyper-link.mdx)

---

#### Package metadata

```json
{
  "preset": [
    {
      "client": "@univerjs/preset-docs-hyper-link",
      "locale": "@univerjs/preset-docs-hyper-link/locales/en-US",
      "style": "@univerjs/preset-docs-hyper-link/lib/index.css"
    }
  ],
  "plugins": [
    {
      "client": "@univerjs/docs-hyper-link"
    },
    {
      "client": "@univerjs/docs-hyper-link-ui",
      "locale": "@univerjs/docs-hyper-link-ui/locale/en-US",
      "style": "@univerjs/docs-hyper-link-ui/lib/index.css"
    }
  ],
  "server": false
}
```

Hyperlinks are used to quickly navigate and access external web pages, email addresses, and other content in documents.

## Preset Mode

### Installation

#### npm

```bash
npm install @univerjs/preset-docs-hyper-link
```

#### pnpm

```bash
pnpm add @univerjs/preset-docs-hyper-link
```

#### yarn

```bash
yarn add @univerjs/preset-docs-hyper-link
```

#### bun

```bash
bun add @univerjs/preset-docs-hyper-link
```

### Usage

```typescript
import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'
import UniverPresetDocsCoreEnUS from '@univerjs/preset-docs-core/locales/en-US'
import { UniverDocsHyperLinkPreset } from '@univerjs/preset-docs-hyper-link' // [!code ++]
import UniverPresetDocsHyperLinkEnUS from '@univerjs/preset-docs-hyper-link/locales/en-US' // [!code ++]
import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'

import '@univerjs/preset-docs-core/lib/index.css'
import '@univerjs/preset-docs-hyper-link/lib/index.css' // [!code ++]

const { univerAPI } = createUniver({
  locale: LocaleType.EN_US,
  locales: {
    [LocaleType.EN_US]: mergeLocales(
      UniverPresetDocsCoreEnUS,
      UniverPresetDocsHyperLinkEnUS, // [!code ++]
    ),
  },
  presets: [
    UniverDocsCorePreset(),
    UniverDocsHyperLinkPreset(), // [!code ++]
  ],
})
```

## Plugin Mode

### Installation

#### npm

```bash
npm install @univerjs/docs-hyper-link @univerjs/docs-hyper-link-ui
```

#### pnpm

```bash
pnpm add @univerjs/docs-hyper-link @univerjs/docs-hyper-link-ui
```

#### yarn

```bash
yarn add @univerjs/docs-hyper-link @univerjs/docs-hyper-link-ui
```

#### bun

```bash
bun add @univerjs/docs-hyper-link @univerjs/docs-hyper-link-ui
```

### Usage

```typescript
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'
import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link' // [!code ++]
import { UniverDocsHyperLinkUIPlugin } from '@univerjs/docs-hyper-link-ui' // [!code ++]
import DocsHyperLinkUIEnUS from '@univerjs/docs-hyper-link-ui/locale/en-US' // [!code ++]

import '@univerjs/docs-hyper-link-ui/lib/index.css' // [!code ++]

const univer = new Univer({
  locale: LocaleType.EN_US,
  locales: {
    [LocaleType.EN_US]: mergeLocales(
      DocsHyperLinkUIEnUS, // [!code ++]
    ),
  },
})

univer.registerPlugin(UniverDocsHyperLinkPlugin) // [!code ++]
univer.registerPlugin(UniverDocsHyperLinkUIPlugin) // [!code ++]
```

## Create and edit links with the Facade API

`link(text, url)` appends linked text and records its range, so you do not need to calculate character offsets. Use the range id returned by `getLinks()` to change the destination later.

```ts
const richText = univerAPI
  .newRichText()
  .text('Read ')
  .link('Web SDK documentation', 'https://docs.univer.ai')
  .text(' for details.')

const [link] = richText.getLinks()
if (!link) throw new Error('Link was not created')

richText.updateLink(link.rangeId, 'https://docs.univer.ai/guides')
```

Call `removeLink(link.rangeId)` to remove the destination while keeping the visible text.
