Install
openclaw skills install @sipingme/html-to-markdown-skill将 HTML 内容转换为 Markdown 格式,支持字符串、文件和 URL 转换
openclaw skills install @sipingme/html-to-markdown-skill将 HTML 内容转换为 Markdown 格式的 ClawHub Skill。
本 Skill 是一个 npm 包集成配置,实际功能由 @siping/html-to-markdown-node npm 包提供。
OpenClaw/AI Agent
↓ (读取 Skill 配置)
html-to-markdown-skill
↓ (调用 npm 包)
@siping/html-to-markdown-node
↓ (转换 HTML)
Markdown 输出
当用户需要将 HTML 内容转换为 Markdown 格式时,AI 会自动调用相应的命令:
触发关键词:
# 安装 npm 包
npm install -g @siping/html-to-markdown-node
# 或在项目中安装
npm install @siping/html-to-markdown-node
# 克隆 Skill 配置和文档
git clone https://github.com/sipingme/html-to-markdown-skill.git
cp -r html-to-markdown-skill ~/.openclaw/skills/html-to-markdown/
场景:用户提供 HTML 代码片段,需要转换为 Markdown
命令:convert
步骤:
示例:
html2md convert \
--html '<strong>Bold Text</strong>' \
--domain 'https://example.com'
输出示例:
{
"success": true,
"markdown": "**Bold Text**",
"length": 13
}
异常处理:
场景:用户有 HTML 文件需要转换为 Markdown 文件
命令:convert-file
步骤:
示例:
html2md convert-file \
--input /path/to/input.html \
--output /path/to/output.md \
--domain 'https://example.com'
输出示例:
{
"success": true,
"message": "转换成功: /path/to/output.md",
"inputFile": "/path/to/input.html",
"outputFile": "/path/to/output.md",
"length": 1234
}
异常处理:
场景:用户想抓取网页内容并转换为 Markdown
命令:convert-url
步骤:
示例:
# 转换整个页面
html2md convert-url \
--url 'https://example.com/article'
# 只提取特定区域
html2md convert-url \
--url 'https://example.com/article' \
--selector 'article.content'
输出示例:
{
"success": true,
"markdown": "# Article Title\n\nContent...",
"url": "https://example.com/article",
"length": 5678
}
异常处理:
所有命令统一使用 JSON 格式输出:
成功响应:
{
"success": true,
"markdown": "转换后的 Markdown 内容",
"length": 1234
}
错误响应:
{
"success": false,
"error": "错误信息"
}
https://example.comsmart(默认)、disabledsmart:智能转义特殊字符disabled:禁用转义article.content、#main、.post-body用户:帮我把这段 HTML 转换为 Markdown:<h1>Title</h1><p>Content</p>
AI:好的,我来帮你转换。
[执行命令]
html2md convert --html '<h1>Title</h1><p>Content</p>'
AI:✅ 转换完成!
# Title
Content
用户:帮我把这个网页保存为 Markdown:https://example.com/blog/post
AI:好的,我来抓取并转换这个网页。
[执行命令]
html2md convert-url --url 'https://example.com/blog/post'
AI:✅ 网页已转换为 Markdown!
用户:把 docs 文件夹下的所有 HTML 文件转换为 Markdown
AI:好的,我来批量转换。
[执行命令]
for file in docs/*.html; do
html2md convert-file \
--input "$file" \
--output "${file%.html}.md"
done
AI:✅ 已转换 5 个文件!
症状:图片或链接显示为相对路径
解决:
html2md convert --html '...' --domain 'https://example.com'
症状:输出的 Markdown 中有很多反斜杠
解决:
html2md convert --html '...' --escape-mode disabled
症状:提示"Failed to fetch URL"
原因:
解决:
convert-file症状:提示"Selector not found"
解决:
<strong>, <b> → **text**<em>, <i> → *text*<del>, <s> → ~~text~~<code> → `code`<h1> → # Heading 1<h2> → ## Heading 2<h3> → ### Heading 3<h4> → #### Heading 4<h5> → ##### Heading 5<h6> → ###### Heading 6<ul>, <li> → - item<ol>, <li> → 1. item<a href="url">text</a> → [text](url)<img src="url" alt="text"> → <blockquote> → > quote<pre><code> → ```code```<table>, <tr>, <td>, <th> → Markdown 表格<hr> → ---<br> → 换行新用户应该能在 2 分钟内完成:
npm install -g @siping/html-to-markdown-nodehtml2md --versionhtml2md convert --html '<strong>Test</strong>'**Test**如果以上步骤都能顺利完成,说明 Skill 已正确配置!