Markdown Fetch

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

MIT-0 · Free to use, modify, and redistribute. No attribution required.
1 · 1.8k · 15 current installs · 16 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
The name/description (request Markdown to save tokens) matches the code and instructions. The files only implement an optimizedFetch, batchFetch, and simple HTML fallback; nothing requests unrelated capabilities or credentials.
Instruction Scope
SKILL.md recommends finding and updating HTTP requests (fetch/axios/request) to add the Accept header and to treat text/markdown responses specially. That is within the stated purpose, but it implies a code-wide change — reviewers should manually confirm changes rather than blindly applying them across all requests because altering every request can change behavior for endpoints that expect other Accept headers.
Install Mechanism
There is no install spec and no external downloads; this is instruction + small JS module only, so nothing will be written to disk by an installer. Low risk from installation mechanisms.
Credentials
The skill requests no environment variables, no credentials, and no config paths. The code makes outgoing HTTP requests to whatever URL you call it with; there are no hidden or hard-coded endpoints or secret-access calls.
Persistence & Privilege
The skill is not marked always:true and does not modify other skills or system settings. It contains only library functions and a test harness — no persistent or privileged behavior is requested.
Assessment
This skill is internally consistent and small: it simply sets an Accept header and returns markdown when available. Before adopting it broadly: 1) Review and apply its changes manually (don't automatically rewrite every HTTP call) because changing Accept headers can alter server behavior; 2) Test in staging — not all sites support text/markdown and behavior may differ; 3) Verify your runtime provides a global fetch (or adapt to node-fetch/axios) so nothing breaks; 4) Note the skill will perform network fetches to URLs you pass it — ensure you don't unintentionally fetch internal endpoints. No secrets are requested by the skill, and there are no hidden endpoints in the code.

Like a lobster shell, security has layers — review code before you run it.

Current versionv1.0.0
Download zip
latestvk97ddenwdsyvad9e86a3bmkjx9813m0w

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

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 响应。

Files

3 total
Select a file
Select a file to preview.

Comments

Loading comments…