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

@bernierllc/markdown-detector

v0.2.2

Published

Detects markdown flavor (MDX, GFM, standard, frontmatter) and extracts metadata with high confidence.

Readme

@bernierllc/markdown-detector

A pure TypeScript package for detecting markdown flavor (MDX, GFM, standard, frontmatter) and extracting metadata with high confidence. No rendering or React/remark/rehype dependencies.

Features

  • 🔄 Automatic Detection: Detects markdown flavor based on content analysis
  • 📝 Multi-Flavor Support: MDX, GFM, standard markdown, and frontmatter
  • 🎯 High Confidence: Provides confidence scores and suggestions
  • ⚡ Performance: Optimized for large content with efficient regex patterns
  • 🛡️ Edge Case Handling: Robust detection with comprehensive test coverage
  • 🔧 Configurable: Flexible for custom detection needs
  • 🪶 Lightweight: No rendering or heavy dependencies

Installation

npm install @bernierllc/markdown-detector

Quick Start

Basic Usage

import { MarkdownDetector } from '@bernierllc/markdown-detector';

const content = `
# My Document

This is **bold** and *italic* text.

<MyComponent prop="value" />
`;

const result = MarkdownDetector.detect(content);
console.log(result.flavor); // 'mdx'
console.log(result.confidence); // 0.95
console.log(result.suggestions); // [ ... ]

API Reference

MarkdownDetector.detect(content: string): DetectionResult

Detects the markdown flavor and extracts metadata.

Returns:

  • flavor: 'mdx' | 'gfm' | 'standard' | 'markdown-with-frontmatter'
  • confidence: number (0.0 - 1.0)
  • features: detailed feature analysis
  • suggestions: helpful suggestions for processing

Types

export type MarkdownFlavor =
  | 'auto'
  | 'standard'
  | 'gfm'
  | 'mdx'
  | 'markdown-with-frontmatter';

export interface DetectionResult {
  flavor: MarkdownFlavor;
  confidence: number;
  features: {
    hasFrontmatter: boolean;
    hasJSX: boolean;
    hasGFM: boolean;
    hasCodeBlocks: boolean;
    hasTables: boolean;
    hasMath: boolean;
    // ...more
  };
  suggestions: string[];
}

Detection Features

  • MDX: JSX tags, expressions, comments, fragments, import/export, hooks
  • GFM: Tables, strikethrough, task lists, autolinks, emoji, mentions, issues
  • Frontmatter: YAML at start, valid key-value pairs, arrays, nested objects
  • Standard: Headers, emphasis, lists, links, images, code blocks
  • Edge Cases: Handles code blocks, invalid frontmatter, HTML vs JSX, large content, unicode, special characters, conflicting features

Example: Detecting Uploaded Markdown

import { MarkdownDetector } from '@bernierllc/markdown-detector';

function handleUpload(content: string) {
  const detection = MarkdownDetector.detect(content);
  // Store detection.flavor and detection.confidence as metadata
  // Route or process content accordingly
}

Performance

  • Regex optimization: Efficient patterns
  • Early termination: Stops when confident
  • Memory efficient: Line-by-line processing

Testing

npm test
npm run test:coverage
  • Unit tests: All detection methods
  • Integration tests: Full detection pipeline
  • Edge case tests: Boundary and error cases
  • Performance tests: Large and complex content

License

This package is licensed under the Bernier LLC license. See LICENSE file for details.