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

markdown-block-extractor

v1.0.0

Published

A TypeScript library for extracting structured blocks and media items from markdown content. Optimized for React and Vite.

Readme

Markdown Block Extractor

A TypeScript/Deno library for extracting structured blocks and media items from markdown content. This library processes markdown with custom block markers and extracts both regular content blocks and media items with detailed metadata.

Features

  • Block Extraction: Extract content blocks marked with HTML comments
  • Media Detection: Automatically detect images and videos in both markdown and HTML syntax
  • Rich Metadata: Generate detailed metadata for each block including word count, line count, and content features
  • TypeScript Support: Full TypeScript definitions included
  • React/Vite Optimized: Built with Vite for optimal bundling in modern React applications
  • Tree Shakeable: ES modules with proper exports for efficient bundling
  • Deno Compatible: Works with Deno runtime and can be published to JSR

Installation

NPM (React/Vite/Node.js)

npm install markdown-block-extractor
import { parse } from "markdown-block-extractor";

React Usage

import React, { useEffect, useState } from 'react';
import { parse, type ParseResult } from 'markdown-block-extractor';

function MarkdownProcessor() {
  const [result, setResult] = useState<ParseResult | null>(null);
  
  useEffect(() => {
    const markdown = `<!-- block:id=1 -->
# My Block
![Image](https://example.com/image.jpg)
Some content here.
<!-- end-block:id=1 -->`;
    
    const parsed = parse(markdown);
    setResult(parsed);
  }, []);
  
  return (
    <div>
      {result?.blockExtracts.map(block => (
        <div key={block.id}>
          <h3>Block {block.id}</h3>
          <p>Word count: {block.metadata.wordCount}</p>
          <p>Has images: {block.metadata.hasImages ? 'Yes' : 'No'}</p>
        </div>
      ))}
    </div>
  );
}

Deno/JSR

import { parse } from "jsr:@your-username/markdown-block-extractor";

Usage

import { parse } from 'markdown-block-extractor';

const markdown = `<!-- block:id=1 -->
# My Block
![Image](https://example.com/image.jpg)
Some content here.
<!-- end-block:id=1 -->`;

const result = parse(markdown);

console.log(result.blockExtracts);
// [
//   {
//     id: "1",
//     type: "block",
//     markdown: "# My Block\n![Image](https://example.com/image.jpg)\nSome content here.",
//     mediaItems: [
//       {
//         type: "image",
//         url: "https://example.com/image.jpg",
//         syntax: "markdown"
//       }
//     ],
//     metadata: {
//       lineCount: 3,
//       hasImages: true,
//       hasVideos: false,
//       hasCodeBlocks: false,
//       hasTables: false,
//       hasLists: false,
//       hasLinks: false,
//       wordCount: 4,
//       characterCount: 50
//     }
//   }
// ]

Block Syntax

The library recognizes two types of blocks:

Regular Blocks

<!-- block:id=1 -->
Your content here
<!-- end-block:id=1 -->

Custom Blocks

<!-- custom-block:id=2 -->
Your content here
<!-- end-custom-block:id=2 -->

API Reference

parse(markdown: string): ParseResult

Parses markdown content and returns extracted blocks and media items.

Parameters:

  • markdown (string): The markdown content to parse

Returns:

  • ParseResult: Object containing:
    • blockExtracts: Array of extracted blocks
    • mediaItems: Array of all media items found
    • ast: The parsed AST tree

Types

BlockExtract

interface BlockExtract {
  id: string;
  type: 'block' | 'customBlock';
  markdown: string;
  mediaItems: MediaItem[];
  metadata: BlockMetadata;
  position?: Position;
}

MediaItem

interface MediaItem {
  type: 'image' | 'video';
  url: string;
  alt?: string;
  title?: string;
  blockId?: string;
  blockType?: string;
  position?: Position;
  syntax: 'markdown' | 'html';
}

BlockMetadata

interface BlockMetadata {
  lineCount: number;
  hasImages: boolean;
  hasVideos: boolean;
  hasCodeBlocks: boolean;
  hasTables: boolean;
  hasLists: boolean;
  hasLinks: boolean;
  wordCount: number;
  characterCount: number;
}

Development

Running the Example

deno task example
# or
deno run --allow-read examples/example.ts

Running Tests

deno task test
# or
deno test --allow-read --allow-write tests/

Building

deno task build
# or
deno check index.ts

Development Mode

deno task dev
# Runs the example in watch mode

Project Structure

markdown-block-extractor/
├── src/                    # Source code
│   ├── index.ts           # Main library entry point
│   ├── types/             # TypeScript type definitions
│   │   └── index.ts
│   ├── utils.ts           # Shared utility functions
│   └── plugins/           # Remark plugins
│       ├── remark-block-extractor.ts
│       ├── remark-custom-blocks.ts
│       ├── remark-media-extractor.ts
│       └── remark-orphan-content-wrapper.ts
├── tests/                 # Test files
│   └── test.ts
├── examples/              # Example usage
│   └── example.ts
├── index.ts              # Library entry point (re-exports from src/)
├── deno.json             # Deno configuration
└── README.md

License

This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License (CC-BY-NC-4.0).

Important: This license prohibits commercial use. You may use this library for personal, educational, or non-commercial projects, but commercial use requires explicit permission from the copyright holder.

For commercial licensing inquiries, please contact the author.