cloudflare-markdown

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloudflare Markdown Rendering

Cloudflare Markdown 渲染

Renders web pages or raw HTML content to Markdown using Cloudflare Browser Rendering API.
借助Cloudflare Browser Rendering API将网页或原始HTML内容转换为Markdown格式。

Usage

使用方法

Convert a URL to Markdown:
bash
bash render.bash --url "https://example.com"
Convert raw HTML to Markdown:
bash
bash render.bash --html "<div>Hello World</div>"
将URL转换为Markdown:
bash
bash render.bash --url "https://example.com"
将原始HTML转换为Markdown:
bash
bash render.bash --html "<div>Hello World</div>"

Options

选项

OptionDescription
--url URL
URL to fetch and convert to Markdown
--html HTML
Raw HTML content to convert to Markdown
--wait-until TYPE
Page load behavior:
load
,
domcontentloaded
,
networkidle0
,
networkidle2
--reject PATTERN
Reject request patterns (regex, can be specified multiple times)
--user-agent UA
Custom user agent string
--help
Show help message
选项说明
--url URL
要抓取并转换为Markdown的URL
--html HTML
要转换为Markdown的原始HTML内容
--wait-until TYPE
页面加载行为:
load
domcontentloaded
networkidle0
networkidle2
--reject PATTERN
要拒绝的请求模式(正则表达式,可多次指定)
--user-agent UA
自定义用户代理字符串
--help
显示帮助信息

Examples

示例

Basic URL conversion

基础URL转换

bash
bash render.bash --url "https://developers.cloudflare.com/"
bash
bash render.bash --url "https://developers.cloudflare.com/"

JavaScript-heavy pages

含大量JavaScript的页面

For SPAs or JS-heavy pages, use
networkidle0
or
networkidle2
:
bash
bash render.bash --url "https://spa-example.com" --wait-until networkidle0
对于单页应用(SPA)或含大量JavaScript的页面,使用
networkidle0
networkidle2
bash
bash render.bash --url "https://spa-example.com" --wait-until networkidle0

Exclude CSS requests

排除CSS请求

bash
bash render.bash --url "https://example.com" --reject '/^.*\.(css)/'
bash
bash render.bash --url "https://example.com" --reject '/^.*\.(css)/'

Custom user agent

自定义用户代理

bash
bash render.bash --url "https://example.com" --user-agent "Mozilla/5.0 (compatible; MyBot/1.0)"
bash
bash render.bash --url "https://example.com" --user-agent "Mozilla/5.0 (compatible; MyBot/1.0)"

Credentials

凭证

Credentials are retrieved from macOS Keychain:
  • CLOUDFLARE_ACCOUNT_ID
    - Cloudflare account ID
  • CLOUDFLARE_MARKDOWN_API_KEY
    - Cloudflare API token with Browser Rendering permissions
To store credentials:
bash
security add-generic-password -s CLOUDFLARE_ACCOUNT_ID -a CLOUDFLARE_ACCOUNT_ID -w "your-account-id"
security add-generic-password -s CLOUDFLARE_MARKDOWN_API_KEY -a CLOUDFLARE_MARKDOWN_API_KEY -w "your-api-token"
凭证从macOS钥匙串中获取:
  • CLOUDFLARE_ACCOUNT_ID
    - Cloudflare账户ID
  • CLOUDFLARE_MARKDOWN_API_KEY
    - 拥有Browser Rendering权限的Cloudflare API令牌
存储凭证的方法:
bash
security add-generic-password -s CLOUDFLARE_ACCOUNT_ID -a CLOUDFLARE_ACCOUNT_ID -w "your-account-id"
security add-generic-password -s CLOUDFLARE_MARKDOWN_API_KEY -a CLOUDFLARE_MARKDOWN_API_KEY -w "your-api-token"

Output

输出

Returns JSON response from Cloudflare API:
json
{
  "success": true,
  "result": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
返回来自Cloudflare API的JSON响应:
json
{
  "success": true,
  "result": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}

Requirements

依赖要求

  • jq
    for JSON processing
  • curl
    for HTTP requests
  • macOS Keychain with stored credentials
  • jq
    用于JSON处理
  • curl
    用于HTTP请求
  • 已存储凭证的macOS钥匙串