remark-taggable

1.0.1 • Public • Published

remark-taggable

license

Plugin for remark to support generalized taggables like #tag and @user. Relies on micromark-extension-taggable for tokenization and mdast-util-taggable for converting markdown to/from abstract syntax trees.

Install

Install remark-taggable on npm.

npm install remark-taggable

Usage

const unified = require("unified");
const markdown = require("remark-parse");
const taggablePlugin = require("remark-taggable");

let processor = unified().use(markdown).use(taggablePlugin);

// Or use with options

let processor = unified()
  .use(markdown)
  .use(citePlugin, {
    classes: ["micromark-taggable"],
    rules: [
      {
        marker: "!",
        type: "warn",
        toUrl: (val) => `/warnings/${val}`,
        classes: ["warning"],
      },
      {
        marker: "$",
        type: "variable",
        toUrl: (val) => `/variables/${val}`,
        classes: ["variable"],
      },
    ],
    allowEmail: false,
  });

Running the processor on the following markdown (without options being defined):

This is a #hashtag and this is a @mentionedUser.

Will produce the following taggable node:

{
  "type": "paragraph",
  "children": [
    {
      "type": "text",
      "value": "This is a "
    },
    {
      "type": "taggable",
      "value": "hashtag",
      "data": {
        "type": "tag",
        "marker": "#",
        "url": "/tags/hashtag"
      }
    },
    {
      "type": "text",
      "value": "This is a "
    },
    {
      "type": "taggable",
      "value": "mentionedUser",
      "data": {
        "type": "mention",
        "marker": "@",
        "url": "/users/mentionedUser"
      }
    },
    {
      "type": "text",
      "value": "."
    }
  ]
}

Configuration

For details about the syntax tree structure, see mdast-util-taggable. For details about the configuration and supported syntax, see micromark-extension-cite.

Credits

Big shoutout to @benrbray's repositry @benrbray/remark-cite for inspiration and for help as a template for this plugin. I would highly recommend it in case you need citation support for remark.

Package Sidebar

Install

npm i remark-taggable

Weekly Downloads

7

Version

1.0.1

License

MIT

Unpacked Size

15.2 kB

Total Files

11

Last publish

Collaborators

  • therdas