Skip to main content
Home

Built and signed on GitHub Actions

A markdown-it plugin that parses and renders Mastodon-style #hashtags

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
5 months ago (0.3.0)

@fedify/markdown-it-hashtag

JSR npm GitHub Actions

This is a markdown-it plugin that parses and renders Mastodon-style #hashtags. It converts, for example, #FooBar into a link:

<a href="#FooBar"><span class="hash">#</span><span class="tag">FooBar</span></a>

The value of href attributes, other attributes (if any), and the content of the link can be customized by passing options to the plugin:

import MarkdownIt from "markdown-it";
import { hashtag, spanHashAndTag } from "@fedify/markdown-it-hashtag";

const md = new MarkdownIt();
md.use(hashtag, {
  link: (tag: string) => `https://example.com/tags/${tag.substring(1)}`,
  linkAttributes: (handle: string) => ({ class: "hashtag" }),
  label: spanHashAndTag,
});

If you want to collect all hashtags in a document, you can pass an environment object to the render() method:

const env = {};
md.render(
  "Hello, #FooBar\n\n> #BazQux",
  env,
);
console.log(env.hashtags);  // ["#FooBar", "#BazQux"]

Installation

Deno

deno add @fedify/markdown-it-hashtag

Node.js

npm add @fedify/markdown-it-hashtag

Bun

bun add @fedify/markdown-it-hashtag
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@fedify/markdown-it-hashtag

Import symbol

import * as markdown_it_hashtag from "@fedify/markdown-it-hashtag";
or

Import directly with a jsr specifier

import * as markdown_it_hashtag from "jsr:@fedify/markdown-it-hashtag";

Add Package

pnpm i jsr:@fedify/markdown-it-hashtag
or (using pnpm 10.8 or older)
pnpm dlx jsr add @fedify/markdown-it-hashtag

Import symbol

import * as markdown_it_hashtag from "@fedify/markdown-it-hashtag";

Add Package

yarn add jsr:@fedify/markdown-it-hashtag
or (using Yarn 4.8 or older)
yarn dlx jsr add @fedify/markdown-it-hashtag

Import symbol

import * as markdown_it_hashtag from "@fedify/markdown-it-hashtag";

Add Package

vlt install jsr:@fedify/markdown-it-hashtag

Import symbol

import * as markdown_it_hashtag from "@fedify/markdown-it-hashtag";

Add Package

npx jsr add @fedify/markdown-it-hashtag

Import symbol

import * as markdown_it_hashtag from "@fedify/markdown-it-hashtag";

Add Package

bunx jsr add @fedify/markdown-it-hashtag

Import symbol

import * as markdown_it_hashtag from "@fedify/markdown-it-hashtag";