markdown-fetch

Optimizes web fetching by using Cloudflare's Markdown for Agents, reducing token consumption by ~80%

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "markdown-fetch" with this command: npx skills add howtimeschange/markdown-fetch

Markdown Fetch - 网页抓取优化

背景

Cloudflare 推出 Markdown for Agents 功能:

  • AI 请求时返回 Markdown 格式
  • Token 消耗比 HTML 减少约 80%

使用方法

在需要网页抓取时,使用优化后的 fetch 函数:

const { optimizedFetch } = require('./markdown-fetch');

const result = await optimizedFetch('https://example.com');
// result.markdown - Markdown 内容(如果有)
// result.html - HTML 内容(备用)
// result.tokensSaved - 节省的 tokens(如果有)

核心逻辑

async function optimizedFetch(url, options = {}) {
  const headers = {
    'Accept': 'text/markdown, text/html',
    ...options.headers
  };

  const response = await fetch(url, { ...options, headers });
  
  const contentType = response.headers.get('content-type');
  const xMarkdownTokens = response.headers.get('x-markdown-tokens');
  
  let result = {
    url,
    contentType,
    tokensSaved: xMarkdownTokens ? parseInt(xMarkdownTokens) : null
  };
  
  if (contentType.includes('text/markdown')) {
    result.markdown = await response.text();
    result.format = 'markdown';
  } else {
    result.html = await response.text();
    result.format = 'html';
  }
  
  return result;
}

响应处理

Content-Type处理方式
text/markdown直接使用,跳过 HTML 解析
text/html走原有解析逻辑

可选:x-markdown-tokens 日志

如果响应中有 x-markdown-tokens header,记录到日志:

if (result.tokensSaved) {
  console.log(`[Markdown Fetch] Token 节省: ${result.tokensSaved}`);
}

改动范围

  1. 找到所有 HTTP 请求(fetch/axios/request)
  2. 统一添加 header
  3. 响应处理加判断

测试验证

找一个 Cloudflare 托管的网站测试:

curl -H "Accept: text/markdown, text/html" https://cloudflare-example.com

确认收到 content-type: text/markdown 响应。

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

技能编辑器

编辑、完善或审查 AgentSkills。当需要创建新技能、对现有 SKILL.md 进行修改、清理/审计/整理技能文件时激活此技能。触发词:编辑技能, skill 注意事项, metadata 检查, 完善技能, 清理技能, 审计技能, skill 规范, 编写 skill, 新建技能

Registry SourceRecently Updated
Automation

全闭环管道

全闭环自动化管道 — Hunter→Skill Factory→Orchestrator→Dashboard→Profit。将Phase 1-3所有组件串联为自动运行的超级管道。核心能力:(1) 一键全流程 (2) 定时自动运行 (3) 异常自愈 (4) 利润报告

Registry SourceRecently Updated
Automation

智美人AI实战课

《智美人AI Agent实战课》配套技能——从0到1搭建AI Agent的完整课程体系。第01节:AI Agent基础概念+工具链搭建。课程内容含数字人讲解视频、实战代码、课后练习。覆盖:OpenClaw配置、技能安装、MCP工具、多Agent协同、变现实战。

Registry SourceRecently Updated
Automation

利润优化引擎

利润优化引擎 — 订单管理/计价/结算模拟。核心能力:(1) 订单管理 (2) 计价模型 (3) 成本追踪 (4) 利润计算

Registry SourceRecently Updated