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

@mfyz/markdown-renderer-with-custom-directives

v1.0.7

Published

Zero-dependency markdown renderer with custom directives

Readme

@mfyz/markdown-renderer-with-custom-directives

A zero-dependency markdown renderer with support for custom directives. This package is part of the @mfyz/markdown-editor-with-custom-directives project.

Features

  • Zero dependencies
  • Support for basic markdown syntax (bold, italic, strikethrough, links)
  • Custom directives:
    • Color directive (:color[text]{#color})
    • Button directive (:button[text]{url=URL shape=SHAPE color=COLOR})
  • Multiple distribution formats (ESM, CommonJS, IIFE)
  • Tiny bundle size
  • Browser and Node.js support

Installation

npm install @mfyz/markdown-renderer-with-custom-directives

Usage

ES Modules

// Option 1: Named imports
import { renderESM } from '@mfyz/markdown-renderer-with-custom-directives'

const markdown =
  '**Bold** and :color[colored]{#ff0000} with :button[Click me]{url=https://example.com shape=pill color=blue}'
const html = renderESM(markdown)

// Option 2: Default import
import MarkdownRenderer from '@mfyz/markdown-renderer-with-custom-directives'

const html = MarkdownRenderer.render(markdown)

CommonJS

// Option 1: Destructuring
const { render } = require('@mfyz/markdown-renderer-with-custom-directives')

const markdown =
  '**Bold** and :color[colored]{#ff0000} with :button[Click me]{url=https://example.com shape=pill color=blue}'
const html = render(markdown)

// Option 2: Using the class
const { MarkdownRenderer } = require('@mfyz/markdown-renderer-with-custom-directives')

const html = MarkdownRenderer.render(markdown)

Browser

<script src="https://unpkg.com/@mfyz/markdown-renderer-with-custom-directives/dist/index.browser.js"></script>
<script>
  const markdown =
    '**Bold** and :color[colored]{#ff0000} with :button[Click me]{url=https://example.com shape=pill color=blue}'
  const html = MarkdownRenderer.render(markdown)
  document.getElementById('content').innerHTML = html
</script>

Custom Directives

Color Directive

The color directive allows you to add colored text:

:color[This text will be red]{#ff0000}

Button Directive

The button directive creates styled buttons with various presets:

:button[Click me]{url=https://example.com shape=pill color=blue}

Available button styles:

  • Shapes: pill, rounded, rect
  • Colors: blue, purple, green, red, yellow, gray

Example variations:

:button[Primary]{url=https://example.com shape=pill color=blue}
:button[Success]{url=https://example.com shape=rect color=green}
:button[Warning]{url=https://example.com shape=rounded color=yellow}

API Reference

render(markdown: string): string

Renders markdown text with custom directives into HTML.

Parameters:

  • markdown: The markdown text to render

Returns:

  • HTML string with rendered markdown and custom directives

Troubleshooting

Import Issues in Next.js or other ESM environments

If you encounter an error like:

Error: Module not found: ESM packages (@mfyz/markdown-renderer-with-custom-directives) need to be imported. Use 'import' to reference the package instead.

Make sure to use ES Module import syntax:

import { renderESM } from '@mfyz/markdown-renderer-with-custom-directives'

Import Issues in CommonJS environments

If you're working in a CommonJS environment (like a Node.js script), use require:

const { render } = require('@mfyz/markdown-renderer-with-custom-directives')

Development

# Install dependencies
npm install

# Run tests
npm test

# Build distribution files
npm run build

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

MIT License - see the LICENSE file for details.