# milkdown-mentions-plugin

> [![GitHub license](https://img.shields.io/github/license/zgrybus/milkdown-mentions-plugin)](https://github.com/zgrybus/milkdown-mentions-plugin/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/milkdown-mentions-plugin)](https://www.npmjs.com/pack

Latest version **0.0.2** (published 2024-04-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install milkdown-mentions-plugin
pnpm add milkdown-mentions-plugin
yarn add milkdown-mentions-plugin
bun add milkdown-mentions-plugin
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2024-04-11 |
| First published | 2024-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 245.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | zgrybus |
| Keywords | milkdown, mentions, milkdown plugin, tag |

## Links

- npm: https://www.npmjs.com/package/milkdown-mentions-plugin
- npm.io page: https://npm.io/package/milkdown-mentions-plugin

## Dependencies (1)

- [@milkdown/utils](https://npm.io/package/@milkdown/utils.md) ^7.3.5

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2024-04-11
- 0.0.1 — 2024-03-25

## README

[![GitHub license](https://img.shields.io/github/license/zgrybus/milkdown-mentions-plugin)](https://github.com/zgrybus/milkdown-mentions-plugin/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/milkdown-mentions-plugin)](https://www.npmjs.com/package/milkdown-mentions-plugin)

- [Overview](#overview)
- [Using library](#using-library)
- [Troubleshoots](#troubleshoots)
  * [After selecting the thing I want to tag, each subsequent word is a link](#after-selecting-the-thing-i-want-to-tag--each-subsequent-word-is-a-link)


## Overview

This library wraps [Milkdown](https://milkdown.dev/) and allows you to tag people, for example. **Of course, you can tag anything or anyone you want, because the library provides options to render a list of people or things you want to tag**, as well as the page to which the user will be redirected after clicking on the tag. 
**Additionally, the library transforms the tag into a link.**

![Demo](https://github.com/zgrybus/milkdown-mentions-plugin/blob/master/assets/plugin_demo.gif)

## Using library

Using `npm`
```bash
npm i --save milkdown-mentions-plugin
```
Using `yarn`
```bash
yarn add  milkdown-mentions-plugin
```

and then import the given components as shown below ( **of course you need to setup Milkdown** )
```typescript
import { Editor as MilkdownEditor, rootCtx } from '@milkdown/core';
import { commonmark } from '@milkdown/preset-commonmark';
import { useEditor } from '@milkdown/react';
import {
  mentionsPlugin,
  mentionsPluginOptions,
} from 'milkdown-mentions-plugin';

import { YourComponent } from '../YourComponent';

export const useMilkdown = () => {
  const mentions = mentionsPlugin();

  const editor = useEditor(
    root =>
      MilkdownEditor.make()
        .config(ctx => {
          ctx.set(rootCtx, root);
          ctx.update(mentionsPluginOptions.key, prev => ({
            ...prev,
            view: MyMentionsPluginDropdownView, 
          }));
        })
        .use(commonmark)
        .use(mentions),
    [],
  );

  return editor;
};
```

```typescript
import { MentionsListDropdownProps } from 'milkdown-mentions-plugin'

export const MyMentionsPluginDropdownView: React.FC<MentionsListDropdownProps> = ({ 
  queryText, // current query text ( if we type @Name, then queryText is Name )
  onMentionItemClick // function that converts @Name text into link with appropriate url
}) => {
    return (
      [...my list]
        .filter(text => text.includes(queryText))
        .map(text => (
          <button 
            key={text} 
            onClick={() => onMentionItemClick(text, `https://facebook.com/user/${text}`)}
          >
            {text}
          </button>
        ))
    )
}
```

## Troubleshoots


### After selecting the thing I want to tag, each subsequent word is a link

![Demo](https://github.com/zgrybus/milkdown-mentions-plugin/blob/master/assets/subsequent_word_troubleshoot.gif)
This is a problem that many people who use Milkdown struggle with. To fix this, just add the following plugin mentioned in this issue: https://github.com/orgs/Milkdown/discussions/1114

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