Jump To
Linkify #Hashtag Plugin
Adds basic support for #-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 social media hashtags with
linkifyHtml
:
const options = {
formatHref: {
hashtag: (href) => "https://bsky.app/hashtag/" + href.substr(1),
},
};
// With linkify-html
linkifyHtml("Works with hashtags #PhotoOfTheDay or #일상", options);
// With linkify-react
<Linkify options={options}>
Works with hashtags #PhotoOfTheDay or #일상
</Linkify>;
The last line returns the following string:
'Works with hashtags <a href="https://bsky.app/hashtag/PhotoOfTheDay">#PhotoOfTheDay</a> or <a href="https://bsky.app/hashtag/일상">#일상</a>';