html-to-code
把 ai-ui-studio 产出的 HTML 原型转成符合本框架规范的 .astro 页面与组件:外壳交给 BaseLayout、颜色换令牌、假数据换集合数据,再截图闭环验收。触发词:HTML转代码、原型转代码、设计稿转页面、HTML转Astro、原型还原、Tailwind原型转组件、区块转换、组件转换、html…
by bkywksj★ 55 GitHub stars
Install html-to-code in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
原型转框架代码(html-to-code)
何时使用
docs/prototypes/下有原型,要还原成真实页面- 把原型里的某个区块 / 卡片单独转成组件
/dev-loop中遇到「原型转页面」类型的任务- 原型是 Tailwind v3 CDN 写的,需要适配 Tailwind v4 + 本框架令牌
概述
原型来源:/kickoff 阶段二经 AI 工作站 ai-ui-studio 生成,放在 docs/prototypes/<业务>/*.html。
典型特征:单文件 HTML、Tailwind(CDN)、Lucide 图标、写死的示例文案与数字、占位图;有时附带 design-system.json 与 component-mapping.md。
🔴 原型是「长什么样」的依据,不是代码来源。结构和视觉照原型,代码按框架规范重写:外壳不要、颜色不照抄、数据不照抄、脚本不照抄。
步骤 1:读原型 → 识别页面类型、区块、交互、设计特征
步骤 2:元素映射 → 外壳 / 布局 / 组件 / 图标 / 颜色 / 数据 / 交互
步骤 3:生成代码 → 页面 .astro + 业务组件 + (必要时)island + lib 查询
步骤 4:规范检查 → 清单逐项过
步骤 5:截图闭环 → 运行页 vs 原型,7 项逐条比对,不达标返工
步骤 1:读原型
ls docs/prototypes/ docs/prototypes/*/
同目录有 design-system.json / component-mapping.md 时一并读:前者给出主色、圆角、间距意图,后者是工作站建议的组件对应关系(以本技能的映射表为准,冲突时按本框架组件)。
1.1 页面类型 → 框架参考页
| 原型特征 | 页面类型 | 参考代码 |
|---|---|---|
| 大标题 + 按钮 + 若干内容区块 | 首页 | src/pages/index.astro |
| 搜索框 / 筛选胶囊 + 卡片网格 | 列表页 | src/pages/works/index.astro + islands/WorksExplorer.tsx |
| 大图 + 标题 + 元信息 + 按钮 + 相关推荐 | 详情页 | src/pages/works/[id].astro |
| 分类标题 + 导语 + 全部卡片 | 分类落地页 | src/pages/works/category/[id].astro |
| 窄栏长文 | 文章页 | src/pages/posts/[...id].astro |
1.2 识别 Tailwind 版本
| 原型里的脚本 | 版本 | 影响 |
|---|---|---|
cdn.tailwindcss.com |
v3 | 部分类名在 v4 改名,见步骤 2.6 |
@tailwindcss/browser@4 |
v4 | 类名基本可直接用 |
内联 tailwind.config = {...} |
自定义主题 | 🔴 不复制,颜色意图映射到令牌 |
1.3 列出区块清单
逐个区块写成一张表再动手(这张表也是步骤 5 的比对依据):
| # | 区块 | 原型里的样子 | 目标实现 | 数据来源 | 是否交互 |
| 1 | 页头 | logo + 4 个导航 + 主题按钮 | BaseLayout 自带 SiteHeader | site.nav | 否 |
| 2 | Hero | H1 + 定义句 + 2 按钮 | 首页 section + Button | site.tagline | 否 |
| 3 | 视频网格 | 3 列卡片,时长角标 | WorkCard 网格 | lib/works.ts | 否 |
| 4 | 筛选条 | 搜索 + 分类胶囊 + 排序 | WorksExplorer island | toCardList | 是 |
步骤 2:元素映射
2.1 外壳:全部删掉
| 原型里的 | 处理 |
|---|---|
<head>、CDN <script>、Google Fonts <link> |
删;BaseLayout 负责 head,字体用系统栈 |
| 页头 / 页脚 | 删;BaseLayout 自带 SiteHeader / SiteFooter,导航改 site.nav |
lucide.createIcons() 等初始化脚本 |
删 |
手机模拟外框(width=375、状态栏、home indicator) |
删,只保留内容区 |
原型页头 / 页脚和框架的差异较大(例如多了搜索入口)→ 属于修改框架核心组件,先和用户确认:在框架仓库里正常提交;
在孵化项目里单独一个提交、scope 写 framework(如 feat(framework): 页头加搜索入口,见 CLAUDE.md「框架核心 vs 业务代码」)。
2.2 布局
| 原型写法 | 框架写法 |
|---|---|
max-w-7xl/6xl/5xl mx-auto px-* |
<Container> |
max-w-3xl/prose mx-auto 的阅读区 |
<Container size="narrow"> + prose-content |
<section> + h2 + 副标题 + 「查看全部」 |
<Section title description eyebrow> + slot="action" |
交替底色的区块 bg-gray-50 |
<Section class="bg-surface"> |
| 面包屑 | <Breadcrumbs crumbs={crumbs}> + breadcrumbJsonLd(crumbs) |
2.3 组件
| 原型元素 | 框架组件 |
|---|---|
| 实心品牌色按钮 | <Button>(primary) |
| 描边按钮 | <Button variant="secondary"> |
| 文字按钮 | <Button variant="ghost"> |
| 分类标签(彩色) | <Badge tone="brand"> |
普通标签 #xxx |
<Badge> |
| 内容卡片(封面 + 标题 + 元信息) | WorkCard;字段差异大时新建 components/<业务>/XxxCard.tsx(照两用组件写法,见 ui-components) |
| FAQ / 折叠面板 | <details> + <summary>(参考首页 FAQ 区块) |
| 移动端菜单 | 已由 SiteHeader 的 <details> 实现 |
| 横向轮播 | CSS 横滑:flex overflow-x-auto snap-x snap-mandatory + 子项 snap-start,零 JS |
| Tab 切换不同内容 | 优先拆成不同 URL(利于 SEO);纯视觉切换才做 island |
| 弹窗 | 尽量改成独立页面;必须弹窗时用原生 <dialog> + 小段 <script> |
| 搜索 + 筛选 + 排序 | island(复用 / 仿照 WorksExplorer.tsx) |
2.4 图标
| 原型 | .astro |
.tsx(island) |
|---|---|---|
<i data-lucide="arrow-right" class="w-4 h-4"> |
import { ArrowRight } from '@lucide/astro' → <ArrowRight class="size-4" aria-hidden="true" /> |
import { ArrowRight } from 'lucide-react' → <ArrowRight className="size-4" aria-hidden="true" /> |
命名规则:kebab-case → PascalCase(chevron-right → ChevronRight、play-circle → CirclePlay 这类改过名的以包里实际导出为准)。
品牌图标(GitHub、B 站等)新版 Lucide 已不提供 → 见 icon-management(内联 SVG)。
2.5 颜色 → 语义令牌
| 原型颜色用途 | 令牌 |
|---|---|
页面白底 bg-white |
bg-canvas |
浅灰区块底 bg-gray-50/100 |
bg-surface |
| 卡片白底 | bg-elevated |
主文字 text-gray-900/800 |
text-ink |
次要文字 text-gray-500/600 |
text-muted |
边框 border-gray-100/200 |
border-line |
| 品牌色做底(装饰色块、圆点) | bg-brand、bg-brand/15 |
| 品牌色浅底(选中标签) | bg-brand-soft |
| 品牌色按钮底 | <Button>(内部 bg-brand-strong) |
| 品牌色文字 / 链接 | text-brand-ink |
选中态深色胶囊 bg-gray-900 text-white |
bg-ink text-canvas |
视频时长角标 bg-black/70 text-white |
保留(叠在图片上,与主题无关) |
- 原型主色和
site.brandColor不同 → 以site.config.ts为准;要换品牌色改配置,不在页面里写 hex - 装饰性渐变可保留,但颜色改用令牌:
from-brand/20 to-transparent - 用了令牌后不需要再写
dark:变体,暗色自动适配
2.6 Tailwind v3 → v4 类名
| v3(原型) | v4(本框架) |
|---|---|
shadow-sm / shadow |
shadow-xs / shadow-sm(卡片优先用 shadow-[var(--shadow-card)]) |
rounded-sm / rounded |
rounded-xs / rounded-sm(卡片用 rounded-[var(--radius-card)]) |
ring(3px) |
ring-3 |
outline-none |
outline-hidden(保留强制色模式下的可见性) |
bg-gradient-to-r |
bg-linear-to-r(v4 的新名字;旧名目 |
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the html-to-code skill do?
把 ai-ui-studio 产出的 HTML 原型转成符合本框架规范的 .astro 页面与组件:外壳交给 BaseLayout、颜色换令牌、假数据换集合数据,再截图闭环验收。触发词:HTML转代码、原型转代码、设计稿转页面、HTML转Astro、原型还原、Tailwind原型转组件、区块转换、组件转换、html-to-code
How do I install the html-to-code skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the html-to-code skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…