html-flashcard-builder

Extract knowledge points from study materials (docx/md/txt) to build a single-file interactive HTML flashcard app. Supports multiple-choice, true/false, fill-in-the-blank, short answer and other question types; includes card flipping, keyboard shortcuts, solution display, progress persistence (localStorage), practice for wrong answers, and mock test mode. Suitable for making review flashcards, drill apps, and mock exams.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "html-flashcard-builder" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-f5f1946a7a6b8049e1795ded6319e7583382c8f72b1a6e0acf0c6671e708fe63. Verify the upstream source and version against https://skillhub.cn/skills/user_2c17e176/csavcdfsv before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Extract knowledge points from study materials (docx/md/txt) to build a single-file interactive HTML flashcard app. Supports multiple-choice, true/false, fill-in-the-blank, short answer and other question types; includes card flipping, keyboard shortcuts, solution display, progress persistence (localStorage), practice for wrong answers, and mock test mode. Suitable for making review flashcards, drill apps, and mock exams.

0 Downloads

Introduction source: third_party · user_2c17e176 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Inputs and outputs
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: html-flashcard-builder
description: 从复习资料(docx/md/txt)提取知识点,构建单文件交互式 HTML 闪卡应用。包含选择题、判断题、填空题、简答题等多种题型,支持空格翻转、键盘快捷键、解析显示、进度持久化(localStorage)、错题重练和模拟测试模式。当用户需要制作复习闪卡、刷题应用、知识点卡片、选择题练习、模拟考试等交互式学习工具时使用。
version: 1.1.0

HTML 交互式闪卡构建器

触发场景

  • 用户提供复习资料(docx/md/txt/pdf)并要求生成闪卡、刷题应用或复习卡片
  • 用户提到"闪卡"、"flashcard"、"刷题"、"复习应用"、"模拟考试"等关键词
  • 用户提供题库或知识点列表,希望做成可交互的练习工具

输入要求

支持以下格式的复习资料:

  • docx 文件:使用 python-docx 提取文本(python -c "from docx import Document; ..."),注意 Windows 下需 sys.stdout.reconfigure(encoding='utf-8')
  • md/txt 文件:直接读取
  • 用户文本描述:从对话中提取知识点

如果用户提供多个文件(如复习提纲 + 模拟试卷),应分别处理并合并。

数据结构规范

CARDS 数组

所有题目存放在 const CARDS = [...] 中,每题为一个对象:

// 选择题
{type:"choice", ch:"第1章", q:"题目文本", opts:["选项A","选项B","选项C","选项D"], ans:0}
// ans 为正确选项的索引(0=A, 1=B, 2=C, 3=D)

// 判断题
{type:"tf", ch:"第2章", q:"题目文本", ans:true}
// ans: true=正确, false=错误

// 填空题
{type:"fill", ch:"第3章", q:"题目中包含____的题目文本", ans:["答案1"]}
// ans 为数组,支持多个可接受答案;多个空时按顺序排列

// 简答题/分析题/应用题
{type:"short", ch:"第4章", q:"题目文本", ans:"参考答案文本,支持\\n换行"}

字段说明:ch 为章节标签(用于筛选),q 为题目文本,opts 仅选择题有,ans 格式因题型而异。

EXPLANATIONS 查找表

const EXPLANATIONS = {
  "题目文本": "解析文本,解释为什么选这个答案以及相关知识点",
  // ...
};

以题目 q 字段的完整文本作为 key。为所有选择题、判断题、填空题编写解析。简答题背面本身就是详细参考答案,无需额外解析。

模拟测试数组(可选)

如有完整试卷,构建独立数组:

const EXAM_A = [ /* 同 CARDS 结构,ch 标记为 "模拟A·第X章" 或 "模拟A·选择" */ ];
const EXAM_B = [ /* 同上,标记为 "模拟B·..." */ ];

工作流步骤

步骤 1:提取资料内容

读取用户提供的所有复习资料,提取全部知识点和题目。对于 docx 文件:

python -c "
import sys
sys.stdout.reconfigure(encoding='utf-8')
from docx import Document
doc = Document(r'文件路径.docx')
for p in doc.paragraphs:
    if p.text.strip():
        print(p.text)
for table in doc.tables:
    for row in table.rows:
        print(' | '.join(cell.text for cell in row.cells))
"

步骤 2:分类与结构化

将提取内容按题型分类(choice/tf/fill/short),按章节(ch)组织。构建 CARDS 数组。

步骤 3:生成解析

为每道选择题、判断题、填空题编写解析文本,构建 EXPLANATIONS 对象。解析应说明:正确答案的原因、相关知识点扩展、易混淆概念的区分。

步骤 4:构建 HTML 文件

参考 reference.md 中的完整模板,生成单文件 HTML。包含:

  • CSS:深色主题、3D 翻转动画(perspective + transform)、响应式布局
  • HTML:控制栏(模式切换按钮 + 章节筛选)+ 卡片容器 + 标记按钮
  • JS:渲染引擎(4种题型各自的 render 函数)、交互逻辑(键盘/鼠标)、localStorage 持久化

