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

@sarchauhan/code-markdown

v0.0.3

Published

A React component for beautiful code snippets with syntax highlighting and theming

Readme

code-markdown

A React component for rendering themeable code blocks with syntax highlighting, optional line numbers, line highlighting, and copy-to-clipboard.

Features

  • Syntax highlighting
  • Multiple built-in themes
  • Optional line numbers (showLineNumbers or lineNumbers)
  • Line highlighting
  • Copy button
  • Optional PNG/JPG export
  • Custom font and styles
  • Grammar-driven tokenizer registry for custom language support

Installation

Install the package with your package manager:

bun add @sarchauhan/code-markdown
npm install @sarchauhan/code-markdown
pnpm add @sarchauhan/code-markdown

Import the component and stylesheet once in your app:

import { CodeMarkdown } from "@sarchauhan/code-markdown";
import "@sarchauhan/code-markdown/styles.css";

Usage

import { CodeMarkdown } from "@sarchauhan/code-markdown";
import "@sarchauhan/code-markdown/styles.css";

export function App() {
  return (
    <CodeMarkdown
      theme="catppuccin-mocha"
      language="tsx"
      showLineNumbers
      showExportButtons
      highlightLines={[2, 3]}
    >
      {`const hello = "world";`}
    </CodeMarkdown>
  );
}

Examples

Python

<CodeMarkdown language="python">
  {`def greet(name):
    return f"hello, {name}"

print(greet("Ada"))`}
</CodeMarkdown>

Go

<CodeMarkdown language="go">
  {`package main

import "fmt"

func main() {
    fmt.Println("hello, go")
}`}
</CodeMarkdown>

Rust

<CodeMarkdown language="rust">
  {`fn main() {
    let name = "Ferris";
    println!("hello, {name}");
}`}
</CodeMarkdown>

C++

<CodeMarkdown language="cpp">
  {`#include <iostream>

int main() {
    std::cout << "hello, c++\\n";
    return 0;
}`}
</CodeMarkdown>

Grammars

Language definitions live under src/grammars. The tokenizer stays unified in src/highlighter.ts, and each grammar file only declares language rules:

  • aliases / language names
  • keywords
  • comment prefixes
  • string delimiters
  • identifier and number patterns
  • punctuation and operator rules

Add a new grammar file and register it in src/grammars/index.ts.

Props

| Prop | Type | Default | Description | | --- | --- | --- | --- | | children | string | required | Code to render | | theme | CodeTheme \| BuiltinThemeName | "catppuccin-mocha" | Theme object or built-in theme name | | font | string | "JetBrains Mono", "Fira Code", monospace | Font family | | language | SupportedLanguage | typescript | Language name or alias | | showLineNumbers | boolean | false | Show line numbers | | lineNumbers | boolean | false | Alias for showLineNumbers | | showCopyButton | boolean | true | Show copy button | | showExportButtons | boolean | false | Show PNG/JPG export buttons | | showLanguage | boolean | true | Show language label | | exportFileName | string | "code-snippet" | Base filename used for image downloads | | highlightLines | number[] | [] | Highlight specific lines | | className | string | - | Extra class name | | style | React.CSSProperties | - | Inline styles |

Supported languages

The built-in grammars support these language names and aliases:

  • C: c, h
  • C++: cpp, cxx, cc, hpp, hxx
  • Go: go
  • JavaScript: javascript, js, jsx, mjs
  • Python: python, py
  • Rust: rust, rs
  • TypeScript: typescript, ts, tsx

Themes

Built-in theme names are lazy-loaded by the component:

  • "catppuccin-mocha"
  • "catppuccin-macchiato"
  • "catppuccin-frappe"
  • "catppuccin-latte"
  • "anysphere"

Theme objects are still exported from the package if you want to import them directly:

  • catppuccinMocha
  • catppuccinMacchiato
  • catppuccinFrappe
  • catppuccinLatte
  • anysphereTheme / anySphereTheme

License

MIT