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

reread-markdown

v1.0.0

Published

A Markdown parser for extracting hierarchical information.

Downloads

2

Readme

reread-markdown

To turn markdown files into structured, queryable data. The input Markdown file is transformed into a special tree exposing the structure intended by the author of the file: the table of contents (TOC). For each key (heading) in the TOC, you get both the title and the related contents under this title. You don't only get titles. Then, you can easily extract whole parts of the original document.

Markdown isn’t just text. It's a source of structured information.

Heading nodes are the primary focus of this library. They are retrieved, enriched and organized to form a new tree. The input document is crawled and indexed by headings. The other components of the input Markdown file are seen as heading attributes. Output heading nodes have two main attributes: their title and the related contents (raw text or tokens).

Agnostic. Versatile. Generic.

Examples in the Node environment

example.md

This is the *introduction*.

# Part One

Bla bla.

## *Title*

1, 2, 3.

### Chapter

A, B, C.

###### Section

i, ii, iii.

A code example with `#` characters..

```python

# This is a comment
def reread():
    print("Detect patterns.")

```

# **Part** *Two*
## Another Title

Last but not least.

Code example

import { readFileSync } from 'node:fs';
import {reread} from "reread-markdown"

const text = readFileSync("./example.md", "utf8")

console.log(reread(text).toJSON())

Output

{
  "data": {
    "title": "",
    "depth": 0,
    "contents": "\nThis is the *introduction*.\n\n"
  },
  "children": [
    {
      "data": {
        "title": "# Part One",
        "depth": 1,
        "contents": "\n\nBla bla.\n\n"
      },
      "children": [
        {
          "data": {
            "title": "## *Title*",
            "depth": 2,
            "contents": "\n\n1, 2, 3.\n\n"
          },
          "children": [
            {
              "data": {
                "title": "### Chapter",
                "depth": 3,
                "contents": "\n\nA, B, C.\n\n"
              },
              "children": [
                {
                  "data": {
                    "title": "###### Section",
                    "depth": 6,
                    "contents": "\n\ni, ii, iii.\n\nA code example with `#` characters..\n\n```python\n\n# This is a comment\ndef reread():\n    print(\"Detect patterns.\")\n\n```\n\n"
                  },
                  "children": []
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "data": {
        "title": "# **Part** *Two*",
        "depth": 1,
        "contents": "\n"
      },
      "children": [
        {
          "data": {
            "title": "## Another Title",
            "depth": 2,
            "contents": "\n\nLast but not least.\n"
          },
          "children": []
        }
      ]
    }
  ]
}

Workflow

  1. mdast-util-from-markdown is used for parsing the input Markdown text. The resulting syntax tree complies with the specification defined by mdast.
  2. This syntax tree is visited (walked, traversed, crawled) by a Visitor object accumulating state in order to produce a new tree.
  3. This new tree allows you to reread Markdown (AST transformation). It exposes the hierarchical structure of the document and enables you to extract parts for further processing.
  4. You can optionally retrieve each part in the form of a list of tokens. Tokens are labelled fragments of text (strings of characters). They are suitable for natural language processing (NLP) or PDF generation.

Related Projects

There is a similar service in Visual Studio Code (range folding).

  • https://github.com/microsoft/vscode-markdown-languageservice
  • https://github.com/microsoft/vscode-markdown-languageservice/blob/main/src/tableOfContents.ts

VS Code uses an alternative technique for getting the same result. No tree traversal. VS Code uses markdown-it. Headers are first extracted with location and depth information. The resulting list of size n is scanned n times for extracting the hierarchical information...

About Markdown

https://commonmark.org

https://commonmark.org/help

https://github.com/syntax-tree/unist

https://github.com/syntax-tree/mdast