dsh-deeptutor 0.1.3 → 0.1.5
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/README.md +177 -136
- package/README.zh.md +131 -107
- package/cordis.patch.yml +17 -17
- package/package.json +62 -56
- package/scripts/install-profile.mjs +233 -0
- package/scripts/md-to-html.js +353 -353
- package/skills/deeptutor/README.md +106 -0
- package/skills/deeptutor/SKILL.md +182 -0
- package/skills/html-doc/SKILL.md +91 -0
- package/skills/html-doc/assets/template.html +420 -0
- package/skills/html-doc/scripts/md-to-html.js +353 -0
- package/src/cli-exec.ts +251 -251
- package/src/config.ts +70 -70
- package/src/html-render.ts +53 -53
- package/src/http-api.ts +83 -83
- package/src/index.ts +449 -449
- package/src/turn.ts +174 -174
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# DeepTutor Learning Assistant (dsh bundle + SKILL)
|
|
2
|
+
|
|
3
|
+
> This README is the human-facing documentation; `SKILL.md` is the agent-facing instruction file (loaded on demand).
|
|
4
|
+
> Bundle: the `dsh-deeptutor` npm package (tools) | Skill: `skills/deeptutor/SKILL.md` (shipped inside the same package, installed to `~/.dsh/skills/deeptutor/`)
|
|
5
|
+
|
|
6
|
+
Bridges **DeepTutor** (open-source personalized tutoring platform) into dsh: combines your **personal knowledge bases** (RAG retrieval) with **authoritative web sources** to generate learning content, self-test questions, and study plans — then archives your notes to a DeepTutor notebook for later review.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
| Capability | Description |
|
|
11
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
12
|
+
| Deep Solve | In-depth explanation of a topic grounded in knowledge bases + web search, with multi-turn follow-up (session continuity) |
|
|
13
|
+
| Deep Question | Generate exercises from the same learning session |
|
|
14
|
+
| Deep Research | Long multi-stage research (report mode supported) |
|
|
15
|
+
| KB Retrieval | RAG hits from your personal knowledge bases (dotnet / sqlserver / react, …) |
|
|
16
|
+
| Note Archiving | Save study notes/plans to a server notebook for searchable review |
|
|
17
|
+
| Mastery Path | Multi-stage learning path planning |
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
The `deeptutor` skill ships inside the `dsh-deeptutor` npm package. The bundled
|
|
22
|
+
installer (`scripts/install-profile.mjs` in the package, or
|
|
23
|
+
`pnpm dlx dsh-deeptutor --profile web`) installs the bundle **and** copies this
|
|
24
|
+
skill to `~/.dsh/skills/deeptutor/` (dsh auto-discovers skills there):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# One-shot: bundle + skill, from the published package
|
|
28
|
+
pnpm dlx dsh-deeptutor --profile web
|
|
29
|
+
|
|
30
|
+
# Or install the skill manually from a checkout
|
|
31
|
+
xcopy /e /i skills\deeptutor %USERPROFILE%\.dsh\skills\deeptutor # Windows
|
|
32
|
+
cp -r skills/deeptutor ~/.dsh/skills/deeptutor # macOS/Linux
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration (environment variables)
|
|
36
|
+
|
|
37
|
+
Set these in `~/.bashrc` or `~/.zshrc` (inherited by any agent at startup — agent-agnostic):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# —— Remote deployment (DeepTutor on a server, via SSH tunnel) ——
|
|
41
|
+
export DEEPTUTOR_SSH_HOST="tencent-cloud" # SSH alias (set = remote mode)
|
|
42
|
+
export DEEPTUTOR_API_BASE="http://127.0.0.1:8001" # local tunnel address (change port here)
|
|
43
|
+
export DEEPTUTOR_REMOTE_BIN="/home/ubuntu/my-deeptutor/.venv/bin/deeptutor"
|
|
44
|
+
export DEEPTUTOR_REMOTE_HOME="/home/ubuntu/my-deeptutor"
|
|
45
|
+
|
|
46
|
+
# —— Local deployment (DeepTutor on this machine) —— leave DEEPTUTOR_SSH_HOST unset for local mode
|
|
47
|
+
# export DEEPTUTOR_LOCAL_BIN="deeptutor" # local CLI path (default: deeptutor on PATH)
|
|
48
|
+
# export DEEPTUTOR_HOME="/path/to/local-workspace" # local workspace
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Deployment auto-adapts**: API reachable (local serve or tunnel) → HTTP/WS; unreachable → local CLI or SSH CLI fallback.
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
Just talk to your agent:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Deep-dive Span<T> with my dotnet knowledge base, quiz me with 5 questions, then archive the notes to a notebook
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The agent follows the SKILL workflow automatically:
|
|
62
|
+
|
|
63
|
+
1. **Dual sourcing**: `web_search` for authoritative material (Microsoft Learn, etc.) + `deeptutor_kb search` on your personal KB
|
|
64
|
+
2. **Deep Solve**: `deeptutor_run` (deep_solve, mount KB + rag + web_search, Chinese replies)
|
|
65
|
+
3. **Follow-up turns**: reuse the returned `session_id` to continue context
|
|
66
|
+
4. **Self-test**: `deep_question` (config `num_questions`)
|
|
67
|
+
5. **Plan**: structured study plan combining authoritative links + KB highlights
|
|
68
|
+
6. **Archive**: `deeptutor_note` into a notebook
|
|
69
|
+
|
|
70
|
+
## Tools
|
|
71
|
+
|
|
72
|
+
| Tool | Key parameters |
|
|
73
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
74
|
+
| `deeptutor_run` | `capability` (deep_solve / deep_question / deep_research / chat / mastery_path / …), `kbs`, `tools` (rag / web_search), `session_id`, `config`, `language` |
|
|
75
|
+
| `deeptutor_kb` | `list` / `search` (kb + query + mode) / `info` |
|
|
76
|
+
| `deeptutor_note` | `notebook` (auto-created), `title`, `type` (chat/question/research/solve), `content` (Markdown) |
|
|
77
|
+
|
|
78
|
+
## Troubleshooting
|
|
79
|
+
|
|
80
|
+
| Symptom | Cause & fix |
|
|
81
|
+
| ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| Connection timeout / host resolution failure | ① Check `DEEPTUTOR_SSH_HOST` is set and SSH passwordless login works ② Is `deeptutor serve` running? (`curl http://127.0.0.1:8001/api/v1/system/status`) |
|
|
83
|
+
| Tool returns "No DEEPTUTOR_* env vars detected" | One-time hint on first call; configure per the Configuration section and restart the agent |
|
|
84
|
+
| Local CLI garbled output / crashes | The extension injects `PYTHONUTF8=1` automatically; verify Python ≥ 3.11 otherwise |
|
|
85
|
+
| DNS resolution fails (Windows) | Common on corporate networks: if `nslookup` works but curl/python can't resolve, fix `C:\Windows\System32\drivers\etc\hosts` (when appending entries, always start with a newline) |
|
|
86
|
+
| CLI-only package missing modules | Official `packaging/deeptutor-cli` has incomplete deps; `pip install <module>` per the error (known: loguru, fastapi) |
|
|
87
|
+
|
|
88
|
+
## FAQ
|
|
89
|
+
|
|
90
|
+
**Q: Can local and remote be used at the same time?**
|
|
91
|
+
A: Yes. Switching only requires changing env vars (set/remove `DEEPTUTOR_SSH_HOST`); the SKILL and bundle stay unchanged.
|
|
92
|
+
|
|
93
|
+
**Q: What if I change servers or ports?**
|
|
94
|
+
A: Only env vars change (`DEEPTUTOR_SSH_HOST` / `DEEPTUTOR_API_BASE` / remote paths) — never the SKILL or bundle.
|
|
95
|
+
|
|
96
|
+
**Q: Is the knowledge base list hardcoded?**
|
|
97
|
+
A: No. Tools query `deeptutor_kb list` dynamically; new bases are picked up automatically.
|
|
98
|
+
|
|
99
|
+
**Q: Can other agents (Claude Code / Codex) use it?**
|
|
100
|
+
A: Yes. The SKILL follows the Agent Skills standard and can be linked into `~/.agents/skills/`; the tools themselves are registered by the dsh bundle.
|
|
101
|
+
|
|
102
|
+
## Maintenance
|
|
103
|
+
|
|
104
|
+
- Bundle features: edit the relevant file under `src/` (`index.ts` for tool wiring, `cli-exec.ts`/`http-api.ts`/`turn.ts` for transport logic, `config.ts` for env vars/helpers) → rebuild with `npm run build`
|
|
105
|
+
- SKILL content: edit `skills/deeptutor/SKILL.md` (keep the `name` + `description` frontmatter)
|
|
106
|
+
- Release: bump the version in `package.json`, push a `v*` tag, then `npm publish` (see the repo README)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deeptutor
|
|
3
|
+
description: Combine DeepTutor personal knowledge bases (RAG) with authoritative web sources to generate learning content, self-test questions, and study plans, and archive notes to a notebook. Works with both local and remote DeepTutor deployments. Use when the user wants to learn/review a technical topic (e.g. .NET, C#, SQL Server, React), get a deep explanation grounded in their own knowledge bases, generate exercises, or plan their learning.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# DeepTutor Learning Assistant (Personal Knowledge Base)
|
|
7
|
+
|
|
8
|
+
Combines the user's **personal knowledge bases** (RAG retrieval) with
|
|
9
|
+
**authoritative web sources** to produce learning content, self-test
|
|
10
|
+
questions, and study plans, then archives notes to a DeepTutor notebook.
|
|
11
|
+
|
|
12
|
+
This skill is **agent-agnostic**: every action below has two equivalent
|
|
13
|
+
drivers —
|
|
14
|
+
|
|
15
|
+
- **dsh (with the dsh-deeptutor bundle installed):** the `deeptutor_*` tools.
|
|
16
|
+
They auto-adapt local/remote deployment (HTTP/WS first with an automatic
|
|
17
|
+
SSH tunnel, CLI fallback) and stream progress.
|
|
18
|
+
- **Any agent / plain CLI:** the `deeptutor` executable directly (local
|
|
19
|
+
binary on PATH, or over SSH for remote deployments). No extension needed.
|
|
20
|
+
|
|
21
|
+
Pick whichever path exists in your environment; the action, not the tool, is
|
|
22
|
+
what matters.
|
|
23
|
+
|
|
24
|
+
## When to Use
|
|
25
|
+
|
|
26
|
+
- The user wants to learn or review a technical topic (.NET, C#, SQL Server, React, …)
|
|
27
|
+
- The user wants content grounded in their own notes/knowledge bases
|
|
28
|
+
- The user wants generated exercises, quizzes, or a learning plan
|
|
29
|
+
- The user wants to archive study notes for later review
|
|
30
|
+
|
|
31
|
+
## Configuration (env vars, agent-agnostic)
|
|
32
|
+
|
|
33
|
+
Nothing is hardcoded in this skill; all server parameters come from environment variables (put them in `~/.bashrc` or `~/.zshrc`; any agent — dsh / Claude Code / Codex / opencode — inherits them at startup). **Deployment mode adapts automatically**:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Remote deployment (DeepTutor on a server, reached through an SSH tunnel)
|
|
37
|
+
export DEEPTUTOR_SSH_HOST="tencent-cloud" # SSH host alias (set = remote mode)
|
|
38
|
+
export DEEPTUTOR_API_BASE="http://127.0.0.1:8001" # local tunnel address (change port/server here)
|
|
39
|
+
export DEEPTUTOR_REMOTE_BIN="/home/ubuntu/my-deeptutor/.venv/bin/deeptutor"
|
|
40
|
+
export DEEPTUTOR_REMOTE_HOME="/home/ubuntu/my-deeptutor"
|
|
41
|
+
|
|
42
|
+
# Local deployment (DeepTutor on this machine) — leave DEEPTUTOR_SSH_HOST unset for local mode
|
|
43
|
+
# export DEEPTUTOR_API_BASE="http://127.0.0.1:8001" # local serve port
|
|
44
|
+
# export DEEPTUTOR_LOCAL_BIN="deeptutor" # local CLI path (default: deeptutor on PATH)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **dsh path:** API reachable (local serve or tunnel) → HTTP/WS; unreachable →
|
|
48
|
+
local CLI or SSH CLI fallback automatically. The bundle starts/recycles
|
|
49
|
+
the SSH tunnel; local mode needs no tunnel.
|
|
50
|
+
- **Plain CLI path:** run `deeptutor <subcommand>` locally, or
|
|
51
|
+
`ssh <DEEPTUTOR_SSH_HOST> <DEEPTUTOR_REMOTE_BIN> <subcommand>` for remote
|
|
52
|
+
deployments (the tunnel is the extension's job — CLI users don't need it).
|
|
53
|
+
- Migrating to another server or port only requires changing env vars — never this skill.
|
|
54
|
+
|
|
55
|
+
## Actions Cheat Sheet
|
|
56
|
+
|
|
57
|
+
| Action | dsh (tools) | CLI equivalent (`deeptutor …`) |
|
|
58
|
+
| ---------------------------- | -------------------------------- | ------------------------------------------------------------ |
|
|
59
|
+
| List knowledge bases | `deeptutor_kb action=list` | `kb list --format json` |
|
|
60
|
+
| Search a knowledge base | `deeptutor_kb action=search` | `kb search <kb> "<query>" --format json --mode hybrid` |
|
|
61
|
+
| Show a knowledge base's info | `deeptutor_kb action=info` | `kb info <kb>` |
|
|
62
|
+
| Run a learning capability | `deeptutor_run capability=<cap>` | `run <cap> "<prompt>" --format json` |
|
|
63
|
+
| Archive a note to a notebook | `deeptutor_note` | `notebook add-md <nb-id> <file> --title "<t>" --type <type>` |
|
|
64
|
+
| View lightweight memory | — (CLI only) | `memory show` |
|
|
65
|
+
| List / inspect sessions | — (CLI only) | `session list` · `session show <id>` |
|
|
66
|
+
| Show a notebook's records | — (CLI only) | `notebook show <name>` |
|
|
67
|
+
| Inspect configuration | — (CLI only) | `config show` (troubleshooting) |
|
|
68
|
+
|
|
69
|
+
Capabilities: `deep_solve` / `deep_question` / `deep_research` / `chat` /
|
|
70
|
+
`mastery_path` / `visualize` / `math_animator`.
|
|
71
|
+
|
|
72
|
+
Useful `run` flags: `--kb <name>` (mount a knowledge base, repeatable),
|
|
73
|
+
`--tool <name>` (`rag`, `web_search`, `reason`, …, repeatable),
|
|
74
|
+
`--session <id>` (continue context), `--language zh`, `--config k=v`
|
|
75
|
+
(repeatable; e.g. `--config num_questions=5`), `--config-json '{"..."}'`
|
|
76
|
+
(complex config), `--notebook-ref <name>` / `--history-ref <id>` (reference
|
|
77
|
+
notebooks or past sessions from the prompt).
|
|
78
|
+
|
|
79
|
+
## Discovering Commands
|
|
80
|
+
|
|
81
|
+
The command set evolves — this cheat sheet is a curated subset, not the full
|
|
82
|
+
surface. Before using a command not listed here, **discover it from the CLI
|
|
83
|
+
itself** and never invent flags:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
deeptutor --help # top-level commands
|
|
87
|
+
deeptutor <cmd> --help # one subcommand's options
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Read the output, then use only what it shows. If a needed capability is not
|
|
91
|
+
in `--help`, report that to the user instead of guessing.
|
|
92
|
+
|
|
93
|
+
## Recommended Learning Workflow
|
|
94
|
+
|
|
95
|
+
### 1. Gather material from both channels
|
|
96
|
+
|
|
97
|
+
- `web_search` for **authoritative sources**: official docs (Microsoft Learn / learn.microsoft.com), official blogs, trusted tutorials. Keep the source links.
|
|
98
|
+
- Search the user's personal knowledge base (pick the right one: dotnet-related → their dotnet base, database → sqlserver) to get their own curated notes:
|
|
99
|
+
- pi: `deeptutor_kb action=search kb=<kb> query="<topic>"`
|
|
100
|
+
- CLI: `deeptutor kb search <kb> "<topic>" --format json`
|
|
101
|
+
- Always list bases first (`deeptutor_kb action=list` / `deeptutor kb list --format json`) — never assume names.
|
|
102
|
+
|
|
103
|
+
### 2. Deep Solve
|
|
104
|
+
|
|
105
|
+
- pi: `deeptutor_run capability=deep_solve prompt="<topic>" kbs=[<kb>] tools=[rag, web_search] language=zh`
|
|
106
|
+
- CLI: `deeptutor run deep_solve "<topic>" --kb <kb> --tool rag --tool web_search --language zh --format json`
|
|
107
|
+
|
|
108
|
+
**Always record the returned `session_id`** — reuse it for every follow-up turn so DeepTutor keeps the context (chat history, knowledge bases, tools).
|
|
109
|
+
|
|
110
|
+
### 3. Follow-up questions / targeted reinforcement
|
|
111
|
+
|
|
112
|
+
Continue with the same `session_id`: details, code examples, common pitfalls, differences vs. authoritative sources.
|
|
113
|
+
|
|
114
|
+
### 4. Self-test
|
|
115
|
+
|
|
116
|
+
- pi: `deeptutor_run capability=deep_question prompt="<topic essentials>" session_id=<same> config={num_questions: 5} kbs=[<kb>] language=zh`
|
|
117
|
+
- CLI: `deeptutor run deep_question "<topic essentials>" --session <same> --config num_questions=5 --kb <kb> --language zh --format json`
|
|
118
|
+
|
|
119
|
+
### 5. Output a study plan
|
|
120
|
+
|
|
121
|
+
Combine all three material sources into a structured plan (Markdown):
|
|
122
|
+
|
|
123
|
+
- Learning goals and prerequisites
|
|
124
|
+
- Core concept list (marked: from personal KB / authoritative link)
|
|
125
|
+
- Phased schedule (each phase: concept → authoritative reading → KB review → exercises)
|
|
126
|
+
- Quiz questions and acceptance criteria
|
|
127
|
+
- Reference list (authoritative links + KB hit sources)
|
|
128
|
+
|
|
129
|
+
### 5b. Render study material to local HTML (recommended)
|
|
130
|
+
|
|
131
|
+
When the user wants readable/browsable/printable study material, render the
|
|
132
|
+
answers to a self-contained HTML page (dark/light toggle, TOC, collapsible
|
|
133
|
+
quiz answers, print-friendly) with the **html-doc skill** (zero-dependency
|
|
134
|
+
Node converter):
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
node skills/html-doc/scripts/md-to-html.js <answer.md> --out <page.html> --title "<主题>" --toc
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
On dsh, `deeptutor_run` does this automatically when given the `html` param:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
deeptutor_run capability=deep_solve prompt=<topic> kbs=[...] tools=[rag, web_search]
|
|
144
|
+
html="data/study/<topic>/knowledge.html" html_title="<主题> · 知识点" language=zh
|
|
145
|
+
deeptutor_run capability=deep_question prompt=<topic essentials> config={num_questions: 5}
|
|
146
|
+
html="data/study/<topic>/quiz.html" html_title="<主题> · 自测题" language=zh
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Then tell the user the HTML file paths so they can open them in a browser.
|
|
150
|
+
|
|
151
|
+
### 6. Archive
|
|
152
|
+
|
|
153
|
+
Store the final notes/plan in a server notebook (e.g. `dotnet-learning`) so they can be retrieved for review later:
|
|
154
|
+
|
|
155
|
+
- dsh: `deeptutor_note notebook=<name> title="<t>" type=solve content=<markdown>`
|
|
156
|
+
- CLI:
|
|
157
|
+
```bash
|
|
158
|
+
deeptutor notebook list # find the notebook id
|
|
159
|
+
deeptutor notebook create <name> --description "archived" # only if missing
|
|
160
|
+
deeptutor notebook add-md <nb-id> <notes.md> --title "<t>" --type solve
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Safety Boundaries
|
|
164
|
+
|
|
165
|
+
Read-only exploration is always fine: `kb list/info/search`, `memory show`,
|
|
166
|
+
`session list/show`, `config show`, `notebook list/show`.
|
|
167
|
+
|
|
168
|
+
Never run destructive commands: `kb delete`, `memory clear`, `session delete`,
|
|
169
|
+
`notebook remove-record`. Creation/update commands (`kb create/add`,
|
|
170
|
+
`notebook create/add-md/replace-md`, `session rename`) only on the user's
|
|
171
|
+
explicit request — never proactively.
|
|
172
|
+
|
|
173
|
+
## Notes
|
|
174
|
+
|
|
175
|
+
- On dsh, calls go through HTTP/WS first (tunnel), falling back to SSH CLI automatically when the tunnel is down; `deeptutor_run` streams over WebSocket so progress is visible.
|
|
176
|
+
- `deep_research` can take minutes: give a generous timeout (900+) or split long tasks.
|
|
177
|
+
- Results may be truncated (default 30000 chars) — ask to continue for the full content.
|
|
178
|
+
- RAG hits can be noisy; treat official sources as authoritative and point out conflicts to the user.
|
|
179
|
+
- Do not delete knowledge bases or run destructive operations (see Safety
|
|
180
|
+
Boundaries above); `kb create/add` is fine, but only on the user's explicit
|
|
181
|
+
request, never proactively.
|
|
182
|
+
- CLI output: add `--format json` for machine-readable events; without it you get human-readable text.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: html-doc
|
|
3
|
+
description: Generates self-contained, browser-ready HTML files from Markdown content (study notes, documentation, quiz/exercise sheets) using a zero-dependency Node converter and a polished built-in template with dark/light theme toggle, collapsible answers, and print-friendly layout. Use when the user wants local HTML output for reading, reviewing, or sharing learning material and docs.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# HTML Doc Generator
|
|
7
|
+
|
|
8
|
+
Convert Markdown into a beautiful, self-contained local HTML file (single file, inline CSS/JS, no network needed to open). Ideal for study notes, knowledge summaries, and self-test question sheets.
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
- After a learning session (e.g. deeptutor deep_solve / deep_question), the user wants readable local HTML of the knowledge points and quiz questions
|
|
13
|
+
- Converting any Markdown notes/docs into a polished local HTML page
|
|
14
|
+
|
|
15
|
+
## Files
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
html-doc/
|
|
19
|
+
├── SKILL.md # this file
|
|
20
|
+
├── scripts/
|
|
21
|
+
│ └── md-to-html.js # zero-dependency Markdown → HTML converter (Node ≥ 18)
|
|
22
|
+
└── assets/
|
|
23
|
+
└── template.html # default HTML template (CSS + JS, customizable)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Basic: write Markdown to a file, then convert
|
|
30
|
+
node scripts/md-to-html.js notes.md --out notes.html --title "C# 抽象类学习笔记"
|
|
31
|
+
|
|
32
|
+
# From stdin (any tool output piped in)
|
|
33
|
+
cat notes.md | node scripts/md-to-html.js --title "Quiz" --theme dark --out quiz.html
|
|
34
|
+
|
|
35
|
+
# Options
|
|
36
|
+
# --out <file> output path (default: <input>.html)
|
|
37
|
+
# --title <text> page title (default: input filename or "Document")
|
|
38
|
+
# --theme <mode> dark | light (default: light; user can toggle in-page anyway)
|
|
39
|
+
# --toc generate a table of contents from headings (h2/h3)
|
|
40
|
+
# --lang <code> html lang attribute (default: zh-CN)
|
|
41
|
+
# --no-collapse disable <details> wrapping for quiz answers (default: collapse enabled)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Supported Markdown
|
|
45
|
+
|
|
46
|
+
ATX headings (`#`–`######`), fenced code blocks (``` with optional language), inline code, bold, italic, links, unordered/ordered lists, task lists (`- [ ]` / `- [x]`), blockquotes, tables (pipe syntax), horizontal rules, paragraphs.
|
|
47
|
+
|
|
48
|
+
Anything unsupported falls back to a plain `<p>` — output always stays valid.
|
|
49
|
+
|
|
50
|
+
## Recommended Workflow for Study Material
|
|
51
|
+
|
|
52
|
+
1. Collect the learning content (e.g. from deeptutor_run answer) as Markdown files under a docs folder, e.g. `~/study/abstract-class/`:
|
|
53
|
+
- `knowledge.md` — the deep-solve explanation
|
|
54
|
+
- `quiz.md` — the self-test questions (mark answers inside `<details>` blocks so they collapse)
|
|
55
|
+
2. Convert each file:
|
|
56
|
+
```bash
|
|
57
|
+
node scripts/md-to-html.js knowledge.md --out knowledge.html --title "C# 抽象类 · 知识点" --toc
|
|
58
|
+
node scripts/md-to-html.js quiz.md --out quiz.html --title "C# 抽象类 · 自测题" --toc
|
|
59
|
+
```
|
|
60
|
+
3. Open the HTML files in the browser (or tell the user the file paths).
|
|
61
|
+
|
|
62
|
+
## Quiz Answer Collapsing
|
|
63
|
+
|
|
64
|
+
The converter auto-detects quiz structure: any heading containing "答案" / "Answer" / "解析" / "Explanation" starts a `<details>` block whose following content (until the next heading) is collapsed. Also, a heading line that is immediately followed by content gets wrapped when the heading matches. This keeps the quiz readable while hiding answers until clicked.
|
|
65
|
+
|
|
66
|
+
To be explicit, authors can also wrap answers manually:
|
|
67
|
+
|
|
68
|
+
```markdown
|
|
69
|
+
<details><summary>答案:C</summary>
|
|
70
|
+
|
|
71
|
+
解析:...
|
|
72
|
+
</details>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Raw `<details>`/`<summary>` blocks are preserved as-is (the only raw-HTML passthrough); everything else is treated as Markdown/text and HTML-escaped.
|
|
76
|
+
|
|
77
|
+
## Customizing the Template
|
|
78
|
+
|
|
79
|
+
Edit `assets/template.html` — it uses `{{TITLE}}`, `{{BODY}}`, `{{THEME}}`, `{{LANG}}`, `{{TOC}}`, `{{GENERATED}}` placeholders. Keep placeholders intact; the converter does simple string replacement. The built-in template includes:
|
|
80
|
+
|
|
81
|
+
- CSS variables for light/dark theming with an in-page toggle button (remembers choice in localStorage)
|
|
82
|
+
- Print stylesheet (answers stay collapsed on paper)
|
|
83
|
+
- Code block styling with optional language badge
|
|
84
|
+
- Table styling, blockquote styling, task-list checkboxes
|
|
85
|
+
- Responsive layout (comfortable reading column)
|
|
86
|
+
|
|
87
|
+
## Notes
|
|
88
|
+
|
|
89
|
+
- Zero dependencies — only `node` (≥ 18) is required; no npm install needed
|
|
90
|
+
- Output is fully self-contained: inline CSS + JS, no external fonts/CDN (offline-friendly)
|
|
91
|
+
- Escaping is handled: content is HTML-escaped before insertion. Raw-HTML passthrough is intentionally narrow (`<details>`/`<summary>` only) since `deeptutor_run` feeds model/web_search-sourced answers into this converter automatically — a wider tag whitelist would let untrusted `<script>`/`on*=` content ride along into the generated local HTML.
|