vscode-colaview 0.0.0-stage → 0.3.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/.vscode/launch.json +30 -0
- package/.vscode/settings.json +7 -0
- package/.vscode/tasks.json +18 -0
- package/.vscodeignore +23 -0
- package/CHANGELOG.md +112 -0
- package/LICENSE +21 -0
- package/README.md +264 -2
- package/README_CN.md +265 -0
- package/RELEASE_NOTES.md +201 -0
- package/esbuild.js +106 -0
- package/icon.png +0 -0
- package/package.json +186 -6
- package/src/commands/commands.ts +105 -0
- package/src/export/css-collector.ts +50 -0
- package/src/export/docx-exporter.ts +923 -0
- package/src/export/html-exporter.ts +18 -0
- package/src/export/pdf-exporter.ts +121 -0
- package/src/export/render-export-images.ts +206 -0
- package/src/export/theme-style.ts +135 -0
- package/src/extension.ts +59 -0
- package/src/preview/preview-manager.ts +499 -0
- package/src/preview/webview/app.ts +371 -0
- package/src/preview/webview/index.html +127 -0
- package/src/themes/built-in/bear.css +38 -0
- package/src/themes/built-in/dark.css +20 -0
- package/src/themes/built-in/dracula.css +38 -0
- package/src/themes/built-in/elegant.css +52 -0
- package/src/themes/built-in/gruvbox.css +42 -0
- package/src/themes/built-in/light.css +20 -0
- package/src/themes/built-in/midnight.css +31 -0
- package/src/themes/built-in/nord.css +38 -0
- package/src/themes/built-in/notion.css +48 -0
- package/src/themes/built-in/sepia.css +47 -0
- package/src/themes/built-in/solarized-dark.css +35 -0
- package/src/themes/built-in/writer.css +44 -0
- package/src/themes/theme-manager.ts +180 -0
- package/src/types/colamd-renderer.d.ts +47 -0
- package/src/types.ts +20 -0
- package/test/fixtures/basic.md +34 -0
- package/test/fixtures/math.md +20 -0
- package/test/fixtures/mermaid.md +19 -0
- package/test/runTest.ts +30 -0
- package/test/suite/html-exporter.test.ts +20 -0
- package/test/suite/markdown-parser.test.ts +8 -0
- package/test/suite/theme-manager.test.ts +31 -0
- package/tsconfig.json +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,186 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vscode-colaview",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "vscode-colaview",
|
|
3
|
+
"displayName": "ColaView MD",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"publisher": "bytechain",
|
|
6
|
+
"description": "ColaMD Preview — Rich Markdown Preview & PDF/HTML Export for VSCode",
|
|
7
|
+
"icon": "icon.png",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/bytechain/vscode-colaview.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"engines": {
|
|
14
|
+
"vscode": "^1.85.0"
|
|
15
|
+
},
|
|
16
|
+
"categories": [
|
|
17
|
+
"Other"
|
|
18
|
+
],
|
|
19
|
+
"activationEvents": [
|
|
20
|
+
"onLanguage:markdown",
|
|
21
|
+
"onCommand:colaview.showPreview",
|
|
22
|
+
"onCommand:colaview.exportPDF",
|
|
23
|
+
"onCommand:colaview.exportHTML",
|
|
24
|
+
"onCommand:colaview.exportWord"
|
|
25
|
+
],
|
|
26
|
+
"main": "./out/extension.js",
|
|
27
|
+
"contributes": {
|
|
28
|
+
"commands": [
|
|
29
|
+
{
|
|
30
|
+
"command": "colaview.showPreview",
|
|
31
|
+
"title": "Show Preview",
|
|
32
|
+
"icon": "$(open-preview)"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"command": "colaview.exportPDF",
|
|
36
|
+
"title": "Export to PDF...",
|
|
37
|
+
"icon": "$(export)"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"command": "colaview.exportHTML",
|
|
41
|
+
"title": "Export to HTML...",
|
|
42
|
+
"icon": "$(export)"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"command": "colaview.exportWord",
|
|
46
|
+
"title": "Export to Word...",
|
|
47
|
+
"icon": "$(export)"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"command": "colaview.switchTheme",
|
|
51
|
+
"title": "Switch Preview Theme..."
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"command": "colaview.importTheme",
|
|
55
|
+
"title": "Import Custom Theme..."
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"menus": {
|
|
59
|
+
"editor/title": [
|
|
60
|
+
{
|
|
61
|
+
"command": "colaview.showPreview",
|
|
62
|
+
"group": "navigation"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"editor/context": [
|
|
66
|
+
{
|
|
67
|
+
"command": "colaview.showPreview",
|
|
68
|
+
"group": "1_colaview"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"command": "colaview.exportPDF",
|
|
72
|
+
"group": "1_colaview"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"command": "colaview.exportHTML",
|
|
76
|
+
"group": "1_colaview"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"command": "colaview.exportWord",
|
|
80
|
+
"group": "1_colaview"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"explorer/context": [
|
|
84
|
+
{
|
|
85
|
+
"command": "colaview.exportPDF",
|
|
86
|
+
"group": "1_colaview"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"command": "colaview.exportHTML",
|
|
90
|
+
"group": "1_colaview"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"command": "colaview.exportWord",
|
|
94
|
+
"group": "1_colaview"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
"configuration": {
|
|
99
|
+
"title": "ColaView MD",
|
|
100
|
+
"properties": {
|
|
101
|
+
"colaview.theme": {
|
|
102
|
+
"type": "string",
|
|
103
|
+
"default": "elegant",
|
|
104
|
+
"enum": [
|
|
105
|
+
"light",
|
|
106
|
+
"dark",
|
|
107
|
+
"elegant",
|
|
108
|
+
"sepia",
|
|
109
|
+
"notion",
|
|
110
|
+
"bear",
|
|
111
|
+
"writer",
|
|
112
|
+
"solarized-dark",
|
|
113
|
+
"nord",
|
|
114
|
+
"gruvbox",
|
|
115
|
+
"dracula",
|
|
116
|
+
"midnight"
|
|
117
|
+
],
|
|
118
|
+
"description": "Visual theme for preview and export"
|
|
119
|
+
},
|
|
120
|
+
"colaview.plugins.math": {
|
|
121
|
+
"type": "boolean",
|
|
122
|
+
"default": true,
|
|
123
|
+
"description": "Enable KaTeX math formula rendering"
|
|
124
|
+
},
|
|
125
|
+
"colaview.plugins.mermaid": {
|
|
126
|
+
"type": "boolean",
|
|
127
|
+
"default": true,
|
|
128
|
+
"description": "Enable Mermaid diagram rendering"
|
|
129
|
+
},
|
|
130
|
+
"colaview.pdfMethod": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"default": "puppeteer",
|
|
133
|
+
"enum": [
|
|
134
|
+
"puppeteer",
|
|
135
|
+
"webviewPrint"
|
|
136
|
+
],
|
|
137
|
+
"description": "PDF export method"
|
|
138
|
+
},
|
|
139
|
+
"colaview.autoPreview": {
|
|
140
|
+
"type": "boolean",
|
|
141
|
+
"default": false,
|
|
142
|
+
"description": "Auto show preview on opening Markdown"
|
|
143
|
+
},
|
|
144
|
+
"colaview.customThemesPath": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"default": "",
|
|
147
|
+
"description": "Custom theme CSS directory path"
|
|
148
|
+
},
|
|
149
|
+
"colaview.scrollSync": {
|
|
150
|
+
"type": "boolean",
|
|
151
|
+
"default": false,
|
|
152
|
+
"description": "Enable scroll sync between editor and preview"
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"scripts": {
|
|
158
|
+
"vscode:prepublish": "npm run esbuild-base -- --production",
|
|
159
|
+
"esbuild-base": "node esbuild.js",
|
|
160
|
+
"build": "node esbuild.js",
|
|
161
|
+
"watch": "node esbuild.js --watch",
|
|
162
|
+
"pretest": "npm run build",
|
|
163
|
+
"test": "node ./out/test/runTest.js",
|
|
164
|
+
"package": "vsce package"
|
|
165
|
+
},
|
|
166
|
+
"dependencies": {
|
|
167
|
+
"@bytechain.cn/colamd": "^2.7.9",
|
|
168
|
+
"docx": "^9.15.2",
|
|
169
|
+
"katex": "^0.16.47",
|
|
170
|
+
"mermaid": "^11.15.0",
|
|
171
|
+
"puppeteer-core": "^25.1.0",
|
|
172
|
+
"remark-gfm": "^4.0.1",
|
|
173
|
+
"remark-parse": "^11.0.0",
|
|
174
|
+
"unified": "^11.0.5"
|
|
175
|
+
},
|
|
176
|
+
"devDependencies": {
|
|
177
|
+
"@types/katex": "^0.16.8",
|
|
178
|
+
"@types/node": "^20.0.0",
|
|
179
|
+
"@types/vscode": "^1.85.0",
|
|
180
|
+
"@vscode/test-electron": "^2.4.0",
|
|
181
|
+
"@vscode/vsce": "^3.0.0",
|
|
182
|
+
"esbuild": "^0.28.0",
|
|
183
|
+
"eslint": "^9.0.0",
|
|
184
|
+
"typescript": "^5.7.0"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// VSCode 命令注册 — 所有 ColaView MD 命令入口
|
|
2
|
+
import * as vscode from 'vscode';
|
|
3
|
+
import { PreviewManager } from '../preview/preview-manager';
|
|
4
|
+
import { ThemeManager } from '../themes/theme-manager';
|
|
5
|
+
import { exportHTML } from '../export/html-exporter';
|
|
6
|
+
import { exportPDF } from '../export/pdf-exporter';
|
|
7
|
+
import { exportWord } from '../export/docx-exporter';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 注册所有 ColaView MD 命令
|
|
11
|
+
* @param context VSCode 扩展上下文
|
|
12
|
+
* @param previewManager 预览面板管理器(可能为 null)
|
|
13
|
+
*/
|
|
14
|
+
export function registerCommands(
|
|
15
|
+
context: vscode.ExtensionContext,
|
|
16
|
+
previewManager: PreviewManager | null
|
|
17
|
+
): void {
|
|
18
|
+
context.subscriptions.push(
|
|
19
|
+
vscode.commands.registerCommand('colaview.showPreview', () => {
|
|
20
|
+
if (!previewManager) {
|
|
21
|
+
vscode.window.showErrorMessage('ColaView: Preview manager not available');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
previewManager.showPreview();
|
|
25
|
+
}),
|
|
26
|
+
|
|
27
|
+
vscode.commands.registerCommand('colaview.exportHTML', async () => {
|
|
28
|
+
const editor = vscode.window.activeTextEditor;
|
|
29
|
+
if (!editor || editor.document.languageId !== 'markdown') {
|
|
30
|
+
vscode.window.showWarningMessage('Open a Markdown file first');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!previewManager) {
|
|
34
|
+
vscode.window.showErrorMessage('ColaView: Preview manager not available');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
previewManager.showPreview();
|
|
38
|
+
const fullHTML = await previewManager.getExportHTML();
|
|
39
|
+
if (!fullHTML) {
|
|
40
|
+
vscode.window.showWarningMessage('ColaView: Could not get rendered HTML from preview');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await exportHTML(editor.document, fullHTML);
|
|
44
|
+
}),
|
|
45
|
+
|
|
46
|
+
vscode.commands.registerCommand('colaview.exportPDF', async () => {
|
|
47
|
+
const editor = vscode.window.activeTextEditor;
|
|
48
|
+
if (!editor || editor.document.languageId !== 'markdown') {
|
|
49
|
+
vscode.window.showWarningMessage('Open a Markdown file first');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!previewManager) {
|
|
53
|
+
vscode.window.showErrorMessage('ColaView: Preview manager not available');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
previewManager.showPreview();
|
|
57
|
+
const fullHTML = await previewManager.getExportHTML();
|
|
58
|
+
if (!fullHTML) {
|
|
59
|
+
vscode.window.showWarningMessage('ColaView: Could not get rendered HTML from preview');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await exportPDF(editor.document, fullHTML);
|
|
63
|
+
}),
|
|
64
|
+
|
|
65
|
+
vscode.commands.registerCommand('colaview.exportWord', async () => {
|
|
66
|
+
const editor = vscode.window.activeTextEditor;
|
|
67
|
+
if (!editor || editor.document.languageId !== 'markdown') {
|
|
68
|
+
vscode.window.showWarningMessage('Open a Markdown file first');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
await exportWord(editor.document);
|
|
72
|
+
}),
|
|
73
|
+
|
|
74
|
+
vscode.commands.registerCommand('colaview.switchTheme', async () => {
|
|
75
|
+
const list = ThemeManager.getThemeList();
|
|
76
|
+
const items: vscode.QuickPickItem[] = [
|
|
77
|
+
...list.builtins.map(t => ({ label: t.charAt(0).toUpperCase() + t.slice(1), description: 'Built-in' })),
|
|
78
|
+
...list.customs.map(t => ({ label: t, description: 'Custom' })),
|
|
79
|
+
];
|
|
80
|
+
const picked = await vscode.window.showQuickPick(items);
|
|
81
|
+
if (picked) {
|
|
82
|
+
const name = picked.label.toLowerCase();
|
|
83
|
+
await ThemeManager.switchTheme(name);
|
|
84
|
+
// 自定义主题需要通过 handleSwitchTheme 发送 CSS
|
|
85
|
+
if (previewManager) {
|
|
86
|
+
previewManager.switchThemeFromCommand(name);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
|
|
91
|
+
vscode.commands.registerCommand('colaview.importTheme', async () => {
|
|
92
|
+
const uris = await vscode.window.showOpenDialog({
|
|
93
|
+
filters: { 'CSS Themes': ['css'] },
|
|
94
|
+
canSelectMany: false,
|
|
95
|
+
});
|
|
96
|
+
if (uris && uris[0]) {
|
|
97
|
+
await ThemeManager.importCustomTheme(uris[0]);
|
|
98
|
+
// 导入后刷新主题列表
|
|
99
|
+
if (previewManager) {
|
|
100
|
+
previewManager.refreshThemeList();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// CSS 变量收集器
|
|
2
|
+
// 从主题 CSS 文本中提取所有设计令牌的声明值
|
|
3
|
+
|
|
4
|
+
/** 设计令牌变量名清单 */
|
|
5
|
+
const DESIGN_TOKEN_NAMES = [
|
|
6
|
+
'--font-family-base', '--font-family-heading', '--font-family-code',
|
|
7
|
+
'--font-size-root', '--line-height-base',
|
|
8
|
+
'--color-bg', '--color-text', '--color-text-muted',
|
|
9
|
+
'--color-border', '--color-link', '--color-accent',
|
|
10
|
+
'--color-accent-dark', '--color-accent-light',
|
|
11
|
+
'--color-selection-bg',
|
|
12
|
+
'--code-bg', '--code-color', '--code-block-bg', '--code-block-text',
|
|
13
|
+
'--blockquote-bg', '--blockquote-border', '--blockquote-color',
|
|
14
|
+
'--table-header-bg', '--table-border',
|
|
15
|
+
'--radius-sm', '--radius-md', '--radius-lg',
|
|
16
|
+
'--mermaid-background', '--mermaid-border-color',
|
|
17
|
+
'--mermaid-node-stroke', '--mermaid-node-fill', '--mermaid-node-text',
|
|
18
|
+
'--mermaid-edge-stroke', '--mermaid-edge-stroke-width',
|
|
19
|
+
'--mermaid-cluster-stroke', '--mermaid-cluster-fill',
|
|
20
|
+
'--mermaid-label-text', '--mermaid-font-family', '--mermaid-font-size',
|
|
21
|
+
'--mermaid-cscale0', '--mermaid-cscale1', '--mermaid-cscale2',
|
|
22
|
+
'--mermaid-cscale3', '--mermaid-cscale4', '--mermaid-cscale5',
|
|
23
|
+
'--mermaid-cscale6', '--mermaid-cscale7', '--mermaid-cscale8',
|
|
24
|
+
'--mermaid-cscale9', '--mermaid-cscale10', '--mermaid-cscale11',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 从 CSS 文本中提取所有设计令牌的声明值
|
|
29
|
+
* @param themeCSS 主题 CSS 文本(foundation + theme)
|
|
30
|
+
* @returns 变量名 → 变量值的映射
|
|
31
|
+
*/
|
|
32
|
+
export function collectCSSVariables(themeCSS: string): Record<string, string> {
|
|
33
|
+
const vars: Record<string, string> = {};
|
|
34
|
+
for (const name of DESIGN_TOKEN_NAMES) {
|
|
35
|
+
const escaped = name.replace(/-/g, '\\-');
|
|
36
|
+
const regex = new RegExp(`${escaped}\\s*:\\s*([^;]+);`);
|
|
37
|
+
const match = themeCSS.match(regex);
|
|
38
|
+
if (match) vars[name] = match[1].trim();
|
|
39
|
+
}
|
|
40
|
+
return vars;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 生成 :root CSS 块(用于导出 HTML)
|
|
45
|
+
* @param vars CSS 变量映射
|
|
46
|
+
*/
|
|
47
|
+
export function buildRootCSSBlock(vars: Record<string, string>): string {
|
|
48
|
+
const lines = Object.entries(vars).map(([k, v]) => ` ${k}: ${v};`);
|
|
49
|
+
return `:root {\n${lines.join('\n')}\n}`;
|
|
50
|
+
}
|