vscode-colaview 0.0.0-stage → 0.3.2

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.
Files changed (47) hide show
  1. package/.vscode/launch.json +30 -0
  2. package/.vscode/settings.json +4 -0
  3. package/.vscode/tasks.json +18 -0
  4. package/.vscodeignore +23 -0
  5. package/CHANGELOG.md +141 -0
  6. package/LICENSE +21 -0
  7. package/README.md +278 -2
  8. package/README_CN.md +279 -0
  9. package/RELEASE_NOTES.md +292 -0
  10. package/esbuild.js +112 -0
  11. package/icon.png +0 -0
  12. package/package.json +162 -4
  13. package/patches/@bytechain.cn+colamd+2.7.11.patch +22 -0
  14. package/src/commands/commands.ts +105 -0
  15. package/src/export/css-collector.ts +50 -0
  16. package/src/export/docx-exporter.ts +962 -0
  17. package/src/export/html-exporter.ts +18 -0
  18. package/src/export/pdf-exporter.ts +121 -0
  19. package/src/export/render-export-images.ts +373 -0
  20. package/src/export/theme-style.ts +156 -0
  21. package/src/extension.ts +48 -0
  22. package/src/preview/preview-manager.ts +542 -0
  23. package/src/preview/webview/app.ts +366 -0
  24. package/src/preview/webview/index.html +134 -0
  25. package/src/themes/built-in/bear.css +38 -0
  26. package/src/themes/built-in/dark.css +20 -0
  27. package/src/themes/built-in/dracula.css +38 -0
  28. package/src/themes/built-in/elegant.css +52 -0
  29. package/src/themes/built-in/gruvbox.css +42 -0
  30. package/src/themes/built-in/light.css +20 -0
  31. package/src/themes/built-in/midnight.css +31 -0
  32. package/src/themes/built-in/nord.css +38 -0
  33. package/src/themes/built-in/notion.css +48 -0
  34. package/src/themes/built-in/sepia.css +47 -0
  35. package/src/themes/built-in/solarized-dark.css +35 -0
  36. package/src/themes/built-in/writer.css +44 -0
  37. package/src/themes/theme-manager.ts +180 -0
  38. package/src/types/colamd-renderer.d.ts +47 -0
  39. package/src/types.ts +20 -0
  40. package/test/fixtures/basic.md +34 -0
  41. package/test/fixtures/math.md +20 -0
  42. package/test/fixtures/mermaid.md +19 -0
  43. package/test/runTest.ts +30 -0
  44. package/test/suite/html-exporter.test.ts +20 -0
  45. package/test/suite/markdown-parser.test.ts +8 -0
  46. package/test/suite/theme-manager.test.ts +31 -0
  47. package/tsconfig.json +19 -0
