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

dom2md

v0.2.0

Published

Convert the live DOM of a page to Markdown. Heuristic, dependency-free, works in the browser and as a content script.

Readme

dom2md

Turn the live DOM of a page into Markdown. Heuristic, dependency-free, and tiny — designed to run in the browser (as a <script> tag or a content script), not on a server.

It walks the DOM, collects leaf text blocks plus structural elements (tables, lists with nesting/numbering, <hr>, <audio>/<video>), drops boilerplate (nav/footer/aside, ads, chat/cookie widgets), and derives heading levels (#–######) from each heading's font size relative to the page's base font.

Install

npm install dom2md

Usage

ESM / CJS

import { dom2md } from 'dom2md';
// const { dom2md } = require('dom2md');  // CommonJS

const markdown = dom2md();                 // converts document.body
const partial  = dom2md({ root: document.querySelector('article') });

Browser <script> tag

The package ships a standalone build at dom2md/global (dist/dom2md.global.js). Include it and call the global dom2md():

<script src="node_modules/dom2md/dist/dom2md.global.js"></script>
<script>
  const md = dom2md();
</script>

(It also exposes window.dom2md.)

Content script (browser extension)

Because the standalone build defines window.dom2md, you can drop it into a content_scripts entry exactly like the original extension:

{
  "content_scripts": [
    { "matches": ["<all_urls>"], "js": ["dom2md.global.js", "content.js"] }
  ]
}
// content.js — dom2md() is now a global
button.onclick = () => {
  const markdown = dom2md();
  // ...
};

API

dom2md(options?)

Returns the page (or subtree) as a Markdown string.

interface Options {
  root?: Node | null;      // root to convert, defaults to document.body
  minTextLength?: number;  // minimum text length to keep a block, defaults to 2
}

How it works

  1. Collect leaf text blocks (elements with text and no block-level children) and structural elements.
  2. Filter hidden / zero-sized blocks and boilerplate (nav/footer/aside, ad/chat/cookie widgets by id/class).
  3. Classify text blocks: headings (level from font size vs. the page's base font), quotes, code, paragraphs.
  4. Render Markdown with inline formatting (bold/italic/code/links/images), escaping literal special characters.

Build

npm install
npm run build   # emits dist/ (esm + cjs + iife + types)

dist/ is committed so consumers can grab dist/dom2md.global.js directly from the package without building.

License

MIT