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

markdown-it-admonitions

v0.1.9

Published

A markdown-it plugin for rendering admonitions

Downloads

918

Readme

markdown-it-admonitions

A markdown-it plugin for rendering admonitions (callouts/alerts).

Installation

npm install markdown-it-admonitions

Usage

import MarkdownIt from 'markdown-it';
import admonitionPlugin from 'markdown-it-admonitions';

const md = new MarkdownIt();
md.use(admonitionPlugin);

const result = md.render(`
:::note Custom Title
This is a note admonition with a custom title.
:::

:::warning
This is a warning with the default title.
:::
`);

Syntax

The plugin supports two syntax styles:

Docusaurus Style (default)

:::note Optional Title
Content goes here
:::

Obsidian Style (default)

> [!note] Optional Title
> Content goes here
> More content

Both styles can be enabled or disabled independently via options.

Default Types

  • note 📝
  • tip 💡
  • warning ⚠️
  • danger 🚨
  • info ℹ️

Options

md.use(admonitionPlugin, {
  // Custom types to register
  types: ['note', 'tip', 'warning', 'danger', 'info', 'custom'],
  
  // Custom emoji icons for types (used when lucideIcons is false)
  icons: {
    custom: '✨',
    note: '📌'
  },
  
  // Use Lucide icons instead of emojis (default: false)
  // See "Lucide Icons" section below for details
  lucideIcons: false,
  
  // Custom marker for Docusaurus style (default is ":")
  marker: ':',
  
  // Enable/disable syntax styles
  // NOTE: At least one must be enabled (default: both true)
  obsidianStyle: true,    // Enable > [!type] syntax (default: true)
  docusaurusStyle: true,  // Enable ::: type syntax (default: true)
  
  // Custom render functions per type
  // IMPORTANT: Both 'open' and 'close' must be provided together for symmetric rendering
  customRenders: {
    custom: {
      open: (tokens, idx, options, env, slf) => {
        tokens[idx].attrJoin('class', 'my-custom-class');
        return slf.renderToken(tokens, idx, options);
      },
      close: (tokens, idx, options, env, slf) => {
        return slf.renderToken(tokens, idx, options);
      }
    }
  }
});

Lucide Icons

The plugin supports Lucide icons via react-icons. When enabled, the plugin renders icon placeholders with data-lucide-icon attributes that you can hydrate with your preferred icon library.

Installation:

npm install react-icons

Enable Lucide icons:

// Use default Lucide icon mappings
md.use(admonitionPlugin, {
  lucideIcons: true
});

// Or provide custom icon name mappings
md.use(admonitionPlugin, {
  lucideIcons: {
    note: 'LuPencil',      // Override default
    tip: 'LuZap',          // Override default
    custom: 'LuSparkles'   // Add new type
  }
});

Default Lucide icon mappings:

| Type | Icon Name | Icon | |------|-----------|------| | note | LuStickyNote | 📄 | | tip | LuLightbulb | 💡 | | warning | LuTriangleAlert | ⚠️ | | danger | LuCircleAlert | 🚨 | | info | LuInfo | ℹ️ |

React example (hydrating icons):

import { useEffect } from 'react';
import * as LucideIcons from 'react-icons/lu';
import { createRoot } from 'react-dom/client';

function hydrateAdmonitionIcons() {
  const iconElements = document.querySelectorAll('[data-lucide-icon]');
  
  iconElements.forEach((el) => {
    const iconName = el.getAttribute('data-lucide-icon');
    const IconComponent = LucideIcons[iconName];
    
    if (IconComponent) {
      const root = createRoot(el);
      root.render(<IconComponent />);
    }
  });
}

// Call after rendering markdown
useEffect(() => {
  hydrateAdmonitionIcons();
}, [markdownContent]);

HTML output with Lucide icons enabled:

<div class="admonition admonition-note">
  <div class="admonition-title">
    <span class="admonition-icon admonition-icon-lucide" data-lucide-icon="LuStickyNote"></span>
    Note
  </div>
  <div class="admonition-content">
    Content here
  </div>
</div>

Symmetry Principles

This plugin enforces symmetry principles to ensure proper HTML structure and consistent behaviour:

  • Render Function Pairs: Custom render functions must provide both open and close together. Providing only one will result in a validation error.
  • Syntax Styles: At least one of obsidianStyle or docusaurusStyle must be enabled. Both are enabled by default.
  • Token Structure: Every opening token has a corresponding closing token with balanced nesting levels.
// ✅ Correct: Both open and close provided
customRenders: {
  note: {
    open: (tokens, idx, options, env, slf) => '<div class="custom">',
    close: (tokens, idx, options, env, slf) => '</div>'
  }
}

// ❌ Invalid: Only open provided (will throw TypeError)
customRenders: {
  note: {
    open: (tokens, idx, options, env, slf) => '<div class="custom">'
  }
}

Styling

The package includes default CSS files with attractive styling for all admonition types. Two versions are available:

  • admonitions.css - Full version with comments and formatting (recommended for development)
  • admonitions.min.css - Minified version for production use

In HTML

<!-- Development -->
<link rel="stylesheet" href="node_modules/markdown-it-admonitions/admonitions.css">

<!-- Production -->
<link rel="stylesheet" href="node_modules/markdown-it-admonitions/admonitions.min.css">

In JavaScript/TypeScript

// Development
import 'markdown-it-admonitions/admonitions.css';

// Production
import 'markdown-it-admonitions/admonitions.min.css';

Features

The default stylesheet includes:

  • Modern, clean design with subtle shadows and borders
  • Unique colour schemes for each admonition type:
    • Note: Blue theme
    • Tip: Green theme
    • Info: Cyan theme
    • Warning: Orange theme
    • Danger: Red theme
  • Automatic dark mode support via prefers-color-scheme
  • Responsive design for mobile devices
  • Print-friendly styles
  • Proper spacing for nested content (lists, code blocks, etc.)

Demo

You can preview all admonition styles by opening demo.html in your browser. The demo includes:

  • All five default admonition types
  • Examples with various content types (lists, code blocks, nested elements)
  • A theme toggle button to test dark mode

Customisation

You can override the default styles by adding your own CSS rules:

/* Example: Custom styling for note admonitions */
.admonition-note {
  border-left-color: #0066cc;
}

.admonition-note .admonition-title {
  background-colour: #e6f2ff;
  colour: #0066cc;
}

TypeScript

The plugin is written in TypeScript and includes full type definitions:

import type { AdmonitionPluginOptions } from 'markdown-it-admonitions';

const options: AdmonitionPluginOptions = {
  types: ['note', 'warning'],
  icons: {
    note: '📝'
  }
};

Development

# Install dependencies
npm install

# Build the package (includes CSS minification)
npm run build

# Build just the CSS (generates minified version)
npm run build:css

# Watch mode for development
npm run dev

Working with CSS

The minified CSS file (admonitions.min.css) is automatically generated from the source file (admonitions.css) during the build process.

Important: Only edit admonitions.css. The minified version is auto-generated and tracked in .gitignore.

When you make changes to admonitions.css:

  1. Edit the source CSS file
  2. Run npm run build:css to regenerate the minified version (or npm run build for full build)
  3. The minified version will be automatically created for distribution

License

MIT