npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markdown-it-kbd-better

v1.2.5

Published

Markdown-it syntax add-on for the <kbd> tag, but with tiny improvements.

Downloads

164

Readme

markdown-it-kbd-better

This is a fork of markdown-it-kbd with some tiny improvements just for myself.

Notably, it includes the following changes:

  • Support for replacing key names with values using a map (e.g. mac:cmd -> ). Fully customizable in the options, add your own replacements or disable it completely. Comes with a built-in preset for replacing some common keys with icons. You could use this to make macros like copy to ⌘+C or win:ctrl to ⊞+Ctrl.
  • Support for transforming key names with a custom function (e.g. adding a prefix to all keys or capitalizing them). Fully customizable in the options, add your own transformations or disable it completely.
  • Support for case-sensitive key matching. Fully customizable in the options, disable it if you don't need it.

Installation

npm i markdown-it-kbd-better
pnpm add markdown-it-kbd-better
yarn add markdown-it-kbd-better

Usage

const markdownIt = require('markdown-it');
const markdownItKbd = require('markdown-it-kbd-better');

const md = markdownIt().use(markdownItKbd);

Options

presets

Default: []

Enable built-in presets. Currently, the only built-in preset is icons, which replaces keys like cmd with , but more may be added in the future (feel free to open an issue if you have a suggestion).

To enable the icons preset, use the following:

.use(markdownItKbd, {
    presets: [{
        name: 'icons'
    }]
});

You can optionally pass prefix as well, which is used to prefix the key name. For example, if you wanted to match icon:cmd (prefixed with icon:) instead of cmd, you could use the following:

.use(markdownItKbd, {
    presets: [
        {
            name: 'icons',
            prefix: 'icon:'
        }
    ]
});

keyMap

Default: {}

A map of keys and values to replace. If the content of a KBD element is present in this map, it will be replaced with the corresponding value.

For example, you could replace win with :

.use(markdownItKbd, {
    keyMap: {
        win: '⊞'
    }
});

caseSensitive

Default: false

Whether or not to match keys in a case-sensitive manner. If this is set to false, all keys will be converted to lowercase before being matched. Otherwise, they will be matched exactly as they appear in the map.

transform

Default: return content; (no transformation)

A function that transforms the content. This is useful for things like capitalizing the key name or adding a prefix to it.

For example, you could capitalize all key names:

.use(markdownItKbd, {
    transform: (content: string) => {
        return content.toUpperCase();
    }
});

Or you could add a text to all key names:

.use(markdownItKbd, {
    transform: (content: string) => {
        return `Key: ${content}`;
    }
});

License

MIT