question-workbench-skill 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +6 -0
- package/SKILL.md +8 -0
- package/package.json +24 -6
- package/scripts/make-worksheet.mjs +15 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- 公式改用 LaTeX:识别与解题都要求 `$...$` / `$$...$$`,不再输出 ∠ △ ∵ ∴ ⊥ ∥ ² 等特殊符号。
|
|
6
|
+
- 讲义用 **KaTeX** 渲染公式,避免特殊字符在字体或打印环节出现方框/乱码;离线时退回可读的 LaTeX 源码。
|
|
7
|
+
- 讲义正文改为保留换行的整段渲染(不再按行拆 div),避免跨行的 `$$...$$` 被拆断。
|
|
8
|
+
- README 增加“公式与 KaTeX”一节,说明联网要求。
|
|
9
|
+
|
|
3
10
|
## 0.1.1
|
|
4
11
|
|
|
5
12
|
- README 重写:两段式识别、取消总字数上限、安装与脚本用法、三种形态对比。
|
package/README.md
CHANGED
|
@@ -44,6 +44,12 @@ node .dsh/skills/question-workbench/scripts/make-worksheet.mjs input.json
|
|
|
44
44
|
|
|
45
45
|
脚本输出生成的 HTML 绝对路径,浏览器打开后 Ctrl+P 打印。
|
|
46
46
|
|
|
47
|
+
## 公式与 KaTeX
|
|
48
|
+
|
|
49
|
+
- 识别时要求模型把数学内容写成 **LaTeX**:行内 `$...$`、独立 `$$...$$`,不输出 ∠ △ ∵ ∴ ⊥ ∥ ² 之类的特殊符号。
|
|
50
|
+
- 讲义脚本把这些 LaTeX 用 **KaTeX** 渲染,避免特殊字符在不同字体/打印机下变成方框或乱码。
|
|
51
|
+
- KaTeX 的 CSS 与脚本从 jsDelivr 加载,**首次打开讲义需要联网**;离线时公式退回为可读的 LaTeX 源码(不会乱码)。
|
|
52
|
+
|
|
47
53
|
## 识别与字数
|
|
48
54
|
|
|
49
55
|
- **两段式**:【题目】【图形】,没有【待确认】清单;看不清处直接在原文写 `[待核实:简短原因]`。
|
package/SKILL.md
CHANGED
|
@@ -15,6 +15,13 @@ whenToUse: 用户提供题目图片/截图,或要求识别、解答、排版
|
|
|
15
15
|
- 【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写 `[待核实:简短原因]`,不要猜。**以完整转录为准,不设总字数上限**;长文(阅读填空、完形)也要转录完。
|
|
16
16
|
- 【图形】每张图一行,≤25 字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。
|
|
17
17
|
|
|
18
|
+
**数学公式一律用 LaTeX**(讲义会用 KaTeX 渲染),不要输出 ∠ △ ∵ ∴ ⊥ ∥ ² 这类特殊符号:
|
|
19
|
+
|
|
20
|
+
- 行内公式用 `$...$`,例如 `$\angle BAC=60^\circ$`、`$AB:BC:AC=6:5:3$`
|
|
21
|
+
- 独立公式用 `$$...$$`,例如 `$$S_{\triangle ABP}:S_{\triangle BCP}=6:5$$`
|
|
22
|
+
- 常见写法:`\triangle ABC`、`\angle`、`\parallel`、`\perp`、`\because`、`\therefore`、`\frac{1}{2}`、`\sqrt{3}`、`x^{2}`、`S_{1}`、`\cdot`
|
|
23
|
+
- 只把数学内容放进 `$...$`,中文说明留在外面;勾股、比例、根式、分式都用 LaTeX,不要用 Unicode 上标或除号
|
|
24
|
+
|
|
18
25
|
不要在这一步解题,也不要补全图中看不清的内容。输出后停下来等用户确认。
|
|
19
26
|
|
|
20
27
|
## 二、解题(用户确认题目之后)
|
|
@@ -57,6 +64,7 @@ node <本 skill 目录>/scripts/make-worksheet.mjs input.json
|
|
|
57
64
|
- `text` 必填;`notes` 可选(打印在题目之后)
|
|
58
65
|
- `images` 可选:本地图片绝对路径数组,会嵌入讲义
|
|
59
66
|
- `outputPath` 默认当前目录;脚本输出 JSON,含生成的 `.html` 绝对路径
|
|
67
|
+
- 讲义用 **KaTeX** 渲染 `$...$` / `$$...$$`;KaTeX 的 CSS 与脚本从 jsDelivr 加载,**首次打开需要联网**,离线时公式退回为可读的 LaTeX 源码而不是乱码
|
|
60
68
|
- 用浏览器打开后 Ctrl+P 预览分页并打印
|
|
61
69
|
|
|
62
70
|
## 注意
|
package/package.json
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "question-workbench-skill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "题目工作台 Skill:识别题目图片、思路与解答、生成 A4 讲义 HTML。一条命令安装到 DSH / Codex / WorkBuddy 等支持 skill 的客户端。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"keywords": [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
"keywords": [
|
|
8
|
+
"skill",
|
|
9
|
+
"dsh",
|
|
10
|
+
"codex",
|
|
11
|
+
"workbuddy",
|
|
12
|
+
"worksheet",
|
|
13
|
+
"education"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"question-workbench-skill": "./bin/install.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"SKILL.md",
|
|
20
|
+
"scripts/make-worksheet.mjs",
|
|
21
|
+
"bin/install.mjs",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Build an A4 worksheet HTML. Usage:
|
|
2
|
+
// Build an A4 worksheet HTML with KaTeX math rendering. Usage:
|
|
3
3
|
// node make-worksheet.mjs '{"text":"...","notes":"...","outputPath":"D:/x.html"}'
|
|
4
|
+
// Math is written as $...$ (inline) or $$...$$ (display) by the model.
|
|
4
5
|
// Prints JSON: { path, bytes, images }
|
|
5
6
|
import fs from 'node:fs';
|
|
6
7
|
import path from 'node:path';
|
|
7
8
|
|
|
8
9
|
const MIME = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.gif': 'image/gif' };
|
|
10
|
+
const KATEX = 'https://cdn.jsdelivr.net/npm/katex@0.16.11/dist';
|
|
9
11
|
const esc = (v) => String(v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
10
12
|
const marker = /([待核实[^]\n]{0,160}]|\[verify[^\]\n]{0,160}\])/gi;
|
|
11
13
|
const marked = (v) => esc(v).replace(marker, '<b class="bad">$1</b>');
|
|
@@ -15,6 +17,14 @@ const stripChecks = (v) => String(v)
|
|
|
15
17
|
.replace(/\n{3,}/g, '\n\n')
|
|
16
18
|
.trim();
|
|
17
19
|
|
|
20
|
+
const KATEX_HEAD = [
|
|
21
|
+
'<link rel="stylesheet" href="' + KATEX + '/katex.min.css">',
|
|
22
|
+
'<script defer src="' + KATEX + '/katex.min.js"></script>',
|
|
23
|
+
'<script defer src="' + KATEX + '/contrib/auto-render.min.js" onload="renderMathInElement(document.body,{delimiters:[{left:\'$$\',right:\'$$\',display:true},{left:\'$\',right:\'$\',display:false},{left:\'\\\\[\',right:\'\\\\]\',display:true},{left:\'\\\\(\',right:\'\\\\)\',display:false}],throwOnError:false,errorColor:\'#b42318\'})"></script>'
|
|
24
|
+
].join('');
|
|
25
|
+
|
|
26
|
+
const STYLE = '@page{size:A4;margin:16mm}body{font:12pt/1.75 system-ui,"Microsoft YaHei",sans-serif;color:#161616}h1{font-size:18pt}h2{font-size:13pt;margin-top:16px;border-bottom:1px solid #999}section{white-space:pre-wrap;overflow-wrap:anywhere}figure{break-inside:avoid;margin:14px 0}figure img{max-width:100%;max-height:235mm;object-fit:contain}figcaption{font-size:9pt;color:#666}.bad{color:#b42318;background:#fff0ec}.katex{font-size:1.05em}.katex-display{margin:.6em 0;overflow-x:auto;overflow-y:hidden}.katex-error{color:#b42318}';
|
|
27
|
+
|
|
18
28
|
const raw = (() => {
|
|
19
29
|
const arg = process.argv[2];
|
|
20
30
|
if (!arg) return '';
|
|
@@ -33,15 +43,15 @@ const figures = (Array.isArray(options.images) ? options.images : []).map((file)
|
|
|
33
43
|
if (!MIME[ext]) throw new Error('unsupported image type: ' + p);
|
|
34
44
|
return { name: path.basename(p), data: 'data:' + MIME[ext] + ';base64,' + fs.readFileSync(p).toString('base64') };
|
|
35
45
|
});
|
|
36
|
-
const lines = (v) => marked(v).split('\n').map((l) => '<div>' + (l || ' ') + '</div>').join('');
|
|
37
46
|
const title = (options.title && String(options.title).trim()) || '题目讲义';
|
|
38
47
|
const notes = options.notes && String(options.notes).trim()
|
|
39
|
-
? '<h2>解答 / 解析</h2><section>' +
|
|
48
|
+
? '<h2>解答 / 解析</h2><section>' + marked(options.notes) + '</section>' : '';
|
|
49
|
+
|
|
40
50
|
const html = '<!doctype html><html><head><meta charset="utf-8"><title>' + esc(title) + '</title>'
|
|
41
|
-
+ '<style
|
|
51
|
+
+ '<style>' + STYLE + '</style>' + KATEX_HEAD + '</head><body>'
|
|
42
52
|
+ '<h1>' + esc(title) + '</h1>'
|
|
43
53
|
+ (options.grade ? '<p>' + esc(options.grade) + '</p>' : '')
|
|
44
|
-
+ '<section>' +
|
|
54
|
+
+ '<section>' + marked(text) + '</section>'
|
|
45
55
|
+ figures.map((f) => '<figure><img src="' + f.data + '" alt="' + esc(f.name) + '"><figcaption>' + esc(f.name) + '</figcaption></figure>').join('')
|
|
46
56
|
+ notes + '</body></html>';
|
|
47
57
|
|