@@ -0,0 +1,20 @@
1
+ /* ===== ColaMD Theme: 浅色 Light =====
2
+ GitHub-inspired clean white. The default look.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #ffffff;
9
+ --text-color: #24292f;
10
+ --text-secondary: #656d76;
11
+ --text-muted: #656d76;
12
+ --border-color: #d0d7de;
13
+ --link-color: #0969da;
14
+ --code-bg: rgba(175, 184, 193, 0.2);
15
+ --code-block-bg: #f6f8fa;
16
+ --blockquote-border: #d0d7de;
17
+ --table-header-bg: #f6f8fa;
18
+ --selection-bg: rgba(9, 105, 218, 0.15);
19
+ --highlight-bg: #fff3bf;
20
+ }
@@ -0,0 +1,31 @@
1
+ /* ===== ColaMD Theme: 午夜 Midnight =====
2
+ Pure OLED black, Apple-style blue links, maximum contrast.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #000000;
9
+ --text-color: #d6d6d6;
10
+ --text-secondary: #b1b1b1;
11
+ --text-muted: #7a7a7a;
12
+ --border-color: #262626;
13
+ --link-color: #0a84ff;
14
+ --code-bg: rgba(255, 255, 255, 0.08);
15
+ --code-block-bg: #111111;
16
+ --blockquote-border: #3a3a3a;
17
+ --table-header-bg: #111111;
18
+ --selection-bg: rgba(10, 132, 255, 0.28);
19
+ --highlight-bg: rgba(255, 214, 10, 0.25);
20
+ }
21
+
22
+ #editor .cm-content .cm-md-atxheading1,
23
+ #editor .cm-content .cm-md-atxheading2,
24
+ #editor .cm-content .cm-md-atxheading3 {
25
+ color: #f5f5f5;
26
+ }
27
+
28
+ #editor .cm-content .cm-md-blockquote {
29
+ color: #9a9a9a;
30
+ }
31
+
@@ -0,0 +1,38 @@
1
+ /* ===== ColaMD Theme: 极地 Nord =====
2
+ Arctic night: cool blue-grays, frost-cyan links.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #2e3440;
9
+ --text-color: #d8dee9;
10
+ --text-secondary: #aebdd4;
11
+ --text-muted: #7d8ba1;
12
+ --border-color: #3b4252;
13
+ --link-color: #88c0d0;
14
+ --code-bg: rgba(136, 192, 208, 0.12);
15
+ --code-block-bg: #262c37;
16
+ --blockquote-border: #81a1c1;
17
+ --table-header-bg: #3b4252;
18
+ --selection-bg: rgba(136, 192, 208, 0.2);
19
+ --highlight-bg: rgba(235, 203, 139, 0.25);
20
+ }
21
+
22
+ #editor .cm-content .cm-md-atxheading1,
23
+ #editor .cm-content .cm-md-atxheading2,
24
+ #editor .cm-content .cm-md-atxheading3 {
25
+ color: #eceff4;
26
+ }
27
+
28
+ #editor .cm-content .cm-md-strong {
29
+ color: #8fbcbb;
30
+ }
31
+
32
+ #editor .cm-content .cm-md-inlinecode {
33
+ color: #88c0d0;
34
+ }
35
+
36
+ #editor .cm-content .cm-md-blockquote {
37
+ color: #aeb9c9;
38
+ }
@@ -0,0 +1,48 @@
1
+ /* ===== ColaMD Theme: 简白 Notion =====
2
+ Clean minimal workspace, warm off-black text on white.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #ffffff;
9
+ --text-color: #37352f;
10
+ --text-secondary: #777674;
11
+ --text-muted: #9b9a97;
12
+ --border-color: #e9e9e7;
13
+ --link-color: #37352f;
14
+ --code-bg: #f7f6f3;
15
+ --code-block-bg: #f7f6f3;
16
+ --blockquote-border: #37352f;
17
+ --table-header-bg: #f7f6f3;
18
+ --selection-bg: rgba(35, 131, 226, 0.14);
19
+ --highlight-bg: #fdecc8;
20
+ }
21
+
22
+ #editor .cm-content .cm-md-link {
23
+ text-decoration: underline;
24
+ text-decoration-color: #9b9a97;
25
+ text-underline-offset: 2px;
26
+ }
27
+
28
+ #editor .cm-content .cm-md-link:hover {
29
+ text-decoration-color: #37352f;
30
+ }
31
+
32
+ #editor .cm-content .cm-md-atxheading1,
33
+ #editor .cm-content .cm-md-atxheading2 {
34
+ border-bottom: none;
35
+ padding-bottom: 0;
36
+ font-weight: 700;
37
+ }
38
+
39
+ #editor .cm-content .cm-md-inlinecode {
40
+ color: #eb5757;
41
+ background: #f7f6f3;
42
+ }
43
+
44
+ #editor .cm-content .cm-md-table-widget th,
45
+ #editor .cm-content .cm-md-table-widget td {
46
+ border-left: none;
47
+ border-right: none;
48
+ }
@@ -0,0 +1,47 @@
1
+ /* ===== ColaMD Theme: 羊皮纸 Sepia =====
2
+ Kindle / Apple Books warm paper, serif body for long-form reading.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #f6efe0;
9
+ --text-color: #4f4032;
10
+ --text-secondary: #7b6b54;
11
+ --text-muted: #9a8a72;
12
+ --border-color: #e2d7bf;
13
+ --link-color: #9c5e29;
14
+ --code-bg: rgba(122, 90, 51, 0.1);
15
+ --code-block-bg: #ece2cb;
16
+ --blockquote-border: #c9a86a;
17
+ --blockquote-bg: #efe6d0;
18
+ --table-header-bg: #ece2cb;
19
+ --selection-bg: rgba(160, 98, 45, 0.15);
20
+ --highlight-bg: #f2dfa8;
21
+ }
22
+
23
+ #editor .cm-content {
24
+ font-family: Georgia, 'Source Han Serif SC', 'Noto Serif SC', 'Songti SC', serif;
25
+ line-height: 1.85;
26
+ }
27
+
28
+ #editor .cm-content .cm-md-atxheading1 {
29
+ text-align: center;
30
+ border-bottom: none;
31
+ letter-spacing: 0.02em;
32
+ }
33
+
34
+ #editor .cm-content .cm-md-atxheading2 {
35
+ border-bottom-style: dashed;
36
+ }
37
+
38
+ #editor .cm-content .cm-md-blockquote {
39
+ /* Horizontal only: a quote is one div per line in the editor, so vertical
40
+ padding would be added once for every line of the quote. */
41
+ padding-left: 24px;
42
+ padding-right: 20px;
43
+ }
44
+
45
+ #editor .cm-content .cm-md-inlinecode {
46
+ color: #7a5a33;
47
+ }
@@ -0,0 +1,35 @@
1
+ /* ===== ColaMD Theme: 夜航 Solarized Dark =====
2
+ Deep teal-black sea, muted cyan text, orange and blue stars.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #002b36;
9
+ --text-color: #c2d5d7;
10
+ --text-secondary: #a4bbc3;
11
+ --text-muted: #586e75;
12
+ --border-color: #0d3d4a;
13
+ --link-color: #3093da;
14
+ --code-bg: rgba(88, 110, 117, 0.22);
15
+ --code-block-bg: #073642;
16
+ --blockquote-border: #2aa198;
17
+ --table-header-bg: #073642;
18
+ --selection-bg: rgba(38, 139, 210, 0.25);
19
+ --highlight-bg: rgba(181, 137, 0, 0.3);
20
+ }
21
+
22
+ #editor .cm-content .cm-md-atxheading1,
23
+ #editor .cm-content .cm-md-atxheading2,
24
+ #editor .cm-content .cm-md-atxheading3,
25
+ #editor .cm-content .cm-md-atxheading4 {
26
+ color: #93a1a1;
27
+ }
28
+
29
+ #editor .cm-content .cm-md-strong {
30
+ color: #cb4b16;
31
+ }
32
+
33
+ #editor .cm-content .cm-md-inlinecode {
34
+ color: #2aa198;
35
+ }
@@ -0,0 +1,44 @@
1
+ /* ===== ColaMD Theme: 作家 Writer =====
2
+ iA Writer homage: monospace body, zero decoration.
3
+
4
+ Import: Theme > Import Theme, or place in ~/.colamd/themes/
5
+ Variables target :root; element rules target the ColaMD editor DOM. */
6
+
7
+ :root {
8
+ --bg-color: #fcfcfa;
9
+ --text-color: #1a1a1a;
10
+ --text-secondary: #757571;
11
+ --text-muted: #8e8e8a;
12
+ --border-color: #e3e3de;
13
+ --link-color: #3b6ec4;
14
+ --code-bg: rgba(0, 0, 0, 0.05);
15
+ --code-block-bg: #f2f2ee;
16
+ --blockquote-border: #1a1a1a;
17
+ --table-header-bg: #f2f2ee;
18
+ --selection-bg: rgba(59, 110, 196, 0.15);
19
+ --highlight-bg: #fff3a3;
20
+ }
21
+
22
+ #editor .cm-content {
23
+ font-family: 'SF Mono', 'JetBrains Mono', 'Fira Code', Menlo, Consolas, 'PingFang SC', 'Noto Sans SC', monospace;
24
+ font-size: 15px;
25
+ line-height: 1.8;
26
+ }
27
+
28
+ #editor .cm-content .cm-md-atxheading1,
29
+ #editor .cm-content .cm-md-atxheading2,
30
+ #editor .cm-content .cm-md-atxheading3 {
31
+ font-weight: 700;
32
+ border-bottom: none;
33
+ padding-bottom: 0;
34
+ }
35
+
36
+ #editor .cm-content .cm-md-blockquote {
37
+ border-left-width: 3px;
38
+ font-style: normal;
39
+ }
40
+
41
+ #editor .cm-content .cm-md-table-widget th,
42
+ #editor .cm-content .cm-md-table-widget td {
43
+ font-size: 0.9em;
44
+ }
@@ -0,0 +1,180 @@
1
+ // 主题管理器 — 支持内置主题 + .themes 目录自定义主题
2
+ import * as vscode from 'vscode';
3
+ import * as path from 'path';
4
+ import * as fs from 'fs';
5
+
6
+ const BUILTIN_THEMES = [
7
+ 'light', 'dark', 'elegant', 'sepia', 'notion', 'bear',
8
+ 'writer', 'solarized-dark', 'nord', 'gruvbox', 'dracula', 'midnight'
9
+ ] as const;
10
+ type ThemeName = typeof BUILTIN_THEMES[number];
11
+
12
+ const customThemeCache = new Map<string, string>();
13
+
14
+ const THEME_CLASS_MAP: Record<string, string> = {
15
+ light: 'theme-light',
16
+ dark: 'theme-dark',
17
+ elegant: 'theme-elegant',
18
+ sepia: 'theme-sepia',
19
+ notion: 'theme-notion',
20
+ bear: 'theme-bear',
21
+ writer: 'theme-writer',
22
+ 'solarized-dark': 'theme-solarized-dark',
23
+ nord: 'theme-nord',
24
+ gruvbox: 'theme-gruvbox',
25
+ dracula: 'theme-dracula',
26
+ midnight: 'theme-midnight',
27
+ };
28
+
29
+ /**
30
+ * 获取资源文件目录 — 优先使用 out/ 目录(打包后),回退到 src/(开发模式)
31
+ */
32
+ function getResDir(context: vscode.ExtensionContext, ...segments: string[]): string {
33
+ const outDir = path.join(context.extensionPath, 'out', ...segments);
34
+ if (fs.existsSync(outDir)) {
35
+ return outDir;
36
+ }
37
+ return path.join(context.extensionPath, 'src', ...segments);
38
+ }
39
+
40
+ /**
41
+ * 主题管理器 — 负责主题 CSS 加载、切换、自定义主题导入
42
+ */
43
+ export class ThemeManager {
44
+ private static context: vscode.ExtensionContext;
45
+
46
+ /**
47
+ * 初始化主题管理器
48
+ */
49
+ static init(context: vscode.ExtensionContext): void {
50
+ this.context = context;
51
+ }
52
+
53
+ /** 获取当前激活的主题名称 */
54
+ static getCurrentTheme(): string {
55
+ return vscode.workspace.getConfiguration('colaview').get('theme', 'elegant');
56
+ }
57
+
58
+ /** 获取主题对应的 CSS class */
59
+ static getThemeClass(theme: string): string {
60
+ return THEME_CLASS_MAP[theme] || `theme-${theme}`;
61
+ }
62
+
63
+ /** 获取内置主题列表 */
64
+ static getBuiltinThemes(): string[] {
65
+ return [...BUILTIN_THEMES];
66
+ }
67
+
68
+ /**
69
+ * 获取 .themes 目录路径(当前工作区根目录下)
70
+ * 如果没有打开工作区,返回 null
71
+ */
72
+ static getThemesDir(): string | null {
73
+ const workspaceFolders = vscode.workspace.workspaceFolders;
74
+ if (!workspaceFolders || workspaceFolders.length === 0) return null;
75
+ return path.join(workspaceFolders[0].uri.fsPath, '.themes');
76
+ }
77
+
78
+ /**
79
+ * 确保 .themes 目录存在
80
+ */
81
+ private static ensureThemesDir(): string | null {
82
+ const dir = this.getThemesDir();
83
+ if (!dir) return null;
84
+ if (!fs.existsSync(dir)) {
85
+ fs.mkdirSync(dir, { recursive: true });
86
+ }
87
+ return dir;
88
+ }
89
+
90
+ /**
91
+ * 扫描 .themes 目录中的自定义主题
92
+ * 返回 { name, path } 列表
93
+ */
94
+ static scanCustomThemes(): Array<{ name: string; filePath: string }> {
95
+ const dir = this.getThemesDir();
96
+ if (!dir || !fs.existsSync(dir)) return [];
97
+
98
+ const results: Array<{ name: string; filePath: string }> = [];
99
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
100
+ if (entry.isFile() && entry.name.endsWith('.css')) {
101
+ const name = path.basename(entry.name, '.css');
102
+ results.push({ name, filePath: path.join(dir, entry.name) });
103
+ }
104
+ }
105
+ return results;
106
+ }
107
+
108
+ /**
109
+ * 获取完整主题列表(内置 + 自定义)
110
+ */
111
+ static getThemeList(): { builtins: string[]; customs: string[]; current: string } {
112
+ const builtins = this.getBuiltinThemes();
113
+ const customs = this.scanCustomThemes().map(t => t.name);
114
+ const current = this.getCurrentTheme();
115
+ return { builtins, customs, current };
116
+ }
117
+
118
+ /**
119
+ * 加载主题 CSS 内容
120
+ * 优先从 .themes/ 加载自定义主题,再加载内置主题
121
+ */
122
+ static loadThemeCSS(theme: string): string {
123
+ // 先检查 .themes 目录
124
+ const themesDir = this.getThemesDir();
125
+ if (themesDir) {
126
+ const customPath = path.join(themesDir, `${theme}.css`);
127
+ if (fs.existsSync(customPath)) {
128
+ return fs.readFileSync(customPath, 'utf-8');
129
+ }
130
+ }
131
+ // 再检查内存缓存
132
+ if (customThemeCache.has(theme)) {
133
+ return customThemeCache.get(theme)!;
134
+ }
135
+ // 最后加载内置主题
136
+ if (BUILTIN_THEMES.includes(theme as ThemeName)) {
137
+ const cssPath = path.join(
138
+ getResDir(this.context, 'themes', 'built-in'), `${theme}.css`
139
+ );
140
+ if (fs.existsSync(cssPath)) {
141
+ return fs.readFileSync(cssPath, 'utf-8');
142
+ }
143
+ }
144
+ return '';
145
+ }
146
+
147
+ /**
148
+ * 导入自定义主题 — 复制到 .themes 目录并缓存
149
+ * @param uri 源 CSS 文件 URI
150
+ */
151
+ static async importCustomTheme(uri: vscode.Uri): Promise<{ name: string; css: string } | null> {
152
+ const themesDir = this.ensureThemesDir();
153
+ if (!themesDir) {
154
+ vscode.window.showWarningMessage('No workspace folder open. Cannot import theme.');
155
+ return null;
156
+ }
157
+
158
+ const css = Buffer.from(await vscode.workspace.fs.readFile(uri)).toString('utf-8');
159
+ const name = path.basename(uri.fsPath, '.css');
160
+ const destPath = path.join(themesDir, `${name}.css`);
161
+
162
+ // 复制文件到 .themes 目录
163
+ fs.writeFileSync(destPath, css, 'utf-8');
164
+
165
+ // 更新内存缓存
166
+ customThemeCache.set(name, css);
167
+
168
+ vscode.window.showInformationMessage(`Theme "${name}" imported to .themes/`);
169
+ return { name, css };
170
+ }
171
+
172
+ /**
173
+ * 切换主题并持久化到 VSCode 配置
174
+ */
175
+ static async switchTheme(theme: string): Promise<void> {
176
+ await vscode.workspace.getConfiguration('colaview').update(
177
+ 'theme', theme, vscode.ConfigurationTarget.Global
178
+ );
179
+ }
180
+ }
@@ -0,0 +1,47 @@
1
+ // ColaMD 2.7.9 渲染库类型声明 + 模块声明
2
+ // 基于 @bytechain.cn/colamd@2.7.9 的 src/lib/index.ts 接口定义
3
+ // 2.7.9 包未发布 .d.ts 文件,此文件提供类型补全
4
+
5
+ declare module '@bytechain.cn/colamd/renderer' {
6
+ export interface ColaMDEditorOptions {
7
+ /** 编辑器容器 id。默认 `editor`,容器不存在时直接报错。 */
8
+ rootId?: string;
9
+ /** 初始 markdown。默认空文档。 */
10
+ markdown?: string;
11
+ /** 是否可编辑。导出场景默认 false。 */
12
+ editable?: boolean;
13
+ }
14
+
15
+ export interface ColaMDRendererHandle {
16
+ /** 应用主题:内置主题名,或 `custom:` + `:root` 契约 CSS。 */
17
+ applyTheme(name: string, customCSS?: string): void;
18
+ /** 替换整篇文档(会清空撤销栈)。 */
19
+ setMarkdown(markdown: string): void;
20
+ /** 当前缓冲区内容。 */
21
+ getMarkdown(): string;
22
+ /** 摊平整篇、等 mermaid/图片/字体就绪。 */
23
+ ensureAllPluginsRendered(): Promise<void>;
24
+ /** 产出一份可以离线打开的完整 HTML。 */
25
+ buildExportHTML(options?: { title?: string }): Promise<string>;
26
+ /** 销毁编辑器。 */
27
+ destroy(): void;
28
+ }
29
+
30
+ export interface ThemeContract {
31
+ contractVersion: string;
32
+ liveVariables: string[];
33
+ deadVariables: string[];
34
+ deadSelectors: string[];
35
+ editorHooks: string[];
36
+ peleVariables: string[];
37
+ constraints: {
38
+ rootOnly: boolean;
39
+ ptUnitsForbidden: boolean;
40
+ verticalPaddingForbiddenOn: string[];
41
+ };
42
+ }
43
+
44
+ export function createColaMDEditor(options?: ColaMDEditorOptions): Promise<ColaMDRendererHandle>;
45
+ export const THEME_CONTRACT: ThemeContract;
46
+ export const CONTRACT_VERSION: string;
47
+ }
package/src/types.ts ADDED
@@ -0,0 +1,20 @@
1
+ export interface PDFExportOptions {
2
+ format: 'A4' | 'Letter';
3
+ margin: {
4
+ top: string;
5
+ right: string;
6
+ bottom: string;
7
+ left: string;
8
+ };
9
+ printBackground: boolean;
10
+ }
11
+
12
+ export interface HTMLExportOptions {
13
+ embedImages: boolean;
14
+ includeCDN: boolean;
15
+ }
16
+
17
+ export interface EditorScrollMessage {
18
+ type: 'editorScroll';
19
+ scrollPercent: number;
20
+ }
@@ -0,0 +1,34 @@
1
+ # Basic Markdown Test
2
+
3
+ ## Heading 2
4
+
5
+ This is a paragraph with **bold**, *italic*, and ~~strikethrough~~ text.
6
+
7
+ ### Lists
8
+
9
+ - Item 1
10
+ - Item 2
11
+ - Nested item
12
+
13
+ 1. First
14
+ 2. Second
15
+
16
+ ### Code
17
+
18
+ Inline `code` and:
19
+
20
+ ```javascript
21
+ function hello() {
22
+ return "world";
23
+ }
24
+ ```
25
+
26
+ > This is a blockquote.
27
+
28
+ | Col A | Col B |
29
+ |-------|-------|
30
+ | val1 | val2 |
31
+
32
+ ---
33
+
34
+ [Link](https://example.com)
@@ -0,0 +1,20 @@
1
+ # Math Formula Test
2
+
3
+ Inline formula: $E = mc^2$
4
+
5
+ Block formula:
6
+
7
+ $$
8
+ \int_0^\infty x^n e^{-x} dx = n!
9
+ $$
10
+
11
+ Vector notation: $\vec{F} = m\vec{a}$
12
+
13
+ Matrix:
14
+
15
+ $$
16
+ \begin{pmatrix}
17
+ a & b \\
18
+ c & d
19
+ \end{pmatrix}
20
+ $$
@@ -0,0 +1,19 @@
1
+ # Mermaid Diagram Test
2
+
3
+ ## Flowchart
4
+
5
+ ```mermaid
6
+ graph TD
7
+ A[Start] --> B{Decision}
8
+ B -->|Yes| C[Process]
9
+ B -->|No| D[End]
10
+ C --> D
11
+ ```
12
+
13
+ ## Sequence Diagram
14
+
15
+ ```mermaid
16
+ sequenceDiagram
17
+ Alice->>Bob: Hello
18
+ Bob-->>Alice: Hi
19
+ ```
@@ -0,0 +1,30 @@
1
+ // 测试入口文件
2
+ import * as path from 'path';
3
+ import Mocha from 'mocha';
4
+
5
+ export function run(): Promise<void> {
6
+ const mocha = new Mocha({
7
+ ui: 'tdd',
8
+ color: true,
9
+ });
10
+
11
+ const testsRoot = path.resolve(__dirname, '..');
12
+
13
+ return new Promise((resolve, reject) => {
14
+ mocha.addFile(path.resolve(testsRoot, 'suite', 'markdown-parser.test.js'));
15
+ mocha.addFile(path.resolve(testsRoot, 'suite', 'theme-manager.test.js'));
16
+ mocha.addFile(path.resolve(testsRoot, 'suite', 'html-exporter.test.js'));
17
+
18
+ try {
19
+ mocha.run(failures => {
20
+ if (failures > 0) {
21
+ reject(new Error(`${failures} tests failed`));
22
+ } else {
23
+ resolve();
24
+ }
25
+ });
26
+ } catch (err) {
27
+ reject(err);
28
+ }
29
+ });
30
+ }
@@ -0,0 +1,20 @@
1
+ // HTML 导出器单元测试
2
+ import * as assert from 'assert';
3
+ import { collectCSSVariables } from '../../src/export/css-collector';
4
+
5
+ suite('HTML Exporter', () => {
6
+ test('should generate full HTML document structure', () => {
7
+ const doc = '<!DOCTYPE html>\n<html>\n<body>\n<div><h1>Test</h1><strong>bold</strong></div>\n</body>\n</html>';
8
+ assert.ok(doc.includes('<!DOCTYPE html>'), 'should have doctype');
9
+ assert.ok(doc.includes('<html>'), 'should have html tag');
10
+ assert.ok(doc.includes('<h1>'), 'should have heading');
11
+ assert.ok(doc.includes('<strong>'), 'should have bold text');
12
+ });
13
+
14
+ test('CSS collector should extract variable values', () => {
15
+ const css = ':root {\n --color-bg: #ffffff;\n --color-text: #333333;\n}';
16
+ const vars = collectCSSVariables(css);
17
+ assert.strictEqual(vars['--color-bg'], '#ffffff');
18
+ assert.strictEqual(vars['--color-text'], '#333333');
19
+ });
20
+ });
@@ -0,0 +1,8 @@
1
+ // Markdown 解析器单元测试 — 模块已迁移至 @bytechain.cn/colamd,测试暂时跳过
2
+ import * as assert from 'assert';
3
+
4
+ suite('Markdown Parser', () => {
5
+ test('placeholder — parser migrated to @bytechain.cn/colamd', () => {
6
+ assert.ok(true, 'Test suite retained for future integration tests');
7
+ });
8
+ });
@@ -0,0 +1,31 @@
1
+ // 主题管理器单元测试
2
+ import * as assert from 'assert';
3
+
4
+ suite('Theme Manager', () => {
5
+ test('should load built-in theme CSS files', () => {
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const themesPath = path.resolve(
9
+ __dirname, '../../../src/themes/built-in'
10
+ );
11
+ const themes = ['light', 'dark', 'elegant', 'newsprint'];
12
+ for (const t of themes) {
13
+ const cssPath = path.join(themesPath, `${t}.css`);
14
+ assert.ok(fs.existsSync(cssPath), `${t}.css should exist`);
15
+ const css = fs.readFileSync(cssPath, 'utf-8');
16
+ assert.ok(css.includes('--color-bg'), `${t}.css should have color-bg variable`);
17
+ }
18
+ });
19
+
20
+ test('foundation.css should exist and contain variables', () => {
21
+ const fs = require('fs');
22
+ const path = require('path');
23
+ const cssPath = path.resolve(
24
+ __dirname, '../../../src/themes/foundation.css'
25
+ );
26
+ assert.ok(fs.existsSync(cssPath), 'foundation.css should exist');
27
+ const css = fs.readFileSync(cssPath, 'utf-8');
28
+ assert.ok(css.includes('--mermaid-cscale'), 'should have mermaid color scale');
29
+ assert.ok(css.includes('--font-family-base'), 'should have font-family-base');
30
+ });
31
+ });