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/README_CN.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# ColaView MD
|
|
2
|
+
|
|
3
|
+
[](https://code.visualstudio.com/)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](package.json)
|
|
7
|
+
|
|
8
|
+
VS Code 富文本 Markdown 预览与 PDF/HTML/Word 导出扩展 — 基于 [ColaMD](https://github.com/byteuser1977/ColaMD-extend) 渲染引擎(CodeMirror 6 内核)。
|
|
9
|
+
|
|
10
|
+
## 功能特性
|
|
11
|
+
|
|
12
|
+
- **所见即所得预览** — CodeMirror 6 驱动的只读编辑器,实时渲染 Markdown 富文本。源码缓冲区是唯一真相,导出零序列化损耗
|
|
13
|
+
- **数学公式** — KaTeX 集成,支持行内 `$...$` 和块级 `$$...$$` 公式(字体通过 base64 内联)
|
|
14
|
+
- **Mermaid 图表** — 17+ 种图表:流程图、时序图、类图、状态图、ER 图、甘特图、思维导图等
|
|
15
|
+
- **PDF 导出** — Puppeteer 无头 Chrome 生成 A4 PDF,完整保留主题样式
|
|
16
|
+
- **HTML 导出** — 独立 `.html` 文件,内嵌 CSS 和字体,零依赖分享
|
|
17
|
+
- **Word 导出** — 高保真 `.docx`,支持标题、列表、表格、图片、代码块、脚注,及 KaTeX/Mermaid 转图
|
|
18
|
+
- **导出保留主题样式** — PDF/HTML/Word 导出继承当前预览主题的字体、强调色、表格样式和引用块内边距
|
|
19
|
+
- **12 套内置主题** — Light、Dark、Elegant、Sepia、Notion、Bear、Writer、Solarized Dark、Nord、Gruvbox、Dracula、Midnight
|
|
20
|
+
- **自定义主题目录** — 在工作区根目录 `.themes/` 文件夹中放入 `.css` 文件即可自动识别
|
|
21
|
+
- **右键上下文菜单** — 预览面板内直接导出 HTML/PDF、切换主题(含子菜单)、导入自定义主题
|
|
22
|
+
- **实时同步** — 编辑后 150ms 防抖更新,实验性编辑器/预览滚动同步
|
|
23
|
+
- **源码保真** — 原始 Markdown 字节原样保留;导出直接使用缓冲区内容,无序列化损耗
|
|
24
|
+
|
|
25
|
+
## 快速开始
|
|
26
|
+
|
|
27
|
+
1. 安装扩展
|
|
28
|
+
2. 在 VS Code 中打开 `.md` 文件
|
|
29
|
+
3. `Ctrl+Shift+P` → **"ColaView MD: Show Preview"**
|
|
30
|
+
4. 侧边栏打开富文本预览
|
|
31
|
+
|
|
32
|
+
## 命令与使用方式
|
|
33
|
+
|
|
34
|
+
### 命令面板 (`Ctrl+Shift+P`)
|
|
35
|
+
|
|
36
|
+
| 命令 | 说明 |
|
|
37
|
+
|------|------|
|
|
38
|
+
| `ColaView MD: Show Preview` | 打开或聚焦预览面板 |
|
|
39
|
+
| `ColaView MD: Export to PDF...` | 导出为 A4 PDF |
|
|
40
|
+
| `ColaView MD: Export to HTML...` | 导出为独立 HTML |
|
|
41
|
+
| `ColaView MD: Export to Word...` | 导出为 `.docx` Word 文档 |
|
|
42
|
+
| `ColaView MD: Switch Preview Theme...` | 切换主题:12 套内置 + 自定义 |
|
|
43
|
+
| `ColaView MD: Import Custom Theme...` | 导入 `.css` 自定义主题 |
|
|
44
|
+
|
|
45
|
+
### 右键上下文菜单(预览面板内)
|
|
46
|
+
|
|
47
|
+
预览面板打开后,任意位置右键可访问:
|
|
48
|
+
|
|
49
|
+
| 菜单项 | 说明 |
|
|
50
|
+
|--------|------|
|
|
51
|
+
| **Export HTML** | 将当前预览导出为独立 HTML |
|
|
52
|
+
| **Export PDF** | 将当前预览导出为 A4 PDF |
|
|
53
|
+
| **Export Word** | 将当前预览导出为 `.docx` Word 文档 |
|
|
54
|
+
| **Theme ▸** | 子菜单列出所有内置 + 自定义主题(✓ 标记当前激活) |
|
|
55
|
+
| **Import Theme...** | 打开文件选择器导入 `.css` 文件 |
|
|
56
|
+
|
|
57
|
+
## 主题
|
|
58
|
+
|
|
59
|
+
### 内置主题
|
|
60
|
+
|
|
61
|
+
| 主题 | 风格 | 适用场景 |
|
|
62
|
+
|------|------|----------|
|
|
63
|
+
| **Light** | 干净白底,蓝色调 | 通用、文档 |
|
|
64
|
+
| **Dark** | GitHub Dark 配色 | 夜间编程 |
|
|
65
|
+
| **Elegant** | 暖色衬线,米色基调 | 学术论文、长文 |
|
|
66
|
+
| **Sepia** | 暖褐色调,纸质质感 | 长时间阅读、护眼 |
|
|
67
|
+
| **Notion** | Not.so MCP 风格 | 类 Notion 极简风 |
|
|
68
|
+
| **Bear** | Bear.app 笔记风格 | 笔记、随笔 |
|
|
69
|
+
| **Writer** | 等宽友好 | 技术文档、含代码多的文档 |
|
|
70
|
+
| **Solarized Dark** | Ethan Schoonover 调色板 | 低对比深色编码 |
|
|
71
|
+
| **Nord** | 北极蓝调色板 | 沉静专注写作 |
|
|
72
|
+
| **Gruvbox** | 复古 80 年代终端风 | 怀旧、高对比 |
|
|
73
|
+
| **Dracula** | Zeno Rocha 调色板 | 活力深色主题 |
|
|
74
|
+
| **Midnight** | 深蓝 + 金色点缀 | 夜间写作、高级感 |
|
|
75
|
+
|
|
76
|
+
### 自定义主题
|
|
77
|
+
|
|
78
|
+
在工作区根目录的 `.themes/` 目录下放置 `.css` 文件。扩展内置了 2 套自定义主题:
|
|
79
|
+
|
|
80
|
+
| 主题 | 风格 | 适用场景 |
|
|
81
|
+
|------|------|----------|
|
|
82
|
+
| **Academic Paper(学术论文)** | GB/T 7713 标准,衬线正文,三线表,纯黑白 | 学术论文、正式文档、打印 |
|
|
83
|
+
| **Trae Blue** | Trae IDE 文档风格,白底 slate 灰字,蓝色点缀 | 技术文档、现代文档编写 |
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
my-project/
|
|
87
|
+
├── .themes/
|
|
88
|
+
│ ├── my-dark.css # 在主题菜单中显示为 "My-dark"
|
|
89
|
+
│ └── corporate.css # 在主题菜单中显示为 "Corporate"
|
|
90
|
+
└── README.md
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
自定义主题会被自动检测,与内置主题一起出现在命令面板和右键菜单的主题列表中。
|
|
94
|
+
|
|
95
|
+
通过命令面板或设置切换:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{ "colaview.theme": "nord" }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
导入自定义 CSS:`Ctrl+Shift+P` → "ColaView MD: Import Custom Theme..." 或右键菜单 → "Import Theme..."
|
|
102
|
+
|
|
103
|
+
## 配置项
|
|
104
|
+
|
|
105
|
+
| 配置 | 类型 | 默认值 | 说明 |
|
|
106
|
+
|------|------|--------|------|
|
|
107
|
+
| `colaview.theme` | `string` | `"elegant"` | 预览主题:`light`、`dark`、`elegant`、`sepia`、`notion`、`bear`、`writer`、`solarized-dark`、`nord`、`gruvbox`、`dracula`、`midnight` 或任意自定义主题名 |
|
|
108
|
+
| `colaview.plugins.math` | `boolean` | `true` | *(已废弃,v0.3.0 起默认启用)* KaTeX 已内置于 ColaMD 引擎,无法单独关闭 |
|
|
109
|
+
| `colaview.plugins.mermaid` | `boolean` | `true` | *(已废弃,v0.3.0 起默认启用)* Mermaid 已内置于 ColaMD 引擎,无法单独关闭 |
|
|
110
|
+
| `colaview.pdfMethod` | `string` | `"puppeteer"` | PDF 引擎:`puppeteer` 或 `webviewPrint` |
|
|
111
|
+
| `colaview.autoPreview` | `boolean` | `false` | 打开 `.md` 文件时自动显示预览 |
|
|
112
|
+
| `colaview.customThemesPath` | `string` | `""` | 自定义主题 CSS 目录路径 |
|
|
113
|
+
| `colaview.scrollSync` | `boolean` | `false` | **实验性功能** — 启用编辑器与预览面板的滚动同步 |
|
|
114
|
+
|
|
115
|
+
> **关于插件开关:** v0.3.0 起,数学公式和 Mermaid 图表是 CodeMirror 6 版 ColaMD 引擎的内置功能,始终启用。`colaview.plugins.math` 和 `colaview.plugins.mermaid` 配置项为向后兼容保留,但已不再生效。
|
|
116
|
+
|
|
117
|
+
## 支持的语法
|
|
118
|
+
|
|
119
|
+
**标准 Markdown** — 标题、粗体、斜体、删除线、代码块、链接、图片、列表、引用
|
|
120
|
+
|
|
121
|
+
**GFM 扩展** — 表格、任务列表、脚注、自动链接
|
|
122
|
+
|
|
123
|
+
**数学公式(KaTeX)**
|
|
124
|
+
|
|
125
|
+
```markdown
|
|
126
|
+
行内:$E = mc^2$
|
|
127
|
+
|
|
128
|
+
块级:
|
|
129
|
+
$$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**图表(Mermaid)**
|
|
133
|
+
|
|
134
|
+
````markdown
|
|
135
|
+
```mermaid
|
|
136
|
+
graph LR
|
|
137
|
+
A[Markdown] --> B[ColaView]
|
|
138
|
+
B --> C[PDF]
|
|
139
|
+
B --> D[HTML]
|
|
140
|
+
```
|
|
141
|
+
````
|
|
142
|
+
|
|
143
|
+
支持:流程图、时序图、类图、状态图、ER 图、用户旅程、饼图、甘特图、Git 图、思维导图、时间线、四象限图、XY 图、C4 架构图、Sankey 图、Block 图、架构图
|
|
144
|
+
|
|
145
|
+
## 技术架构
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
┌─────────────┐ postMessage ┌──────────────────┐
|
|
149
|
+
│ Extension │ ◄──────────────────► │ WebView │
|
|
150
|
+
│ (Node.js) │ │ (CodeMirror 6/ │
|
|
151
|
+
│ │ raw markdown ──► │ ColaMD 渲染器) │
|
|
152
|
+
│ ThemeManager│ theme/css ──► │ │
|
|
153
|
+
│ Exporters │ ◄── 完整 HTML │ 只读富文本预览 │
|
|
154
|
+
│ │ │ + 右键上下文菜单 │
|
|
155
|
+
└─────────────┘ └──────────────────┘
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**核心设计:** 扩展端将原始 Markdown 发送到 WebView,由 ColaMD(CodeMirror 6 内核)渲染为只读富文本预览。源码缓冲区是唯一真相,导出时直接使用缓冲区内容,零序列化损耗。导出时,WebView 异步构建完整独立 HTML(含 KaTeX 字体、Mermaid SVG、主题 CSS),返回给扩展端。
|
|
159
|
+
|
|
160
|
+
### 安全模型
|
|
161
|
+
|
|
162
|
+
WebView 采用严格的内容安全策略(CSP):
|
|
163
|
+
|
|
164
|
+
1. `style-src 'unsafe-inline'` — CodeMirror 6 动态样式和 KaTeX 内联字体需要
|
|
165
|
+
2. `script-src 'unsafe-inline'` — esbuild IIFE 打包格式需要
|
|
166
|
+
3. 所有资源 URI 通过 `webview.asWebviewUri()` 解析,实现沙箱隔离
|
|
167
|
+
4. 即使 Markdown 内容包含恶意脚本也能防止 XSS 注入
|
|
168
|
+
|
|
169
|
+
### 项目结构
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
src/
|
|
173
|
+
├── extension.ts # 入口(activate/deactivate),错误隔离
|
|
174
|
+
├── commands/commands.ts # 命令注册(showPreview, exportHTML, exportPDF 等)
|
|
175
|
+
├── preview/
|
|
176
|
+
│ ├── preview-manager.ts # WebView 生命周期、消息处理、防抖同步
|
|
177
|
+
│ └── webview/
|
|
178
|
+
│ ├── index.html # WebView 模板 + 右键菜单样式
|
|
179
|
+
│ └── app.ts # ColaMD (CM6) 初始化 + 右键菜单 + 滚动同步
|
|
180
|
+
├── export/
|
|
181
|
+
│ ├── pdf-exporter.ts # Puppeteer PDF 生成(A4、保留背景)
|
|
182
|
+
│ ├── html-exporter.ts # 独立 HTML 导出(内嵌 CSS)
|
|
183
|
+
│ ├── docx-exporter.ts # Word (.docx) 导出(docx + remark-parse/remark-gfm)
|
|
184
|
+
│ ├── render-export-images.ts # KaTeX/Mermaid → PNG(无头 Chrome)用于 Word 导出
|
|
185
|
+
│ └── theme-style.ts # 主题 CSS → 语义化 HTML 样式转换器(供导出使用)
|
|
186
|
+
├── themes/
|
|
187
|
+
│ ├── theme-manager.ts # 主题加载、切换、.themes/ 目录扫描、导入
|
|
188
|
+
│ ├── foundation.css # 基础 CSS 变量层(颜色、间距)
|
|
189
|
+
│ └── built-in/ # 12 套内置主题(light.css, dark.css, elegant.css, sepia.css, ...)
|
|
190
|
+
└── types/
|
|
191
|
+
└── colamd-renderer.d.ts # ColaMD 2.7.9 npm 包本地类型声明
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## 开发
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
git clone https://github.com/bytechain/vscode-colaview.git
|
|
198
|
+
cd vscode-colaview
|
|
199
|
+
npm install
|
|
200
|
+
|
|
201
|
+
# 构建(esbuild 将所有依赖打包到 out/)
|
|
202
|
+
npm run build
|
|
203
|
+
|
|
204
|
+
# 监听模式
|
|
205
|
+
npm run watch
|
|
206
|
+
|
|
207
|
+
# 打包 .vsix
|
|
208
|
+
npm run package
|
|
209
|
+
|
|
210
|
+
# 调试:在 VS Code 中按 F5 启动扩展开发宿主
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### 构建系统
|
|
214
|
+
|
|
215
|
+
项目使用 **esbuild** 打包 — 扩展端(`out/extension.js`)是一个仅依赖 VS Code API 的小型 CJS bundle。WebView 端(`out/preview/webview/app.js`)是包含完整 ColaMD 2.7.9 渲染引擎(CodeMirror 6 + Mermaid + KaTeX)的 IIFE bundle — 未压缩约 3.4MB,gzip 后约 400KB。构建时自动复制资源文件(CSS、WebView HTML、KaTeX 样式表、Mermaid 脚本)到 `out/` 目录,确保打包安装后功能正常。
|
|
216
|
+
|
|
217
|
+
## 更新日志
|
|
218
|
+
|
|
219
|
+
### v0.3.0(当前版本)
|
|
220
|
+
|
|
221
|
+
- **📝 Word 导出(`.docx`)** — 从 ColaMD-extend 移植。高保真 Word 导出,支持标题、段落、行内样式、代码块、列表、表格、引用块、水平线、图片、脚注,以及 KaTeX/Mermaid 转图。
|
|
222
|
+
- **🎨 导出保留主题样式** — 新增 `theme-style.ts` 转换模块,将编辑器专属选择器(`#editor .cm-content .cm-md-*`)映射为语义化 HTML 选择器,PDF/HTML/Word 导出继承当前预览主题的字体、强调色、表格表头样式和引用块内边距。
|
|
223
|
+
- **🐛 修复 PDF 导出空白** — 剥离 ColaMD 的 Electron `@media print` 规则(该规则会隐藏导出的 `<article>` 元素),PDF(和 HTML)导出不再空白。
|
|
224
|
+
- **🐛 修复 HTML 导出主题样式失效** — 修复导出 HTML 因编辑器专属选择器无法匹配而丢失主题样式的问题。
|
|
225
|
+
- **📦 新增依赖** — `docx`、`katex`、`remark-parse`、`remark-gfm`、`unified`。
|
|
226
|
+
- **🔧 引擎升级 — ColaMD 2.7.9(CodeMirror 6)** — 从 Milkdown/ProseMirror 迁移到 CodeMirror 6。源码缓冲区成为唯一真相,导出零序列化损耗
|
|
227
|
+
- **🎨 12 套内置主题** — 从 4 套扩展到 12 套:Light、Dark、Elegant、Sepia、Notion、Bear、Writer、Solarized Dark、Nord、Gruvbox、Dracula、Midnight。默认主题改为 Elegant
|
|
228
|
+
- **📤 异步 HTML 导出** — `buildExportHTML()` 变为异步,自动等待 Mermaid 图表和 KaTeX 字体渲染完成后再产出最终 HTML
|
|
229
|
+
- **🗑️ 移除插件开关** — 数学公式和 Mermaid 已内置于 ColaMD 引擎;`colaview.plugins.math` 和 `colaview.plugins.mermaid` 配置项不再生效
|
|
230
|
+
- **📰 移除 Newsprint 主题** — Newsprint 在 ColaMD 2.7.9 中不存在
|
|
231
|
+
- **🔄 DOM 结构变更** — 预览容器使用 `.cm-editor` / `.cm-scroller` / `.cm-content` 替代 `.ProseMirror`。滚动同步目标更新为 `.cm-scroller`
|
|
232
|
+
- **📦 依赖升级** — `@bytechain.cn/colamd` 从 `^1.5.2` 升级到 `^2.7.9`。2.7.9 npm 包未发布 `.d.ts` 文件,本地补充类型声明
|
|
233
|
+
- **🖼️ KaTeX 字体内联** — KaTeX 字体 base64 编码在 `colamd.css` 中,PDF 导出无需额外资源路径
|
|
234
|
+
|
|
235
|
+
### v0.2.0
|
|
236
|
+
|
|
237
|
+
- **🏗️ 架构重构** — 激活流程错误隔离、PreviewManager 重构、math/mermaid 设置变更自动实时同步
|
|
238
|
+
- **🖱️ 右键上下文菜单** — 预览面板内直接导出 HTML/PDF、切换主题(含子菜单)、导入自定义主题
|
|
239
|
+
- **🎨 新增自定义主题** — 学术论文 Academic Paper(GB/T 7713 标准)和 Trae Blue(Trae IDE 文档风格)
|
|
240
|
+
- **🧹 代码清理** — 移除废弃文件(`debug-load.js`、`configuration.ts`、`file-utils.ts`)
|
|
241
|
+
- **🐛 问题修复** — h4 标题颜色一致性、代码块边框颜色、打印页边距宽度
|
|
242
|
+
|
|
243
|
+
### v0.1.3
|
|
244
|
+
|
|
245
|
+
- **🔄 实验性滚动同步** — 编辑器与预览面板双向滚动同步。通过 `colaview.scrollSync` 设置启用。
|
|
246
|
+
- 增强扩展激活和预览管理器初始化时的错误处理
|
|
247
|
+
|
|
248
|
+
### v0.1.2
|
|
249
|
+
|
|
250
|
+
- **🐛 引用块背景色修复** — 修复 Dark、Light、Newsprint 主题下 blockquote 背景色被页面背景色覆盖的问题
|
|
251
|
+
|
|
252
|
+
### v0.1.1
|
|
253
|
+
|
|
254
|
+
- **🎨 主题一致性修复** — 统一 4 套内置主题(Light、Dark、Elegant、Newsprint)的 `--code-color` 和 `--code-block-text` CSS 变量,解决行内代码与代码块字体颜色不一致的问题
|
|
255
|
+
- **📰 Newsprint 主题对齐** — Newsprint 主题变量完全对齐 [ColaMD-extend](https://github.com/byteuser1977/ColaMD-extend) base.css,包括衬线字体(PT Serif 字体栈)、代码颜色继承及全部语义化颜色 token
|
|
256
|
+
- **🔧 Light 主题补全** — 补充 Light 主题缺失的 `--table-border` 变量,确保表格样式一致
|
|
257
|
+
- **📦 依赖迁移** — 从本地 ColaMD 项目引用切换为 npm 包 `@bytechain.cn/colamd` (^1.5.2)
|
|
258
|
+
|
|
259
|
+
### v0.1.0
|
|
260
|
+
|
|
261
|
+
- 首次发布,包含所见即所得预览、PDF/HTML 导出、4 套内置主题、自定义主题支持
|
|
262
|
+
|
|
263
|
+
## 许可证
|
|
264
|
+
|
|
265
|
+
[MIT](LICENSE)
|
package/RELEASE_NOTES.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Release Notes
|
|
2
|
+
|
|
3
|
+
## v0.3.0 (2026-11-06)
|
|
4
|
+
|
|
5
|
+
### 🎨 Theme-Faithful Export
|
|
6
|
+
|
|
7
|
+
Exports now inherit the current preview theme's visual styling. Previously, theme CSS targeted editor-only DOM selectors (`#editor .cm-content .cm-md-*`), which could not match the semantic HTML (`<h1>`, `<strong>`, `<code>`, `<table>`, `<blockquote>`...) produced by PDF/HTML/Word export — causing fonts, accent colors, table header styling and blockquote padding to fall back to defaults.
|
|
8
|
+
|
|
9
|
+
The new `src/export/theme-style.ts` conversion layer fixes this by:
|
|
10
|
+
|
|
11
|
+
- Mapping `.cm-md-*` decoration classes to semantic HTML tags (e.g. `.cm-md-strong` → `strong`, `.cm-md-inlinecode` → `code`, `.cm-md-atxheading1` → `h1`)
|
|
12
|
+
- Extracting `:root` CSS variables and `.cm-content` font family / line-height tokens from the theme
|
|
13
|
+
- Injecting the converted styles into PDF, HTML and Word exports so the output faithfully reflects the active preview theme
|
|
14
|
+
|
|
15
|
+
### 📝 Word Export — `.docx`
|
|
16
|
+
|
|
17
|
+
Reference implementation ported from [ColaMD-extend](https://github.com/byteuser1977/ColaMD-extend)'s `docx-export.ts`. Export any Markdown document to a high-fidelity Word document:
|
|
18
|
+
|
|
19
|
+
- **Full structure** — headings, paragraphs, blockquotes, horizontal rules
|
|
20
|
+
- **Inline styles** — bold, italic, strikethrough, inline code, links, `==highlight==`, footnotes
|
|
21
|
+
- **Code blocks** — monospace with shaded background
|
|
22
|
+
- **Lists** — ordered (with correct numbering), unordered, and task lists (`☑`/`☐`)
|
|
23
|
+
- **Tables** — GFM tables with header shading and column alignment
|
|
24
|
+
- **Images** — local, `data:` and remote (`http(s)`) images embedded natively
|
|
25
|
+
- **KaTeX formulas** — inline/display math rasterized to images via headless Chrome + KaTeX
|
|
26
|
+
- **Mermaid diagrams** — rasterized to images via headless Chrome + Mermaid
|
|
27
|
+
|
|
28
|
+
The Word export runs entirely in the extension host (`docx` v9 → OOXML), parsing Markdown with `unified`/`remark-parse`/`remark-gfm`. Electron's `nativeImage` has been replaced with a pure-JS image dimension sniffer (`sniffImage`), so no DOM is required.
|
|
29
|
+
|
|
30
|
+
**Usage** — Command Palette → "ColaView MD: Export to Word...", editor/explorer context menu, or preview right-click menu.
|
|
31
|
+
|
|
32
|
+
New direct dependencies: `docx`, `katex`, `remark-parse`, `remark-gfm`, `unified`.
|
|
33
|
+
|
|
34
|
+
### 🐛 PDF Blank Export Fixed
|
|
35
|
+
|
|
36
|
+
The exported PDF was blank because `colamd.css`'s Electron desktop print rule
|
|
37
|
+
|
|
38
|
+
```css
|
|
39
|
+
@media print {
|
|
40
|
+
body > :not(#editor-region), #editor .code-copy-btn, ... { display: none !important }
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
hides the entire exported `<article>` (which lives inside `<body>` without an `#editor-region` wrapper). The rule is now stripped from the inlined CSS at source, so both PDF and HTML export render correctly.
|
|
45
|
+
|
|
46
|
+
### 🔧 Engine Upgrade — ColaMD 2.7.9 (CodeMirror 6)
|
|
47
|
+
|
|
48
|
+
This release upgrades the entire rendering engine from Milkdown/ProseMirror to **CodeMirror 6** via `@bytechain.cn/colamd@2.7.9`. This is a major version jump (from `^1.5.2` to `^2.7.9`) with fundamentally different architecture:
|
|
49
|
+
|
|
50
|
+
**Source Buffer as Single Source of Truth** — Unlike ProseMirror's document model which could silently serialize Markdown back, CodeMirror 6 treats the raw source buffer as the canonical state. Export operations use buffer content directly, guaranteeing zero serialization loss.
|
|
51
|
+
|
|
52
|
+
**Async Export Pipeline** — `buildExportHTML()` now returns a Promise. Internally it calls `ensureAllPluginsRendered()` first, waiting for Mermaid diagrams and KaTeX fonts to finish before producing the final HTML. The WebView → extension handshake remains identical (message passing), but the WebView side now properly awaits completion.
|
|
53
|
+
|
|
54
|
+
**New CM6 DOM Structure** — The preview container changed from `.ProseMirror` to `.cm-editor` / `.cm-scroller` / `.cm-content`. Scroll sync had to be retargeted from `#editor` to `.cm-scroller`.
|
|
55
|
+
|
|
56
|
+
### 🎨 12 Built-in Themes
|
|
57
|
+
|
|
58
|
+
| Theme | Style |
|
|
59
|
+
|-------|-------|
|
|
60
|
+
| **Light** | Clean white, blue accents |
|
|
61
|
+
| **Dark** | GitHub Dark palette |
|
|
62
|
+
| **Elegant** *(new default)* | Warm serif, beige tones |
|
|
63
|
+
| **Sepia** | Warm sepia, paper texture |
|
|
64
|
+
| **Notion** | Not.so MCP minimalism |
|
|
65
|
+
| **Bear** | Bear.app note style |
|
|
66
|
+
| **Writer** | Monospace-friendly |
|
|
67
|
+
| **Solarized Dark** | Ethan Schoonover palette |
|
|
68
|
+
| **Nord** | Arctic blue |
|
|
69
|
+
| **Gruvbox** | Retro 80s terminal |
|
|
70
|
+
| **Dracula** | Zeno Rocha vibrant dark |
|
|
71
|
+
| **Midnight** | Deep navy + gold |
|
|
72
|
+
|
|
73
|
+
*Newsprint was removed* — it is not part of ColaMD 2.7.9. Users with `colaview.theme: "newsprint"` will get the default ("elegant").
|
|
74
|
+
|
|
75
|
+
### 🗑️ Plugin Toggle Deprecated
|
|
76
|
+
|
|
77
|
+
`colaview.plugins.math` and `colaview.plugins.mermaid` are now **no-ops**. Math and Mermaid are integral parts of the CodeMirror 6 engine — they cannot be independently disabled. The settings remain in `package.json` for backward compatibility but have no effect at runtime.
|
|
78
|
+
|
|
79
|
+
### 📦 Build Size
|
|
80
|
+
|
|
81
|
+
| | v0.2.0 | v0.3.0 |
|
|
82
|
+
|--|-------|-------|
|
|
83
|
+
| Extension (`out/extension.js`) | ~28KB | ~30KB |
|
|
84
|
+
| WebView (`out/preview/webview/app.js`) | ~50KB | ~3.4MB |
|
|
85
|
+
| WebView (gzip) | ~15KB | ~400KB |
|
|
86
|
+
|
|
87
|
+
The WebView bundle grew significantly because it now includes the full CodeMirror 6 + Mermaid + KaTeX rendering engine inlined via esbuild IIFE. The extension side stays lean.
|
|
88
|
+
|
|
89
|
+
### ⚠️ Security Model Change
|
|
90
|
+
|
|
91
|
+
CSP was relaxed from nonce-based to `'unsafe-inline'` for both `style-src` and `script-src`. This is required by CodeMirror 6 (dynamic inline styles) and esbuild IIFE format. Sandbox isolation via `asWebviewUri()` remains intact.
|
|
92
|
+
|
|
93
|
+
### 📄 KaTeX Fonts
|
|
94
|
+
|
|
95
|
+
No more font resource path management headaches. KaTeX fonts are base64-encoded inside `colamd.css` — they work in WebView preview, HTML export, and PDF export without any additional configuration.
|
|
96
|
+
|
|
97
|
+
### Files Changed
|
|
98
|
+
10 files changed — 2,438 insertions, 912 deletions
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## v0.2.0 (2025-05-30)
|
|
103
|
+
|
|
104
|
+
### 🏗️ Architecture Overhaul
|
|
105
|
+
|
|
106
|
+
**Error-Isolated Activation** — Extension `activate()` now uses independent try/catch blocks for ThemeManager, PreviewManager, and command registration. A failure in one component no longer blocks the others, improving extension reliability in edge cases.
|
|
107
|
+
|
|
108
|
+
**PreviewManager Refactoring** — Split monolithic `setupEventListeners()` into dedicated methods (`registerActiveEditorListener`, `registerScrollSyncListeners`, `registerConfigurationListener`) for better maintainability and separation of concerns.
|
|
109
|
+
|
|
110
|
+
**Runtime Plugin Toggle Sync** — `colaview.plugins.math` and `colaview.plugins.mermaid` setting changes are now automatically synced to the preview WebView via `onDidChangeConfiguration`. No manual reload required — toggle KaTeX or Mermaid rendering in real-time.
|
|
111
|
+
|
|
112
|
+
### ✨ New Features
|
|
113
|
+
|
|
114
|
+
**Right-Click Context Menu** — Native context menu inside the preview WebView panel:
|
|
115
|
+
- Export HTML / PDF directly from the preview
|
|
116
|
+
- Switch theme via a nested submenu (✓ marks active theme)
|
|
117
|
+
- Import custom `.css` theme file
|
|
118
|
+
- All commands are now accessible without leaving the preview panel
|
|
119
|
+
|
|
120
|
+
**New Custom Themes:**
|
|
121
|
+
| Theme | File | Style |
|
|
122
|
+
|-------|------|-------|
|
|
123
|
+
| **Academic Paper** | `.themes/academic-paper.css` | GB/T 7713 standard — serif body, sans-serif headings, three-line tables, pure black-on-white |
|
|
124
|
+
| **Trae Blue** | `.themes/trae-blue.css` | Trae IDE documentation style — white + Slate gray, system sans-serif, blue (#3b82f6) accents |
|
|
125
|
+
|
|
126
|
+
**Read-Only Mode** — Preview ProseMirror editor now explicitly styles as read-only: cursor hidden, selection highlights disabled.
|
|
127
|
+
|
|
128
|
+
### 🧹 Cleanup
|
|
129
|
+
|
|
130
|
+
| Removed | Reason |
|
|
131
|
+
|---------|--------|
|
|
132
|
+
| `debug-load.js` | Obsolete development helper |
|
|
133
|
+
| `src/config/configuration.ts` | Unused module |
|
|
134
|
+
| `src/utils/file-utils.ts` | Unused module |
|
|
135
|
+
| Scroll sync fields (`scrollTop`, `scrollHeight`, `clientHeight`, `scrollPercent`) | Removed unused fields from shared message types |
|
|
136
|
+
|
|
137
|
+
### 🐛 Fixes
|
|
138
|
+
- Fixed h4 heading color inconsistency in exports
|
|
139
|
+
- Fixed code block border color mismatch after theme changes
|
|
140
|
+
- Fixed print margin width (reduced from 60px to 28px)
|
|
141
|
+
|
|
142
|
+
### Files Changed
|
|
143
|
+
42 files changed — 208,517 insertions, 208,696 deletions (includes colamd-renderer.js and colamd.css rebuild)
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## v0.1.3 (2025-05-29)
|
|
148
|
+
|
|
149
|
+
### 🔄 Experimental Scroll Sync
|
|
150
|
+
|
|
151
|
+
Bidirectional scroll synchronization between VS Code editor and preview panel. When enabled, moving the cursor in the editor scrolls the preview to the matching position, and scrolling the preview highlights the corresponding editor line.
|
|
152
|
+
|
|
153
|
+
**Enable:** Set `colaview.scrollSync` to `true` in VS Code settings.
|
|
154
|
+
|
|
155
|
+
**Algorithm:** Uses relative position mapping (cursor-to-visible-range ratio) rather than simple percentage for more accurate positioning, with debouncing to prevent performance issues and circular reference prevention to avoid infinite scroll loops.
|
|
156
|
+
|
|
157
|
+
### 🛡️ Error Handling
|
|
158
|
+
- Enhanced error handling in extension activation
|
|
159
|
+
- Improved resilience in preview manager initialization
|
|
160
|
+
|
|
161
|
+
### 🐛 Fixes
|
|
162
|
+
- Fixed list indentation and symbol alignment in HTML/PDF exports
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## v0.1.2 (2025-05-28)
|
|
167
|
+
|
|
168
|
+
### 🐛 Bug Fix
|
|
169
|
+
|
|
170
|
+
**Blockquote Background Color** — Fixed blockquote background color being overridden by page background (`--bg-color`) in Dark, Light, and Newsprint themes.
|
|
171
|
+
|
|
172
|
+
#### Root Cause
|
|
173
|
+
The base blockquote rule in `colamd.css` did not set a `background` property, causing blockquotes to inherit `body`'s background color. Only the Elegant theme had an explicit override rule, so it was unaffected.
|
|
174
|
+
|
|
175
|
+
#### Fix
|
|
176
|
+
Added explicit `background: var(--blockquote-bg)` rules to all 3 affected built-in theme CSS files:
|
|
177
|
+
|
|
178
|
+
| Theme | Blockquote Background |
|
|
179
|
+
|-------|----------------------|
|
|
180
|
+
| **Dark** | `#161b22` (slightly lighter than page `#0d1117`) |
|
|
181
|
+
| **Light** | `#ffffff` |
|
|
182
|
+
| **Newsprint** | `#eae6de` (slightly darker than page `#f5f2eb`) |
|
|
183
|
+
|
|
184
|
+
### Files Changed
|
|
185
|
+
- `src/themes/built-in/dark.css` — Added blockquote background rule
|
|
186
|
+
- `src/themes/built-in/light.css` — Added blockquote background rule
|
|
187
|
+
- `src/themes/built-in/newsprint.css` — Added blockquote background rule
|
|
188
|
+
- `package.json` / `package-lock.json` — Version bump to 0.1.2
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## v0.1.1
|
|
193
|
+
|
|
194
|
+
- **🎨 Theme Consistency Fix** — Unified `--code-color` and `--code-block-text` CSS variables across all 4 built-in themes
|
|
195
|
+
- **📰 Newsprint Theme Alignment** — Aligned with ColaMD-extend base.css variables
|
|
196
|
+
- **🔧 Light Theme Completion** — Added missing `--table-border` variable
|
|
197
|
+
- **📦 Dependency Migration** — Switched to npm package `@bytechain.cn/colamd` (^1.5.2)
|
|
198
|
+
|
|
199
|
+
## v0.1.0
|
|
200
|
+
|
|
201
|
+
- Initial release with WYSIWYG preview, PDF/HTML export, 4 built-in themes, custom theme support
|
package/esbuild.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// esbuild 打包脚本 — 扩展宿主(Node.js) + WebView 浏览器端 分别打包
|
|
2
|
+
const esbuild = require('esbuild');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const isWatch = process.argv.includes('--watch');
|
|
7
|
+
const isProd = process.argv.includes('--production');
|
|
8
|
+
|
|
9
|
+
// ── 扩展宿主 (Node.js, CJS) ──
|
|
10
|
+
const extensionOpts = {
|
|
11
|
+
entryPoints: ['src/extension.ts'],
|
|
12
|
+
bundle: true,
|
|
13
|
+
outfile: 'out/extension.js',
|
|
14
|
+
external: ['vscode', 'puppeteer-core'],
|
|
15
|
+
format: 'cjs',
|
|
16
|
+
platform: 'node',
|
|
17
|
+
target: 'node18',
|
|
18
|
+
sourcemap: !isProd,
|
|
19
|
+
minify: isProd,
|
|
20
|
+
logLevel: 'info',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// ── WebView 浏览器端 (IIFE, bundled) ──
|
|
24
|
+
const webviewOpts = {
|
|
25
|
+
entryPoints: ['src/preview/webview/app.ts'],
|
|
26
|
+
bundle: true,
|
|
27
|
+
outfile: 'out/preview/webview/app.js',
|
|
28
|
+
format: 'iife',
|
|
29
|
+
platform: 'browser',
|
|
30
|
+
target: 'es2020',
|
|
31
|
+
sourcemap: !isProd,
|
|
32
|
+
minify: isProd,
|
|
33
|
+
logLevel: 'info',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
async function build() {
|
|
37
|
+
if (isWatch) {
|
|
38
|
+
const ctx1 = await esbuild.context(extensionOpts);
|
|
39
|
+
const ctx2 = await esbuild.context(webviewOpts);
|
|
40
|
+
await Promise.all([ctx1.watch(), ctx2.watch()]);
|
|
41
|
+
console.log('Watching for changes...');
|
|
42
|
+
} else {
|
|
43
|
+
await Promise.all([
|
|
44
|
+
esbuild.build(extensionOpts),
|
|
45
|
+
esbuild.build(webviewOpts),
|
|
46
|
+
]);
|
|
47
|
+
copyResources();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 复制资源文件到 out/ 目录(CSS、WebView HTML 等)
|
|
53
|
+
*/
|
|
54
|
+
function copyResources() {
|
|
55
|
+
const copies = [
|
|
56
|
+
{ src: 'src/preview/webview/index.html', dst: 'out/preview/webview/index.html' },
|
|
57
|
+
{ src: 'src/themes/built-in', dst: 'out/themes/built-in' },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// Copy ColaMD renderer CSS if available
|
|
61
|
+
const colamdCss = 'node_modules/@bytechain.cn/colamd/dist/lib/colamd.css';
|
|
62
|
+
if (fs.existsSync(colamdCss)) {
|
|
63
|
+
copies.push({ src: colamdCss, dst: 'out/preview/webview/colamd.css' });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Copy static assets needed by the host-side renderers (Word export).
|
|
67
|
+
// These live in node_modules, which .vscodeignore strips from the vsix,
|
|
68
|
+
// so they must be copied into out/assets/ to survive packaging.
|
|
69
|
+
const katexCss = 'node_modules/katex/dist/katex.min.css';
|
|
70
|
+
if (fs.existsSync(katexCss)) {
|
|
71
|
+
copies.push({ src: katexCss, dst: 'out/assets/katex.min.css' });
|
|
72
|
+
}
|
|
73
|
+
const mermaidJs = 'node_modules/mermaid/dist/mermaid.min.js';
|
|
74
|
+
if (fs.existsSync(mermaidJs)) {
|
|
75
|
+
copies.push({ src: mermaidJs, dst: 'out/assets/mermaid.min.js' });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const { src, dst } of copies) {
|
|
79
|
+
if (!fs.existsSync(src)) continue;
|
|
80
|
+
if (fs.statSync(src).isDirectory()) {
|
|
81
|
+
copyDirSync(src, dst);
|
|
82
|
+
} else {
|
|
83
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
84
|
+
fs.copyFileSync(src, dst);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log('Resources copied to out/');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 递归复制目录
|
|
92
|
+
*/
|
|
93
|
+
function copyDirSync(src, dst) {
|
|
94
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
95
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
96
|
+
const srcPath = path.join(src, entry.name);
|
|
97
|
+
const dstPath = path.join(dst, entry.name);
|
|
98
|
+
if (entry.isDirectory()) {
|
|
99
|
+
copyDirSync(srcPath, dstPath);
|
|
100
|
+
} else {
|
|
101
|
+
fs.copyFileSync(srcPath, dstPath);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
build().catch(() => process.exit(1));
|
package/icon.png
ADDED
|
Binary file
|