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

html2md4llm

v1.2.0

Published

Convert HTML to clean Markdown or JSON, optimized for LLM processing

Readme

html2md4llm

把 HTML 转成更干净的 Markdown 或 JSON,便于人和 AI 直接消费。

安装

npm install html2md4llm

最常用方式

1) 在代码中调用

import { main } from 'html2md4llm';

const html = '<h1>Hello</h1><p>World</p>';
const md = main(html); // 默认输出 markdown
console.log(md);

输出 JSON:

const json = main('<h1>Hello</h1>', { outputFormat: 'json' });

2) 用 npx 当命令行工具

本地文件转 .md

npx html2md4llm ./input.html ./output.md

stdin -> stdout(Linux 管道):

cat ./input.html | npx html2md4llm > ./output.md

API(给代码/AI 调用)

main(htmlInput, options?)

  • htmlInput: string:HTML 字符串
  • options.outputFormat: 'markdown' | 'json':默认 'markdown'
  • options.strategy: 'list' | 'article':可选提取策略
  • options.removeAttributes: string[]:按规则移除属性,如 ['aria-*', 'role']
  • options.unescapeHTML: 'auto' | true | false:默认 'auto'auto 时若输入去首尾空白后以 &lt; 开头且 &gt; 结尾,会先做一次全量 unescape。

返回值:string(Markdown 文本或 JSON 字符串)

CLI 参数

html2md4llm <input.html> [output.md] [options]
html2md4llm - [output.md] [options]
  • -o, --output <file>:输出文件路径
  • -f, --format <markdown|json>:输出格式
  • --json:等价于 --format json
  • --markdown:等价于 --format markdown
  • -s, --strategy <list|article>:内容提取策略
  • -u, --unescape-html <auto|true|false>:输入 HTML 反转义策略(默认 auto
  • -r, --remove-attrs <attrs>:逗号分隔,如 aria-*,role
  • -h, --help:查看帮助
  • -v, --version:查看版本

AI 使用建议

如果你在 Agent/工作流里调用这个工具,推荐固定约定:

  1. 输入始终传完整 HTML 字符串。
  2. 需要结构化消费时使用 outputFormat: 'json'
  3. 需要最简正文时按场景加 strategy: 'article'strategy: 'list'
  4. 需要清理无关属性时传 removeAttributes,例如 ['aria-*', 'role', 'data-*']
  5. 输入可能是转义 HTML(如 &lt;h1&gt;Hello&lt;/h1&gt;)时,保持默认 unescapeHTML: 'auto';若要强制关闭则传 false

开发

npm test

License

MIT