使用 Readability + Turndown 将 HTML 页面转换为干净的、Agent 友好的 Markdown。去除导航栏、广告、页脚、Cookie 横幅、社交按钮等干扰元素。支持 URL...
Aggressive HTML-to-markdown converter for AI agents. Mozilla Readability isolates main content, Turndown converts to markdown, then heavy post-processing strips remaining noise.
Full flag reference and advanced examples:
references/usage.md
bash
cd <skill-dir>/scripts
npm install
npm link # makes `html2md` globally available
Requires Node.js 22+.
bash
html2md https://example.com # fetch + convert
html2md --file page.html # local HTML file
cat page.html | html2md --stdin # pipe from stdin
html2md --max-tokens 2000 https://example.com # budget-aware truncation
html2md --no-links https://example.com # strip hrefs, keep text
html2md --json https://example.com # JSON: {title, url, markdown, tokens}
<body> when Readability returns too little (e.g. HN's table layout).--max-tokens N keeps all headings, fills remaining budget in document order, appends [truncated — N more tokens]. Uses 1 token ≈ 4 chars heuristic.--json for programmatic use.web_fetch#Use html2md whenUse web_fetch whenReading pages in cron jobs / sub-agentsQuick one-off fetch in main sessionToken budget matters ( --max-tokens)Page is a JSON/XML API endpointHeavy nav/ads/footers to stripJS rendering not neededNeed JSON outputSimple pages
html2md fetches URLs and reads local files — that's its job. If you're passing untrusted input:
--file reads any path the process can access. In agent workflows, the agent controls the path — this is equivalent to the agent using cat.execFileSync (not execSync) to avoid shell injection.bash
# Read a Paul Graham essay within 2000 tokens
html2md --max-tokens 2000 https://paulgraham.com/greatwork.html
# HN front page as clean text, no link noise
html2md --no-links --no-images https://news.ycombinator.com
# Get token count before committing
html2md --json https://example.com | jq .tokens
# Pipe to file
html2md https://docs.example.com/api > api-docs.md