https://github.com/dahlia/markdown-it-mention
A markdown-it plugin that parses and renders Mastodon-style @mentions
https://github.com/dahlia/markdown-it-mention
fediverse markdown markdown-it markdown-it-plugin mention
Last synced: 4 months ago
JSON representation
A markdown-it plugin that parses and renders Mastodon-style @mentions
- Host: GitHub
- URL: https://github.com/dahlia/markdown-it-mention
- Owner: dahlia
- License: mit
- Created: 2024-05-08T15:31:30.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-12-16T03:36:23.000Z (4 months ago)
- Last Synced: 2024-12-27T04:31:47.504Z (4 months ago)
- Topics: fediverse, markdown, markdown-it, markdown-it-plugin, mention
- Language: TypeScript
- Homepage: https://jsr.io/@fedify/markdown-it-mention
- Size: 23.4 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
@fedify/markdown-it-mention
===========================[![JSR][JSR badge]][JSR]
[![npm][npm badge]][npm]
[![GitHub Actions][GitHub Actions badge]][GitHub Actions]This is a [markdown-it] plugin that parses and renders Mastodon-style @mentions,
e.g., `@[email protected]`. It converts them to a link, e.g.:~~~~ html
@username
~~~~The value of `href` attributes, other attributes (if any), and the content of
the link can be customized by passing [options] to the plugin:~~~~ typescript
import MarkdownIt from "markdown-it";
import { mention, toFullHandle } from "@fedify/markdown-it-mention";const md = new MarkdownIt();
md.use(mention, {
link: (handle: string, env: any) => `https://example.com/${handle}`,
linkAttributes: (handle: string, env: any) => ({ class: "mention" }),
label: toFullHandle,
});
~~~~> [!TIP]
> The `link` callback can return `null` to disable the link.If you want to collect all the handles mentioned in the document, you can pass
the environment object to the `render()` method:~~~~ typescript
const env = {};
md.render(
"# Hello, @[email protected]\n\n> @[email protected]",
env,
);
console.log(env.mentions); // ["@[email protected]", "@[email protected]"]
~~~~[JSR]: https://jsr.io/@fedify/markdown-it-mention
[JSR badge]: https://jsr.io/badges/@fedify/markdown-it-mention
[npm]: https://www.npmjs.com/package/@fedify/markdown-it-mention
[npm badge]: https://img.shields.io/npm/v/%40fedify%2Fmarkdown-it-mention?logo=npm
[GitHub Actions]: https://github.com/dahlia/markdown-it-mention/actions/workflows/main.yaml
[GitHub Actions badge]: https://github.com/dahlia/markdown-it-mention/actions/workflows/main.yaml/badge.svg
[markdown-it]: https://github.com/markdown-it/markdown-it
[options]: https://jsr.io/@fedify/markdown-it-mention/doc/~/PluginOptionsInstallation
------------### Deno
~~~~ sh
deno add @fedify/markdown-it-mention
~~~~### Node.js
~~~~ sh
npm add @fedify/markdown-it-mention
~~~~### Bun
~~~~ sh
bun add @fedify/markdown-it-mention
~~~~