关键 JS 函数清单(按模板实现):

函数 职责
renderChoice(card) 渲染选择题正反面;卡片 div 添加 onclick="flipCard()",选项添加 onclick="answerChoice(...)" 并 stopPropagation
renderTF(card) 渲染判断题正反面;卡片 div 添加 onclick="flipCard()"
renderFill(card) 渲染填空题正反面;卡片 div 添加 onclick="flipCard()";背面底部显示 "1=已掌握 2=待巩固 空格=下一题" 提示
renderShort(card) 渲染简答题正反面;卡片 div 添加 onclick="flipCard()";背面底部显示操作提示
renderCard() 调度:根据 card.type 调用对应 render 函数
renderMarkButtons(realIdx) 渲染"已掌握/待巩固"标记按钮
flipCard() 翻转卡片;翻转到背面时自动 answeredCards.add(currentIndex)
nextCard() / prevCard() 前后翻页
answerChoice(realIdx, optionIdx, e) 鼠标点击选择题选项时作答,需 e.stopPropagation() 防止触发卡片翻转
handleKey(e) 全局键盘事件处理:空格=翻转/下一题(双态)、j/→=下一题、k/←=上一题、翻转后 1=掌握 2=巩固、选择题 A/B/C/D、判断题正面 1/2
setMode(mode) 切换练习模式(全部/选择/判断/填空/简答/错题)
setChapter(ch) 切换章节筛选
setExam(which) 进入模拟测试模式
buildFilterBar() 构建章节筛选按钮栏
filterCards(keepIndex) 根据模式和章节过滤卡片
saveProgress() 保存进度到 localStorage
loadProgress() 从 localStorage 恢复进度
init() 初始化应用

步骤 5:添加模拟测试(可选)

如果用户提供了完整试卷,构建 EXAM_A / EXAM_B 数组,添加模拟测试按钮和 setExam() 函数逻辑。

步骤 6:语法验证与输出

必须验证 JS 语法——这是最容易出错的环节:

