question-workbench-skill 0.1.1 → 0.2.1
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 +13 -0
- package/README.md +6 -0
- package/SKILL.md +7 -0
- package/package.json +24 -6
- package/scripts/make-worksheet.mjs +67 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- **纠正方向**:识别与解题仍输出教材里的 Unicode 数学符号(∠ △ ∵ ∴ ⊥ ∥ ²、S₁、x²、√3、π),不再要求模型写 LaTeX。
|
|
6
|
+
- 讲义脚本新增 Unicode→LaTeX 转换:只包裹真正的数学片段,再把它们交给 KaTeX 渲染,中文标点不会被吞进公式。
|
|
7
|
+
- 0.2.0 中“要求模型输出 `$...$`”的做法作废。
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
- 公式改用 LaTeX:识别与解题都要求 `$...$` / `$$...$$`,不再输出 ∠ △ ∵ ∴ ⊥ ∥ ² 等特殊符号。
|
|
12
|
+
- 讲义用 **KaTeX** 渲染公式,避免特殊字符在字体或打印环节出现方框/乱码;离线时退回可读的 LaTeX 源码。
|
|
13
|
+
- 讲义正文改为保留换行的整段渲染(不再按行拆 div),避免跨行的 `$$...$$` 被拆断。
|
|
14
|
+
- README 增加“公式与 KaTeX”一节,说明联网要求。
|
|
15
|
+
|
|
3
16
|
## 0.1.1
|
|
4
17
|
|
|
5
18
|
- 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
|
+
- 识别与解题时,数学公式**照原样写教材符号**:`∠ △ ∵ ∴ ⊥ ∥ ²`、`S₁`、`x²`、`√3`、`π`,不需要写 LaTeX,也不用 `$` 包裹。
|
|
50
|
+
- 讲义脚本会自动把这些 Unicode 数学符号转换成 KaTeX 公式再渲染,避免特殊字符在不同字体/打印机下变成方框或乱码。
|
|
51
|
+
- KaTeX 的 CSS 与脚本从 jsDelivr 加载,**首次打开讲义需要联网**;离线时公式退回为可读的原始符号(不会乱码)。
|
|
52
|
+
|
|
47
53
|
## 识别与字数
|
|
48
54
|
|
|
49
55
|
- **两段式**:【题目】【图形】,没有【待确认】清单;看不清处直接在原文写 `[待核实:简短原因]`。
|
package/SKILL.md
CHANGED
|
@@ -15,6 +15,12 @@ whenToUse: 用户提供题目图片/截图,或要求识别、解答、排版
|
|
|
15
15
|
- 【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写 `[待核实:简短原因]`,不要猜。**以完整转录为准,不设总字数上限**;长文(阅读填空、完形)也要转录完。
|
|
16
16
|
- 【图形】每张图一行,≤25 字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。
|
|
17
17
|
|
|
18
|
+
**数学公式照原样用教材符号书写**,不要用 LaTeX 命令,也不要用 `$` 包裹:
|
|
19
|
+
|
|
20
|
+
- 直接写 `∠BAC=60°`、`△ABC`、`AB⊥CD`、`AB∥CD`、`∵`、`∴`、`S₁`、`x²`、`√3`、`π`、`AB∶BC=6∶5`
|
|
21
|
+
- 中文说明、题干文字照常写,不用刻意分栏
|
|
22
|
+
- 讲义生成时会自动把这些符号转成 KaTeX 公式渲染,所以不需要你输出 LaTeX
|
|
23
|
+
|
|
18
24
|
不要在这一步解题,也不要补全图中看不清的内容。输出后停下来等用户确认。
|
|
19
25
|
|
|
20
26
|
## 二、解题(用户确认题目之后)
|
|
@@ -57,6 +63,7 @@ node <本 skill 目录>/scripts/make-worksheet.mjs input.json
|
|
|
57
63
|
- `text` 必填;`notes` 可选(打印在题目之后)
|
|
58
64
|
- `images` 可选:本地图片绝对路径数组,会嵌入讲义
|
|
59
65
|
- `outputPath` 默认当前目录;脚本输出 JSON,含生成的 `.html` 绝对路径
|
|
66
|
+
- 讲义用 **KaTeX** 渲染 `$...$` / `$$...$$`;KaTeX 的 CSS 与脚本从 jsDelivr 加载,**首次打开需要联网**,离线时公式退回为可读的 LaTeX 源码而不是乱码
|
|
60
67
|
- 用浏览器打开后 Ctrl+P 预览分页并打印
|
|
61
68
|
|
|
62
69
|
## 注意
|
package/package.json
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "question-workbench-skill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
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,20 +1,82 @@
|
|
|
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>');
|
|
14
|
+
|
|
15
|
+
// Convert plain Unicode math (∠ △ ∵ ∴ ⊥ ∥ ² S₁ …) into KaTeX inline math, so the
|
|
16
|
+
// author keeps writing normal textbook symbols instead of LaTeX commands.
|
|
17
|
+
const SYMBOLS = {
|
|
18
|
+
'∠': '\\angle ', '△': '\\triangle ', '∵': '\\because ', '∴': '\\therefore ',
|
|
19
|
+
'⊥': '\\perp ', '∥': '\\parallel ', '≌': '\\cong ', '∽': '\\backsim ',
|
|
20
|
+
'≈': '\\approx ', '≠': '\\ne ', '≤': '\\le ', '≥': '\\ge ',
|
|
21
|
+
'±': '\\pm ', '×': '\\times ', '÷': '\\div ', '·': '\\cdot ',
|
|
22
|
+
'√': '\\surd ', 'π': '\\pi ', '°': '^{\\circ}', '∶': ':', ':': ':',
|
|
23
|
+
'∞': '\\infty ', '∪': '\\cup ', '∩': '\\cap ', '∈': '\\in ', '⊂': '\\subset '
|
|
24
|
+
};
|
|
25
|
+
const SUP = { '⁰': '0', '¹': '1', '²': '2', '³': '3', '⁴': '4', '⁵': '5', '⁶': '6', '⁷': '7', '⁸': '8', '⁹': '9' };
|
|
26
|
+
const SUB = { '₀': '0', '₁': '1', '₂': '2', '₃': '3', '₄': '4', '₅': '5', '₆': '6', '₇': '7', '₈': '8', '₉': '9' };
|
|
27
|
+
const MATH_CHARS = new Set([...Object.keys(SYMBOLS), ...Object.keys(SUP), ...Object.keys(SUB)]);
|
|
28
|
+
|
|
29
|
+
function unicodeMathToTex(token) {
|
|
30
|
+
let out = '';
|
|
31
|
+
let i = 0;
|
|
32
|
+
while (i < token.length) {
|
|
33
|
+
const ch = token[i];
|
|
34
|
+
if (SUP[ch]) { let n = ''; while (i < token.length && SUP[token[i]]) { n += SUP[token[i]]; i++; } out += '^{' + n + '}'; continue; }
|
|
35
|
+
if (SUB[ch]) { let n = ''; while (i < token.length && SUB[token[i]]) { n += SUB[token[i]]; i++; } out += '_{' + n + '}'; continue; }
|
|
36
|
+
if (SYMBOLS[ch] !== undefined) { out += SYMBOLS[ch]; i++; continue; }
|
|
37
|
+
if (ch === '%') { out += '\\%'; i++; continue; }
|
|
38
|
+
out += ch;
|
|
39
|
+
i++;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const RUN_EXTRA = new Set('+-=/().,:<>[]{}^_|'.split(''));
|
|
45
|
+
|
|
46
|
+
function latexify(text) {
|
|
47
|
+
const lines = String(text).split('\n');
|
|
48
|
+
return lines.map((line) => {
|
|
49
|
+
let out = '';
|
|
50
|
+
let run = '';
|
|
51
|
+
const flush = () => {
|
|
52
|
+
if (!run) return;
|
|
53
|
+
const hasMath = [...run].some((c) => MATH_CHARS.has(c));
|
|
54
|
+
out += hasMath ? '$' + unicodeMathToTex(run) + '$' : run;
|
|
55
|
+
run = '';
|
|
56
|
+
};
|
|
57
|
+
for (const ch of line) {
|
|
58
|
+
const isRunChar = /[A-Za-z0-9]/.test(ch) || RUN_EXTRA.has(ch) || MATH_CHARS.has(ch);
|
|
59
|
+
if (isRunChar) run += ch;
|
|
60
|
+
else { flush(); out += ch; }
|
|
61
|
+
}
|
|
62
|
+
flush();
|
|
63
|
+
return out;
|
|
64
|
+
}).join('\n');
|
|
65
|
+
}
|
|
12
66
|
const stripChecks = (v) => String(v)
|
|
13
67
|
.replace(/(?:^|\n)\s*【(?:待确认|待核实)】[\s\S]*?(?=\n\s*【|$)/g, '')
|
|
14
68
|
.replace(/(?:^|\n)\s*\[(?:Checks|Items to verify)\][\s\S]*?(?=\n\s*\[|$)/gi, '')
|
|
15
69
|
.replace(/\n{3,}/g, '\n\n')
|
|
16
70
|
.trim();
|
|
17
71
|
|
|
72
|
+
const KATEX_HEAD = [
|
|
73
|
+
'<link rel="stylesheet" href="' + KATEX + '/katex.min.css">',
|
|
74
|
+
'<script defer src="' + KATEX + '/katex.min.js"></script>',
|
|
75
|
+
'<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>'
|
|
76
|
+
].join('');
|
|
77
|
+
|
|
78
|
+
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}';
|
|
79
|
+
|
|
18
80
|
const raw = (() => {
|
|
19
81
|
const arg = process.argv[2];
|
|
20
82
|
if (!arg) return '';
|
|
@@ -33,15 +95,15 @@ const figures = (Array.isArray(options.images) ? options.images : []).map((file)
|
|
|
33
95
|
if (!MIME[ext]) throw new Error('unsupported image type: ' + p);
|
|
34
96
|
return { name: path.basename(p), data: 'data:' + MIME[ext] + ';base64,' + fs.readFileSync(p).toString('base64') };
|
|
35
97
|
});
|
|
36
|
-
const lines = (v) => marked(v).split('\n').map((l) => '<div>' + (l || ' ') + '</div>').join('');
|
|
37
98
|
const title = (options.title && String(options.title).trim()) || '题目讲义';
|
|
38
99
|
const notes = options.notes && String(options.notes).trim()
|
|
39
|
-
? '<h2>解答 / 解析</h2><section>' +
|
|
100
|
+
? '<h2>解答 / 解析</h2><section>' + marked(latexify(options.notes)) + '</section>' : '';
|
|
101
|
+
|
|
40
102
|
const html = '<!doctype html><html><head><meta charset="utf-8"><title>' + esc(title) + '</title>'
|
|
41
|
-
+ '<style
|
|
103
|
+
+ '<style>' + STYLE + '</style>' + KATEX_HEAD + '</head><body>'
|
|
42
104
|
+ '<h1>' + esc(title) + '</h1>'
|
|
43
105
|
+ (options.grade ? '<p>' + esc(options.grade) + '</p>' : '')
|
|
44
|
-
+ '<section>' +
|
|
106
|
+
+ '<section>' + marked(latexify(text)) + '</section>'
|
|
45
107
|
+ figures.map((f) => '<figure><img src="' + f.data + '" alt="' + esc(f.name) + '"><figcaption>' + esc(f.name) + '</figcaption></figure>').join('')
|
|
46
108
|
+ notes + '</body></html>';
|
|
47
109
|
|