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-it-anchor-sections

v1.0.1

Published

Create anchor sections from markdown headers

Readme

Tests NPM version Conventional Commits

Wrap markdown content in <section> tags automatically, grouped by header level, and hoisting or creating an anchor tag on the section; perfect for Intersection Observers, scroll-spying, or semantic styling without manual markup.

# Introduction

Hello world.

## Details

More info here.

renders to:

<section id="introduction">
	<h1>Introduction</h1>
	<p>Hello world.</p>
	<section id="details">
		<h2>Details</h2>
		<p>More info here.</p>
	</section>
</section>

The problem

Modern web layouts often require grouping content into logical blocks—for example, to trigger animations as sections enter the viewport or to build sticky navigation that knows which part of the page you're reading.

Markdown is inherently flat. While you can manually wrap blocks in <div> or <section> tags, it breaks the readability of the raw text and is prone to errors. markdown-it-anchor-sections bridges the gap by treating your header hierarchy as the source of truth for your document's structure.

Features

  • Hierarchical nesting — lower-level headers (like h3) are automatically nested within higher-level sections (like h2)
  • Attribute-aware — works seamlessly with markdown-it-attrs sections inherit the same IDs as their headers
  • Semantic HTML — produces clean, valid <section> structures that reflect your content's outline
  • Zero configuration — works out of the box with sensible defaults
  • Lightweight — tiny footprint with no external dependencies

Installation

Install via your preferred package manager:

yarn add markdown-it-anchor-sections
npm install markdown-it-anchor-sections
pnpm add markdown-it-anchor-sections
bun add markdown-it-anchor-sections

Usage

import md from "markdown-it";
import anchorSections from "markdown-it-anchor-sections";

const parser = md().use(anchorSections);

const src = `
# First header
lorem ipsum

## Second header
dolor sit amet
`;

console.log(parser.render(src));

With attributes

If you use markdown-it-attrs before this plugin, the generated <section> tags will inherit the id applied to the headers and retain any other attributes on the header.

import md from "markdown-it";
import attrs from "markdown-it-attrs";
import anchorSections from "markdown-it-anchor-sections";

const parser = md().use(attrs).use(anchorSections);

Markdown:

# Great stuff {.jumbotron #intro}

lorem ipsum

Output:

<section id="intro">
	<h1 class="jumbotron">Great stuff</h1>
	<p>lorem ipsum</p>
</section>

How it works

  1. Iterates through the token stream generated by markdown-it.
  2. When a header token is encountered, it identifies its level (1–6).
  3. Closes any open sections of the same or lower level.
  4. Opens a new <section> tag.
  5. If the header has attributes (classes, IDs, etc.), they are copied to the opening <section> tag.
  6. Automatically closes all remaining tags at the end of the document.

License

Apache 2.0 © Cassondra Roberts

Inspiration

This project was inspired by markdown-it-header-sections.