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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mdfriday/shortcode

v0.0.14

Published

A flexible component-based shortcode system for Markdown content with theme support

Downloads

28

Readme

@mdfriday/shortcode

A flexible component-based shortcode system for Markdown content with theme support.

npm version License: MIT

Introduction

@mdfriday/shortcode provides a powerful shortcode system that allows you to embed rich, themeable components in your Markdown content. It uses a simple and intuitive syntax while offering extensive customization through themes and component variants.

Features

  • Simple Shortcode Syntax: Easily embed components using a familiar {{< component attr="value" >}} syntax
  • Themeable Components: Define and apply different themes to your components
  • Component Variants: Create multiple variants of components with different styles
  • Light/Dark Mode Support: Built-in support for light and dark mode themes
  • Extensible Architecture: Easily add new components and extend existing ones

Installation

npm install @mdfriday/shortcode
# or
yarn add @mdfriday/shortcode

Usage

This package provides a flexible shortcode system that allows you to register and render custom shortcodes in Markdown content.

CommonJS Usage (Node.js)

// CommonJS (require) - RECOMMENDED WAY
const pkg = require('@mdfriday/shortcode');
const { Shortcode } = pkg;

// Create a new Shortcode instance
const shortcode = new Shortcode();

// Register a shortcode
shortcode.registerShortcode({
  id: 1,
  name: 'alert',
  template: '<div class="alert alert-{{.type}}">{{.content}}</div>',
  uuid: 'alert-shortcode'
});

// Render markdown content with shortcodes
const markdown = 'Normal text {{< alert type="danger" >}}This is an alert{{< /alert >}}';
const html = shortcode.render(markdown);

ES Modules Usage

// ES Modules (import) - RECOMMENDED WAY
import pkg from '@mdfriday/shortcode';
const { Shortcode } = pkg;

// Create a new Shortcode instance
const shortcode = new Shortcode();

// Register a shortcode
shortcode.registerShortcode({
  id: 2,
  name: 'button',
  template: '<button class="btn btn-{{.type}}">{{.content}}</button>',
  uuid: 'button-shortcode'
});

// Render markdown content with shortcodes
const markdown = 'Normal text {{< button type="primary" >}}Click me{{< /button >}}';
const html = shortcode.render(markdown);

Important Note About Imports

Due to how the package is built, always use the imports as shown above. Direct named imports (e.g., import { Shortcode } from '@mdfriday/shortcode') might not work in all environments.

Shortcode Metadata

When registering a shortcode, you should provide metadata:

shortcode.registerShortcode({
  id: "unique-id", // Required: string or number
  name: "shortcode-name", // Required: the name used in markdown {{< shortcode-name >}}
  template: "Template with {{.content}} and {{.params}}", // Required: the template to render
  uuid: "optional-uuid", // Optional: a UUID for the shortcode
  tags: ["optional", "tags"], // Optional: tags for categorization
  // Other optional fields: slug, example, asset, width, height, etc.
});

Advanced Usage

Custom Functions and Data Providers

// Register a shortcode with custom functions and data provider
shortcode.registerShortcode(
  {
    id: 3,
    name: 'list',
    template: '{{range .items}}<li>{{.}}</li>{{end}}',
    uuid: 'list-shortcode'
  },
  {
    // Custom function map (optional)
    funcMap: new Map([
      ['uppercase', (str) => str.toUpperCase()],
      // Add more custom functions...
    ]),
    
    // Custom data provider (optional)
    dataProvider: (params, content) => {
      return {
        content,
        items: content ? content.split(',').map(item => item.trim()) : [],
        // Add more data based on params...
      };
    }
  }
);

API Reference

Shortcode Class

  • new Shortcode(cacheSizeLimit?: number) - Create a new Shortcode instance with optional cache size limit
  • registerShortcode(metadata, options?) - Register a new shortcode
  • render(markdownContent) - Render markdown content with shortcodes
  • existsById(id) - Check if a shortcode exists by ID
  • findByName(name) - Find a shortcode by name
  • findByUuid(uuid) - Find a shortcode by UUID
  • findById(id) - Find a shortcode by ID
  • getAllShortcodes() - Get all registered shortcodes
  • clearCache() - Clear the rendering cache

License

This project is licensed under the MIT License - see the LICENSE file for details.