JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 278
  • Score
    100M100P100Q98252F
  • License ISC

A rehype plugin to add a color chip with an inline block with a valid color code

Package Exports

  • rehype-color-chips
  • rehype-color-chips/package.json

Readme

rehype-color-chips

rehype plugin to add a color chip with an inline code block containing a supported color model.

These don't work with .md files, but work inside issues. See https://github.com/shreshthmohan/rehype-color-chips/issues/1#issue-1391093265

On GitHub issues:

image

On a page with this plugin:

image

Note that the 3-digit hex code doesn't work on GitHub, but works with this plugin.

Appropriate styles will need to be applied for the the color "chip" to show up.

Installation

npm install rehype-color-chips
yarn add  rehype-color-chips

Usage

This plugin has been tested to work with next-mdx-remote. But should work with other mdx libraries too.

See it being used in a Next.js project here.

import { serialize } from 'next-mdx-remote/serialize'
import rehypeColorChips from 'rehype-color-chips'

const serializedContent = await serialize(content, {
  mdxOptions: {
    remarkPlugins: [remarkGfm],
    rehypePlugins: [
      /* other rehype plugins */
      rehypeColorChips,
    ],
  },
})

Styling

By default, the plugin applies a gfm-color-chip class to the added element.

As an example the following styles can be applied to the color chip:

.gfm-color-chip
  margin-left: 0.125rem;
  display: inline-block;
  height: 0.625rem;
  width: 0.625rem;
  border-radius: 9999px;
  border: 1px solid gray;