node -e "
const fs = require('fs');
const html = fs.readFileSync('输出文件.html', 'utf8');
const scriptMatch = html.match(/<script>([\s\S]*?)<\/script>/);
try {
  new Function(scriptMatch[1]);
  console.log('JS syntax: OK');
} catch(e) {
  console.log('JS syntax error:', e.message);
}
const s = scriptMatch[1];
console.log('CARDS:', (s.match(/\{type:/g) || []).length, 'cards');
"

验证通过后,将文件保存到用户目录并用 present_files 呈现。

交互模型

闪卡应用采用键盘优先、鼠标可选的交互设计,用户全程无需鼠标即可完成刷题。以下是标准交互规范,生成闪卡时必须严格遵循。

完整操作流程(全键盘)

看题(正面) → 空格翻转 → 查看答案(背面) → 按 1 标记"已掌握" / 按 2 标记"待巩固" → 空格进入下一题

此流程适用于所有四种题型(选择、判断、填空、简答)。选择题和判断题还可以在正面直接按键作答(A/B/C/D 或 1/2),系统自动翻转并判定对错。

快捷键映射表

按键 条件 行为
空格 卡片未翻转 翻转卡片,显示答案
空格 卡片已翻转 且 已作答 进入下一题(nextCard())
1 卡片已翻转(背面) 标记为"已掌握"(加入 masteredSet)
2 卡片已翻转(背面) 标记为"待巩固"(加入 wrongSet)
j / → 任意状态 下一题
k / ← 任意状态 上一题
A/B/C/D 选择题正面 选择对应选项,自动翻转并判定
1 / 2 判断题正面 1=正确,2=错误,自动翻转并判定

鼠标交互

  • 点击卡片任意区域:翻转卡片(与空格等效)
  • 点击选择题选项:直接作答并翻转(选项 onclick 需 e.stopPropagation() 防止触发卡片翻转)
  • 点击标记按钮:标记已掌握/待巩固(按钮 onclick 同样需要 stopPropagation())

answeredCards 状态机(空格键双态行为核心)

空格键的行为由 answeredCards 集合和 currentFlipped 状态共同决定:

// handleKey 中空格键的处理逻辑:
if (e.code === 'Space') {
  if (currentFlipped && answeredCards.has(currentIndex)) {
    nextCard();   // 已翻转 + 已作答 → 下一题
  } else {
    flipCard();   // 否则 → 翻转
  }
}

关键实现:flipCard() 在翻转到背面时,必须将当前索引加入 answeredCards,确保填空/简答等无键盘作答机制的题型翻转后空格也能进入下一题:

function flipCard() {
  if (currentCards.length === 0) return;
  currentFlipped = !currentFlipped;
  if (currentFlipped) answeredCards.add(currentIndex);  // 关键:翻转到背面即视为"已作答"
  renderCard();
}

对于选择题/判断题,键盘或鼠标作答时也会 answeredCards.add(currentIndex),与 flipCard 的行为一致。

卡片背面提示文字

所有题型的卡片背面底部必须显示统一的操作提示:

<div class="card-hint" style="color:#888">1=已掌握 2=待巩固 空格=下一题</div>

简答题如果没有此提示,需手动添加。页面底部还需显示全局快捷键提示栏:

<div class="shortcut-hint">
快捷键:空格=翻转 | ←→ 或 j/k=上/下一题<br>
选择题: A/B/C/D 或点击选项作答<br>
判断题: 1=正确 2=错误 | 翻转后: 1=掌握 2=巩固
</div>

关键注意事项

引号冲突(最高频错误)

JS 字符串使用双引号 " 作为定界符时,题目文本中的中文引号("")或嵌套双引号会导致语法错误。必须将题目内的引号替换为单引号 ' 或转义 \":

// 错误
{q:""确定软件系统必须做什么"是哪个阶段的任务?"}
// 正确
{q:"'确定软件系统必须做什么'是哪个阶段的任务?"}

生成数据后务必用正则扫描潜在冲突:

lines.forEach((line, i) => {
  if (line.includes('\u201c') || line.includes('\u201d')) {
    console.log('WARNING line', i+1, ': curly quotes found');
  }
});

localStorage 持久化要点

保存项:wrongSet(错题索引集合)、masteredSet(已掌握集合)、answered(答题记录)、currentIndex(当前题号)、currentMode(当前模式)、currentChapter(当前章节)、examMode(测试模式)。

关键细节:

  • saveProgress() 必须在 nextCard()、prevCard()、setMode()、setChapter()、setExam() 中调用
  • loadProgress() 恢复 currentIndex 后,filterCards(true) 需传入 keepIndex 参数以保留位置
  • setExam(which, keepIndex) 同样需要 keepIndex 支持,避免恢复时重置题号
  • filterCards() 和 setExam() 中要重置 answeredCards = new Set()

answeredCards 集合

用于追踪当前视图中已作答或已翻转的卡片索引。它是空格键双态行为的核心:当 currentFlipped && answeredCards.has(currentIndex) 时,按空格执行 nextCard();否则执行 flipCard()。

写入时机(以下场景均需 answeredCards.add(currentIndex)):

  • flipCard() 翻转到背面时——这是让填空题、简答题等无键盘作答机制的题型也能纯键盘操作的关键
  • 选择题通过键盘(A/B/C/D)或鼠标点击选项作答时
  • 判断题通过键盘(1/2)作答时

重置时机:切换视图(filterCards()、setExam())时必须 answeredCards = new Set()。

详细的状态机图和代码示例见上方「交互模型 → answeredCards 状态机」小节。

realIdx 计算

在非考试模式下,realIdx = CARDS.indexOf(card) 用于在 wrongSet/masteredSet 中标记题目;在考试模式下,考试题目不在 CARDS 中(indexOf 返回 -1),需改用 realIdx = currentIndex:

const realIdx = examMode ? currentIndex : CARDS.indexOf(card);

验证步骤

  1. JS 语法验证:用 node -e "new Function(scriptContent)" 验证,必须无语法错误
  2. 题目计数:统计 CARDS、EXAM_A、EXAM_B 的题目数量,与原始资料核对
  3. EXPLANATIONS 计数:确认解析覆盖所有选择题、判断题、填空题
  4. 引号扫描:正则检查所有行,确保无嵌套引号冲突
  5. 浏览器测试:用 start "" "文件路径.html" 在浏览器中打开验证

参考模板

完整的 HTML/CSS/JS 模板代码和实现细节见 reference.md。生成闪卡时,应以 reference.md 为蓝本,替换数据部分(CARDS、EXPLANATIONS、EXAM_A/B)并调整章节名称和标题。

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value95/100

Highlights

  • 支持多种题型(选择题、判断题、填空题、简答题)和交互模式(空格翻转、键盘快捷键、解析显示、进度持久化、错题重练、模拟测试)
  • 从复习资料(docx/md/txt)提取知识点,构建单文件交互式 HTML 闪卡应用,解决用户制作复习闪卡、刷题应用、知识点卡片、选择题练习、模拟考试等交互式学习工具的核心需求
Trigger Precision85/100

Highlights

  • 触发词精准完整,覆盖多种变体(闪卡、flashcard、刷题、复习应用、模拟考试等关键词)
  • 边界清晰,明确区分不同题型和交互模式
Structure and Standards80/100

Highlights

  • Phase/步骤清晰,有出口条件,含端到端示例
  • frontmatter完整,单文件≤500行
Execution Reliability75/100

Highlights

  • 工具来源明确,参数正确,覆盖主要异常
  • 不可逆操作有确认机制
Evidence Verifiability (mean of the first four)84/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.