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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mermaid-converter-core

v1.0.0

Published

Core library for converting Markdown with Mermaid diagrams to various formats

Readme

@mermaid-converter/core

Core library for converting Markdown with Mermaid diagrams to various formats.

Features

  • Plugin-based Architecture: Extensible system for output formats and diagram types
  • Built-in PDF Generation: High-quality PDF output with embedded diagrams
  • Mermaid Support: Full support for Mermaid diagram rendering
  • Performance Optimized: Browser pooling and intelligent caching
  • TypeScript Support: Full type definitions included

Installation

npm install @mermaid-converter/core

Quick Start

import { createConverter, PDFGenerator, MermaidRenderer } from '@mermaid-converter/core';

// Create converter with built-in plugins
const converter = createConverter();
converter.registerGenerator(new PDFGenerator());
converter.registerRenderer(new MermaidRenderer());

// Convert markdown with diagrams to PDF
const result = await converter.convert({
  content: `
# My Document

Here's a diagram:

\`\`\`mermaid
graph TD
    A[Start] --> B[Process]
    B --> C[End]
\`\`\`
  `,
  format: 'pdf'
});

// Result contains the PDF buffer
console.log('Generated PDF:', result.data.length, 'bytes');

API Reference

Core Classes

MarkdownMermaidConverter

Main converter class that orchestrates the conversion process.

const converter = new MarkdownMermaidConverter(config);

// Register plugins
converter.registerGenerator(new PDFGenerator());
converter.registerRenderer(new MermaidRenderer());

// Convert content
const result = await converter.convert({
  content: '# Test',
  format: 'pdf',
  options: { theme: 'dark' }
});

MarkdownParser

Parses markdown content and extracts diagrams.

const parser = new MarkdownParser();
const parsed = await parser.parse(markdownContent);

CacheManager

Manages caching of rendered diagrams for performance.

const cache = new CacheManager({
  enabled: true,
  maxSize: 100, // MB
  ttl: 3600 // seconds
});

Built-in Plugins

PDF Generator

Generates high-quality PDF files with embedded diagrams.

const pdfGenerator = new PDFGenerator();
converter.registerGenerator(pdfGenerator);

// Generate with options
const result = await converter.convert({
  content: markdown,
  format: 'pdf',
  options: {
    theme: 'dark',
    pageSize: 'A4',
    quality: 'high'
  }
});

Mermaid Renderer

Renders Mermaid diagrams to images.

const mermaidRenderer = new MermaidRenderer();
converter.registerRenderer(mermaidRenderer);

Configuration

const config = {
  generators: new Map(),
  renderers: new Map(),
  cache: {
    enabled: true,
    maxSize: 100, // MB
    ttl: 3600,    // seconds
    directory: './cache'
  },
  performance: {
    maxConcurrency: 3
  }
};

const converter = new MarkdownMermaidConverter(config);

Events

The converter emits events during processing:

converter.onEvent((event) => {
  switch (event.type) {
    case 'start':
      console.log('Conversion started');
      break;
    case 'progress':
      console.log('Progress:', event.data.message);
      break;
    case 'diagram_rendered':
      console.log('Diagram rendered:', event.data.diagramId);
      break;
    case 'complete':
      console.log('Conversion complete');
      break;
    case 'error':
      console.error('Error:', event.data.error);
      break;
  }
});

Creating Custom Plugins

Custom Output Generator

import { OutputGenerator } from '@mermaid-converter/core';

class CustomGenerator implements OutputGenerator {
  format = 'custom';
  name = 'Custom Generator';
  description = 'Custom output format';

  async generate(content, diagrams, options) {
    // Implement your custom generation logic
    return {
      format: 'custom',
      data: Buffer.from('custom output'),
      mimeType: 'application/custom'
    };
  }
}

converter.registerGenerator(new CustomGenerator());

Custom Diagram Renderer

import { DiagramRenderer } from '@mermaid-converter/core';

class CustomRenderer implements DiagramRenderer {
  supportedTypes = ['custom-diagram'];

  async render(diagram, options) {
    // Implement your custom rendering logic
    return {
      info: diagram,
      imageData: Buffer.from('image data'),
      format: 'png',
      dimensions: { width: 800, height: 600 },
      dataUrl: 'data:image/png;base64,...'
    };
  }

  async validate(code, type) {
    return { valid: true, errors: [], warnings: [] };
  }
}

converter.registerRenderer(new CustomRenderer());

Requirements

  • Node.js 16+
  • Modern browser support (uses Puppeteer)

License

MIT