# markdown-it-handle

> Parse links to users on social networks using markdown-it.

Latest version **0.3.1** (published 2025-08-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install markdown-it-handle
pnpm add markdown-it-handle
yarn add markdown-it-handle
bun add markdown-it-handle
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2025-08-02 |
| First published | 2023-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=22 \|\| >=24 |
| Dependencies | 0 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Paul Robert Lloyd |
| Maintainers | paulrobertlloyd |
| Keywords | markdown-it-plugin, markdown-it, markdown, handle |

## Links

- npm: https://www.npmjs.com/package/markdown-it-handle
- Repository: https://github.com/paulrobertlloyd/markdown-it-handle
- Homepage: https://github.com/paulrobertlloyd/markdown-it-handle#readme
- Issues: https://github.com/paulrobertlloyd/markdown-it-handle/issues
- npm.io page: https://npm.io/package/markdown-it-handle

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.3.1 (latest) — 2025-08-02
- 0.3.0 — 2025-02-23
- 0.2.2 — 2025-02-23
- 0.2.1 — 2025-02-14
- 0.2.0 — 2025-02-14
- 0.1.0 — 2023-04-01

## README

# markdown-it-handle · [![test](https://github.com/paulrobertlloyd/markdown-it-handle/actions/workflows/test.yml/badge.svg)](https://github.com/paulrobertlloyd/markdown-it-handle/actions/workflows/test.yml)

Link to users on social networks using [`markdown-it`](https://github.com/markdown-it/markdown-it) and the `@username@host` handle format used by networks that use ActivityPub, such as Mastodon.

You can also link to users on social networks that use the [AT Protocol](https://atproto.com), such as Bluesky. In this instance, handles follow the `@username.host` format, where `host` is a personal data server (PDS).

## Requirements

Node.js v22 or later.

## Installation

`npm install markdown-it-handle`

## Usage

```js
import markdownit from "markdown-it";
import handle from "markdown-it-handle";

const md = markdownit();

md.use(handle);
```

### ActivityPub

This plugin converts the format used for username handles common to federated social networks, into linked usernames.

For example, given this Markdown:

```md
@paulrobertlloyd@micro.blog and @paulrobertlloyd@mastadon.social.
```

the following markup will be generated:

```html
<p><a href="https://micro.blog/paulrobertlloyd" rel="external">@paulrobertlloyd</a>, and <a href="https://mastodon.social/@paulrobertlloyd" rel="external">@paulrobertlloyd</a>.</p>
```

This can be particularly useful if you are syndicating plain-text posts using Markdown, but rendering them on your own site as HTML.

Syndicated text containing handles will get parsed as mentions by the federated server, while readable link text is shown to readers on your own website.

### AT Protocol

This plugin converts the format used for username handles used by the AT Protocol into linked usernames.

For example, given this Markdown:

```md
@paulrobertlloyd.com but not @paulrobertlloyd.bsky.social.
```

the following markup will be generated:

```html
<p><a href="https://bsky.app/profile/paulrobertlloyd.com" rel="external">@paulrobertlloyd.com</a> but not <a href="https://bsky.app/profile/paulrobertlloyd.bsky.social" rel="external">@paulrobertlloyd.bsky.social</a>.</p>
```

Syndicated text containing handles can get parsed as mentions by an AT Protocol application, while readable link text is shown to readers on your own website.

The default AT Protocol application is `bsky.app`, but you can override this behaviour value using the `atProto.app` option.

## Options

### Link attributes

By default, links include a `rel="external"` attribute. To override this behaviour, set the `attributes` option to `false`:

```js
md.use(handle, {
  attributes: false,
});

marked("@username@social.example");
```

This will output:

```html
<p><a href="https://social.example/@username">@username</a></p>
```

You can add or update attributes used on handle links by providing them in the `attributes` option:

```js
md.use(handle, {
  attributes: {
    class: "handle",
    rel: "external nofollow",
    target: "_blank",
  },
});

marked("@username@social.example");
```

This will output:

```html
<p><a href="https://social.example/@username" class="handle" rel="external nofollow" target="_blank">@username</a></p>
```

### URL prefixes

Most federated networks include the `@` symbol in profile URLs but older and non-federated networks do not. Meanwhile, some networks use a common path for user profiles. For example:

| Network   | Username URL format                  |
| --------- | ------------------------------------ |
| Mastodon  | <https://server/@username>           |
| LinkedIn  | <https://linkedin.com/in/username>   |
| Flickr    | <https://flickr.com/photos/username> |

By default, usernames are linked to URLs using the first format which includes the `@` symbol.

A list of common social networks that don’t use this format is provided in [/lib/prefixes.js](/lib/prefixes.js). These values can be overridden and extended.

For example, if you want a Flickr usernames to link to profile pages instead of photo pages, you can update the `prefixes` option as follows:

```js
md.use(handle, {
  prefixes: {
    "flickr.com": "people/",
  },
});

marked("@username@flickr.com");
```

This will output:

```html
<p><a href="https://flickr.com/people/username" rel="external">@username</a></p>
```

### AT Protocol AppView

By default, AT Protocol handles link to profile pages on [bsky.app](https://bsky.app).

You can change this value using the `atProto.app` option. You can also add a custom prefix if this application uses a different URL format for profile pages:

```js
md.use(handle, {
  atProto: {
    app: "example.app"
  },
  prefixes: {
    "example.app": "users/",
  },
});

marked("@username.bsky.social");
```

This will output:

```html
<p><a href="https://example.app/users/@username.bsky.social" rel="external">@username.bsky.social</a></p>
```

## Releasing new versions

The recommended way to release new versions of this package is using [`np`](https://github.com/sindresorhus/np). This can be run using the following command:

```shell
npm run release
```

## Credits

Inspired by an original idea by [Cédric Aellen](https://alienlebarge.ch/notes/20230326175845/).

---
_Source: https://npm.io/package/markdown-it-handle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
