JSPM

@fedify/markdown-it-hashtag

0.1.0-dev.1+6387f205
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q62160F
  • License MIT

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

Package Exports

  • @fedify/markdown-it-hashtag

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@fedify/markdown-it-hashtag) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@fedify/markdown-it-hashtag

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