Jump To

Linkify #Hashtag Plugin

Adds basic support for Twitter-style hashtags.

Installation

Node.js module

Install from the command line with NPM

npm install linkifyjs linkify-plugin-hashtag
const linkify = require("linkifyjs");
require("linkify-plugin-hashtag");

or with ES6 modules

import * as linkify from "linkifyjs";
import "linkify-plugin-hashtag";

Browser globals

Download linkify and extract the contents into your website’s assets directory. Include the following scripts in your HTML:

<script src="linkify.js"></script>
<script src="linkify-plugin-hashtag.js"></script>

Usage

Use the formatHref option with your preferred interface to correctly resolve a hashtag. Example linking to Twitter hashtags with linkifyHtml:

const options = {
  formatHref: {
    hashtag: (href) => "https://twitter.com/hashtag/" + href.substr(1),
  },
};
linkifyHtml("Works with hashtags #PhotoOfTheDay or #일상");

The last line returns the following string:

'Works with hashtags <a href="https://twitter.com/hashtag/PhotoOfTheDay">#PhotoOfTheDay</a> or <a href="https://twitter.com/hashtag/일상">#일상</a>';