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.
Files changed (46) hide show
  1. package/.vscode/launch.json +30 -0
  2. package/.vscode/settings.json +7 -0
  3. package/.vscode/tasks.json +18 -0
  4. package/.vscodeignore +23 -0
  5. package/CHANGELOG.md +112 -0
  6. package/LICENSE +21 -0
  7. package/README.md +264 -2
  8. package/README_CN.md +265 -0
  9. package/RELEASE_NOTES.md +201 -0
  10. package/esbuild.js +106 -0
  11. package/icon.png +0 -0
  12. package/package.json +186 -6
  13. package/src/commands/commands.ts +105 -0
  14. package/src/export/css-collector.ts +50 -0
  15. package/src/export/docx-exporter.ts +923 -0
  16. package/src/export/html-exporter.ts +18 -0
  17. package/src/export/pdf-exporter.ts +121 -0
  18. package/src/export/render-export-images.ts +206 -0
  19. package/src/export/theme-style.ts +135 -0
  20. package/src/extension.ts +59 -0
  21. package/src/preview/preview-manager.ts +499 -0
  22. package/src/preview/webview/app.ts +371 -0
  23. package/src/preview/webview/index.html +127 -0
  24. package/src/themes/built-in/bear.css +38 -0
  25. package/src/themes/built-in/dark.css +20 -0
  26. package/src/themes/built-in/dracula.css +38 -0
  27. package/src/themes/built-in/elegant.css +52 -0
  28. package/src/themes/built-in/gruvbox.css +42 -0
  29. package/src/themes/built-in/light.css +20 -0
  30. package/src/themes/built-in/midnight.css +31 -0
  31. package/src/themes/built-in/nord.css +38 -0
  32. package/src/themes/built-in/notion.css +48 -0
  33. package/src/themes/built-in/sepia.css +47 -0
  34. package/src/themes/built-in/solarized-dark.css +35 -0
  35. package/src/themes/built-in/writer.css +44 -0
  36. package/src/themes/theme-manager.ts +180 -0
  37. package/src/types/colamd-renderer.d.ts +47 -0
  38. package/src/types.ts +20 -0
  39. package/test/fixtures/basic.md +34 -0
  40. package/test/fixtures/math.md +20 -0
  41. package/test/fixtures/mermaid.md +19 -0
  42. package/test/runTest.ts +30 -0
  43. package/test/suite/html-exporter.test.ts +20 -0
  44. package/test/suite/markdown-parser.test.ts +8 -0
  45. package/test/suite/theme-manager.test.ts +31 -0
  46. package/tsconfig.json +19 -0
@@ -0,0 +1,30 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Run Extension",
6
+ "type": "extensionHost",
7
+ "request": "launch",
8
+ "args": [
9
+ "--extensionDevelopmentPath=${workspaceFolder}"
10
+ ],
11
+ "outFiles": [
12
+ "${workspaceFolder}/out/**/*.js"
13
+ ],
14
+ "preLaunchTask": "${defaultBuildTask}"
15
+ },
16
+ {
17
+ "name": "Extension Tests",
18
+ "type": "extensionHost",
19
+ "request": "launch",
20
+ "args": [
21
+ "--extensionDevelopmentPath=${workspaceFolder}",
22
+ "--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
23
+ ],
24
+ "outFiles": [
25
+ "${workspaceFolder}/out/test/**/*.js"
26
+ ],
27
+ "preLaunchTask": "${defaultBuildTask}"
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "colaview.autoPreview": false,
3
+ "colaview.customThemesPath": ".themes/",
4
+ "colaview.theme": "newsprint",
5
+ "colaview.pdfMethod": "webviewPrint",
6
+ "colaview.plugins.math": false
7
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "type": "npm",
6
+ "script": "watch",
7
+ "problemMatcher": "$tsc-watch",
8
+ "isBackground": true,
9
+ "presentation": {
10
+ "reveal": "never"
11
+ },
12
+ "group": {
13
+ "kind": "build",
14
+ "isDefault": true
15
+ }
16
+ }
17
+ ]
18
+ }
package/.vscodeignore ADDED
@@ -0,0 +1,23 @@
1
+ .vscode/**
2
+ .gitignore
3
+ src/**
4
+ test/**
5
+ tsconfig.json
6
+ esbuild.js
7
+ debug-load.js
8
+ node_modules/**
9
+ !node_modules/puppeteer-core/**
10
+ !node_modules/@puppeteer/**
11
+ !node_modules/chromium-bidi/**
12
+ !node_modules/devtools-protocol/**
13
+ !node_modules/typed-query-selector/**
14
+ !node_modules/webdriver-bidi-protocol/**
15
+ !node_modules/ws/**
16
+ ../ColaMD-extend/**
17
+ **/*.ts
18
+ **/*.map
19
+ !out/**/*.js
20
+ !out/**/*.css
21
+ !out/**/*.html
22
+ .claude/**
23
+ .trae/**
package/CHANGELOG.md ADDED
@@ -0,0 +1,112 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.3.0] - 2026-11-06
6
+
7
+ ### Added
8
+ - Added **Word (`.docx`) export** — ported from ColaMD-extend's `docx-export.ts`. Exports high-fidelity `.docx` with headings, paragraphs, inline styles (bold/italic/strikethrough/inline-code/links/highlight), code blocks, ordered/unordered/task lists, tables, blockquotes, horizontal rules, local & remote images, footnotes, KaTeX formulas (rasterized to images), and Mermaid diagrams (rasterized to images). New command `colaview.exportWord` ("Export to Word...") in the command palette, editor context menu, explorer context menu, and preview right-click menu.
9
+ - Added `src/export/docx-exporter.ts` — pure-Node `markdownToDocx()` using `docx` v9 + `unified`/`remark-parse`/`remark-gfm`, with a pure-JS image dimension sniffer (`sniffImage`) in place of Electron's `nativeImage`.
10
+ - Added `src/export/render-export-images.ts` — headless-Chrome (puppeteer-core) rasterizes KaTeX and Mermaid to PNG, rewriting the source Markdown to image placeholders.
11
+ - Added direct dependencies: `docx`, `katex`, `remark-parse`, `remark-gfm`, `unified`.
12
+ - Added **9 new built-in themes**: Sepia, Notion, Bear, Writer, Solarized Dark, Nord, Gruvbox, Dracula, Midnight — expanding from 4 to 12 total built-in themes
13
+ - Added local **TypeScript type declarations** (`src/types/colamd-renderer.d.ts`) for `@bytechain.cn/colamd@2.7.9`, since the npm package does not publish `.d.ts` files
14
+ - Added `src/export/theme-style.ts` — **theme-faithful export**. Converts editor-specific theme selectors (`#editor .cm-content .cm-md-*`) into semantic HTML selectors (`h1`/`strong`/`em`/`code`/`table`/`blockquote`...) and extracts `:root` tokens plus `.cm-content` font/line-height, then injects the converted styles into PDF, HTML and Word exports so exported documents inherit the current preview theme's fonts, accent colors, table styling, blockquote padding, etc.
15
+
16
+ ### Changed
17
+ - **Engine upgrade: ColaMD 2.7.9** — Migrated from Milkdown/ProseMirror to **CodeMirror 6** rendering engine. Source buffer is now the single source of truth with zero serialization loss on export.
18
+ - **Async HTML export** — `buildExportHTML()` is now asynchronous. The WebView automatically waits for Mermaid diagrams and KaTeX fonts to finish rendering before producing the final standalone HTML.
19
+ - **12 built-in themes** total, up from 4. Default theme changed from `"light"` to `"elegant"`.
20
+ - **DOM structure changed** — Preview container uses `.cm-editor` / `.cm-scroller` / `.cm-content` (CM6) instead of `.ProseMirror`. Scroll sync target updated to `.cm-scroller`.
21
+ - **CSP relaxed** — `style-src 'unsafe-inline'` and `script-src 'unsafe-inline'` are now required (CodeMirror 6 dynamic styles + esbuild IIFE bundle). Nonce-based CSP removed.
22
+ - **Build system** — The WebView bundle now includes the full ColaMD 2.7.9 rendering engine (CM6 + Mermaid + KaTeX). WebView bundle size increased from ~50KB to ~3.4MB unminified (gzip ~400KB). Extension side remains small (~30KB).
23
+
24
+ ### Removed
25
+ - **Removed Newsprint theme** — Not available in ColaMD 2.7.9. Users who had `colaview.theme: "newsprint"` will fall back to the default ("elegant").
26
+ - **Removed runtime plugin toggle** — `colaview.plugins.math` and `colaview.plugins.mermaid` settings are retained for backward compatibility but no longer have any effect, since math and Mermaid are integral parts of the ColaMD 2.7.9 engine.
27
+ - **Removed local `colamd-renderer.js` copy** — The WebView now imports ColaMD directly from the npm package via esbuild bundling.
28
+
29
+ ### Fixed
30
+ - Fixed **PDF export rendering a blank page** — stripped the `@media print { ... #editor-region { display: none } }` rule (Electron desktop print rule) from the inlined `colamd.css` during WebView HTML construction, preventing the exported `<article>` from being hidden.
31
+ - Fixed **exported documents losing preview theme styles** — theme CSS used editor-only DOM selectors (`#editor .cm-content .cm-md-*`) that could not match the semantic HTML produced by PDF/HTML/Word export, causing fonts, accent colors, table headers and blockquote padding to fall back to defaults. Fixed via the new `theme-style.ts` conversion layer.
32
+ - Fixed scroll sync listening to wrong DOM node — CM6 uses `.cm-scroller` for scrolling instead of the container `#editor` element
33
+
34
+ ### Files Changed
35
+ - `package.json` — Bump `@bytechain.cn/colamd` from `^1.5.2` to `^2.7.9`, update theme enum, change default theme; add `docx`, `katex`, `remark-parse`, `remark-gfm`, `unified`
36
+ - `src/export/docx-exporter.ts` — New Word export converter
37
+ - `src/export/render-export-images.ts` — New KaTeX/Mermaid → PNG renderer for Word export
38
+ - `src/export/theme-style.ts` — New theme CSS → semantic HTML style converter for exports
39
+ - `src/preview/preview-manager.ts` — Strip Electron print rule from inlined CSS, add Word export message handler
40
+ - `src/types/colamd-renderer.d.ts` — New local type declarations
41
+ - `src/themes/theme-manager.ts` — Expand `BUILTIN_THEMES` to 12, update `THEME_CLASS_MAP`
42
+ - `src/themes/built-in/*.css` — 9 new theme CSS files
43
+ - `src/preview/webview/app.ts` — Complete rewrite for CM6 API
44
+ - `src/preview/webview/index.html` — CM6 DOM styles, hide cursor/selection, default white-space:pre-wrap
45
+ - `src/preview/preview-manager.ts` — Fix scrollSync message type
46
+ - `src/preview/webview/colamd-renderer.js` — Deleted (old Milkdown renderer copy)
47
+
48
+ ---
49
+
50
+ ## [0.2.0] - 2025-05-30
51
+
52
+ ### Added
53
+ - Added **right-click context menu** in the preview WebView: export HTML/PDF, switch theme (with submenu), import custom theme — all accessible directly within the preview panel
54
+ - Added **Academic Paper** custom theme (`.themes/academic-paper.css`) — follows GB/T 7713 Chinese academic paper typesetting standards: serif body, sans-serif headings, three-line table, pure black-on-white print layout
55
+ - Added **Trae Blue** custom theme (`.themes/trae-blue.css`) — Trae IDE documentation style: white background with Slate grayscale text, system sans-serif fonts, blue accent (#3b82f6)
56
+ - Added **read-only mode styling** for ProseMirror editor: hides cursor and disables selection highlights in preview mode
57
+
58
+ ### Changed
59
+ - **Restructured extension activation**: error-isolated initialization with independent try/catch blocks for ThemeManager, PreviewManager, and command registration — a failure in one component no longer blocks the others
60
+ - **Refactored PreviewManager**: split monolithic `setupEventListeners()` into dedicated methods: `registerActiveEditorListener()`, `registerScrollSyncListeners()`, `registerConfigurationListener()`
61
+ - **Runtime plugin toggle sync**: `colaview.plugins.math` and `colaview.plugins.mermaid` setting changes are now automatically synced to the preview WebView via `onDidChangeConfiguration`, no reload required
62
+ - Improved scroll sync error resilience: errors in scroll sync handlers are now silently ignored to prevent cascading failures
63
+
64
+ ### Removed
65
+ - Removed obsolete `debug-load.js` development helper
66
+ - Removed unused `src/config/configuration.ts` module
67
+ - Removed unused `src/utils/file-utils.ts` module
68
+ - Cleaned up unused scroll sync message fields (`scrollTop`, `scrollHeight`, `clientHeight`, `scrollPercent`) from shared types
69
+
70
+ ### Fixed
71
+ - Fixed h4 heading color inconsistency in exports
72
+ - Fixed code block border color mismatch after theme changes
73
+ - Fixed print margin width issue (reduced from 60px to 28px)
74
+
75
+ ## [0.1.3] - 2025-05-29
76
+
77
+ ### Added
78
+ - Added **experimental** scroll sync feature between editor and preview panel
79
+ - Added `colaview.scrollSync` configuration option (**experimental**) to enable/disable scroll synchronization
80
+ - Implemented bidirectional scroll tracking: editor cursor position syncs to preview and vice versa
81
+ - Added `topRatio` calculation for precise scroll positioning based on visible editor area
82
+
83
+ ### Improved
84
+ - Enhanced error handling in extension activation and preview manager initialization
85
+ - Enhanced scroll sync algorithm using relative position mapping instead of simple percentage
86
+ - Added debouncing to scroll events to prevent performance issues
87
+ - Added circular reference prevention to avoid infinite scroll loops
88
+ - Optimized scroll position calculation to handle content wrapping and screen width variations
89
+
90
+ ### Fixed
91
+ - Fixed list indentation and symbol alignment issues in HTML/PDF exports
92
+
93
+ ## [0.1.2] - 2025-05-28
94
+
95
+ ### Fixed
96
+ - Fixed blockquote background color being overwritten by page background in dark/light/newsprint themes
97
+
98
+ ## [0.1.1] - 2025-05-27
99
+
100
+ ### Added
101
+ - Initial release with Markdown preview and PDF/HTML export support
102
+ - 4 built-in themes: Light, Dark, Elegant, Newsprint
103
+ - Custom theme support via `.themes/` directory
104
+ - KaTeX math formula rendering
105
+ - Mermaid diagram rendering (17+ chart types)
106
+ - Plugin toggle for math/mermaid via settings
107
+
108
+ ### Changed
109
+ - Switched from local ColaMD project reference to npm package `@bytechain.cn/colamd` (^1.5.2)
110
+ - Unified `--code-color` and `--code-block-text` CSS variables across all 4 built-in themes
111
+ - Aligned Newsprint theme with ColaMD-extend base.css (PT Serif font stack, code color inheritance)
112
+ - Added missing `--table-border` variable to Light theme
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 bytechain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,265 @@
1
- # Temporary Holding Version
1
+ # ColaView MD
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![VS Code](https://img.shields.io/badge/VS_Code-1.85%2B-007ACC?logo=visual-studio-code)](https://code.visualstudio.com/)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-3178C6?logo=typescript)](https://www.typescriptlang.org/)
5
+ [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
6
+ [![Version](https://img.shields.io/badge/Version-0.3.0-orange)](package.json)
7
+
8
+ Rich Markdown preview & PDF/HTML/Word export for VS Code — powered by [ColaMD](https://github.com/byteuser1977/ColaMD-extend) rendering engine (CodeMirror 6 based).
9
+
10
+ ## Features
11
+
12
+ - **WYSIWYG Preview** — CodeMirror 6 powered read-only editor renders Markdown as rich text in real-time, with source buffer as the single source of truth
13
+ - **Math Formulas** — KaTeX integration for inline `$...$` and display `$$...$$` expressions (fonts inlined via base64)
14
+ - **Mermaid Diagrams** — 17+ chart types: flowcharts, sequence, class, state, ER, Gantt, mind maps, etc.
15
+ - **PDF Export** — Puppeteer headless Chrome renders A4 PDF with full theme styling
16
+ - **HTML Export** — Standalone `.html` with embedded CSS and fonts, zero-dependency sharing
17
+ - **Word Export** — High-fidelity `.docx` with headings, lists, tables, images, code blocks, footnotes, and rasterized KaTeX/Mermaid
18
+ - **Theme-Faithful Export** — PDF/HTML/Word exports inherit the current preview theme's fonts, accent colors, table styling and blockquote padding
19
+ - **12 Built-in Themes** — Light, Dark, Elegant, Sepia, Notion, Bear, Writer, Solarized Dark, Nord, Gruvbox, Dracula, Midnight
20
+ - **Custom Theme Directory** — Drop `.css` files into `.themes/` folder in your workspace root; they appear automatically in the theme menu
21
+ - **Right-click Context Menu** — Export HTML/PDF, switch theme (with submenu), import custom theme — all from within the preview panel
22
+ - **Live Sync** — 150ms debounced update while editing, experimental scroll sync between editor and preview
23
+ - **Source Buffer Fidelity** — Raw Markdown bytes are preserved exactly; export uses the buffer content directly, no serialization loss
24
+
25
+ ## Quick Start
26
+
27
+ 1. Install the extension
28
+ 2. Open a `.md` file in VS Code
29
+ 3. `Ctrl+Shift+P` → **"ColaView MD: Show Preview"**
30
+ 4. Preview opens in a side panel with rich rendering
31
+
32
+ ## Commands & Usage
33
+
34
+ ### Command Palette (`Ctrl+Shift+P`)
35
+
36
+ | Command | Description |
37
+ |---------|-------------|
38
+ | `ColaView MD: Show Preview` | Open or focus the preview panel |
39
+ | `ColaView MD: Export to PDF...` | Export current file as A4 PDF |
40
+ | `ColaView MD: Export to HTML...` | Export as standalone HTML |
41
+ | `ColaView MD: Export to Word...` | Export current file as `.docx` Word document |
42
+ | `ColaView MD: Switch Preview Theme...` | Choose from 12 built-in + custom themes |
43
+ | `ColaView MD: Import Custom Theme...` | Load a `.css` file as custom theme |
44
+
45
+ ### Right-click Context Menu (in Preview)
46
+
47
+ When the preview is open, right-click anywhere to access:
48
+
49
+ | Menu Item | Description |
50
+ |-----------|-------------|
51
+ | **Export HTML** | Export current preview as standalone HTML |
52
+ | **Export PDF** | Export current preview as A4 PDF |
53
+ | **Export Word** | Export current preview as `.docx` Word document |
54
+ | **Theme ▸** | Submenu listing all built-in + custom themes (✓ marks active) |
55
+ | **Import Theme...** | Open file picker to import a `.css` file |
56
+
57
+ ## Themes
58
+
59
+ ### Built-in Themes
60
+
61
+ | Theme | Style | Best For |
62
+ |-------|-------|----------|
63
+ | **Light** | Clean white, blue accents | General use, documentation |
64
+ | **Dark** | GitHub Dark palette | Night coding |
65
+ | **Elegant** | Warm serif, beige tones | Academic papers, long-form |
66
+ | **Sepia** | Warm sepia, paper texture | Extended reading, low-eye-strain |
67
+ | **Notion** | Not.so MCP | Notion-like clean minimalism |
68
+ | **Bear** | Bear.app style | Note-taking, casual writing |
69
+ | **Writer** | Monospace-friendly | Technical writing, code-heavy docs |
70
+ | **Solarized Dark** | Ethan Schoonover palette | Low-contrast dark coding |
71
+ | **Nord** | Arctic blue palette | Calm, focused writing |
72
+ | **Gruvbox** | Retro 80s terminal | Nostalgia, high-contrast |
73
+ | **Dracula** | Zeno Rocha palette | Vibrant dark theme |
74
+ | **Midnight** | Deep navy, gold accents | Night writing, premium feel |
75
+
76
+ ### Custom Themes
77
+
78
+ Place `.css` files in the `.themes/` directory at your workspace root. Two custom themes are bundled with the extension:
79
+
80
+ | Theme | Style | Best For |
81
+ |-------|-------|----------|
82
+ | **Academic Paper** | GB/T 7713 standard, serif body, three-line tables, black-on-white | Academic papers, formal documents, printing |
83
+ | **Trae Blue** | Trae IDE documentation style, white + Slate gray, blue accents | Technical docs, modern documentation |
84
+
85
+ ```
86
+ my-project/
87
+ ├── .themes/
88
+ │ ├── my-dark.css # appears as "My-dark" in theme menu
89
+ │ └── corporate.css # appears as "Corporate" in theme menu
90
+ └── README.md
91
+ ```
92
+
93
+ Custom themes are automatically detected and appear alongside built-in themes in both the command palette and right-click context menu.
94
+
95
+ Switch via command palette or settings:
96
+
97
+ ```json
98
+ { "colaview.theme": "nord" }
99
+ ```
100
+
101
+ Import custom CSS: `Ctrl+Shift+P` → "ColaView MD: Import Custom Theme..." or via right-click menu → "Import Theme..."
102
+
103
+ ## Configuration
104
+
105
+ | Setting | Type | Default | Description |
106
+ |---------|------|---------|-------------|
107
+ | `colaview.theme` | `string` | `"elegant"` | Preview theme: `light`, `dark`, `elegant`, `sepia`, `notion`, `bear`, `writer`, `solarized-dark`, `nord`, `gruvbox`, `dracula`, `midnight`, or any custom theme name |
108
+ | `colaview.plugins.math` | `boolean` | `true` | *(Deprecated, always-on since v0.3.0)* KaTeX is built into the ColaMD engine and cannot be disabled |
109
+ | `colaview.plugins.mermaid` | `boolean` | `true` | *(Deprecated, always-on since v0.3.0)* Mermaid is built into the ColaMD engine and cannot be disabled |
110
+ | `colaview.pdfMethod` | `string` | `"puppeteer"` | PDF engine: `puppeteer` or `webviewPrint` |
111
+ | `colaview.autoPreview` | `boolean` | `false` | Auto-open preview for `.md` files |
112
+ | `colaview.customThemesPath` | `string` | `""` | Directory for custom theme CSS files |
113
+ | `colaview.scrollSync` | `boolean` | `false` | **Experimental** — Enable scroll sync between editor and preview |
114
+
115
+ > **Note on plugin settings:** Since v0.3.0, math and mermaid rendering are integral parts of the CodeMirror 6 based ColaMD engine and are always enabled. The `colaview.plugins.math` and `colaview.plugins.mermaid` settings are retained for backward compatibility but no longer have any effect.
116
+
117
+ ## Supported Syntax
118
+
119
+ **Standard Markdown** — Headings, bold, italic, strikethrough, code blocks, links, images, lists, blockquotes
120
+
121
+ **GFM Extensions** — Tables, task lists, footnotes, autolinks
122
+
123
+ **Math (KaTeX)**
124
+
125
+ ```markdown
126
+ Inline: $E = mc^2$
127
+
128
+ Display:
129
+ $$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$
130
+ ```
131
+
132
+ **Diagrams (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
+ Supports: flowchart, sequence, class, state, ER, journey, pie, Gantt, gitGraph, mindmap, timeline, quadrant, XY, C4, Sankey, block, architecture
144
+
145
+ ## Architecture
146
+
147
+ ```
148
+ ┌─────────────┐ postMessage ┌──────────────────┐
149
+ │ Extension │ ◄──────────────────► │ WebView │
150
+ │ (Node.js) │ │ (CodeMirror 6/ │
151
+ │ │ raw markdown ──► │ ColaMD renderer)│
152
+ │ ThemeManager│ theme/css ──► │ │
153
+ │ Exporters │ ◄── complete HTML │ Read-only rich │
154
+ │ │ │ preview + Menu │
155
+ └─────────────┘ └──────────────────┘
156
+ ```
157
+
158
+ **Key design:** The extension sends raw Markdown to the WebView, where ColaMD (CodeMirror 6 based) renders it as a read-only rich preview. The source buffer is the single source of truth — no serialization loss on export. For exports, the WebView asynchronously builds a complete standalone HTML (including KaTeX fonts, Mermaid SVGs, and theme CSS) and returns it to the extension.
159
+
160
+ ### Security Model
161
+
162
+ The WebView uses a strict Content-Security-Policy (CSP):
163
+
164
+ 1. `style-src 'unsafe-inline'` is required for CodeMirror 6's dynamic styling and KaTeX's inline fonts
165
+ 2. `script-src 'unsafe-inline'` is required for esbuild's IIFE bundle format
166
+ 3. All resource URIs are resolved through `webview.asWebviewUri()` for sandbox isolation
167
+ 4. This prevents XSS injection even if markdown content contains malicious scripts
168
+
169
+ ### Project Structure
170
+
171
+ ```
172
+ src/
173
+ ├── extension.ts # Entry point (activate/deactivate), error isolation
174
+ ├── commands/commands.ts # Command registration (showPreview, exportHTML, exportPDF, etc.)
175
+ ├── preview/
176
+ │ ├── preview-manager.ts # WebView lifecycle, message handling, debounce sync
177
+ │ └── webview/
178
+ │ ├── index.html # WebView template + context menu styles
179
+ │ └── app.ts # ColaMD (CM6) init + context menu + scroll sync
180
+ ├── export/
181
+ │ ├── pdf-exporter.ts # Puppeteer PDF generation (A4, print background)
182
+ │ ├── html-exporter.ts # Standalone HTML export (embedded CSS)
183
+ │ ├── docx-exporter.ts # Word (.docx) export via docx + remark-parse/remark-gfm
184
+ │ ├── render-export-images.ts # KaTeX/Mermaid → PNG (headless Chrome) for Word export
185
+ │ └── theme-style.ts # Theme CSS → semantic HTML style converter for exports
186
+ ├── themes/
187
+ │ ├── theme-manager.ts # Theme loading, switching, .themes/ directory scanning, import
188
+ │ ├── foundation.css # Base CSS variables (colors, spacing)
189
+ │ └── built-in/ # 12 built-in themes (light.css, dark.css, elegant.css, sepia.css, ...)
190
+ └── types/
191
+ └── colamd-renderer.d.ts # Local type declarations for ColaMD 2.7.9 npm package
192
+ ```
193
+
194
+ ## Development
195
+
196
+ ```bash
197
+ git clone https://github.com/bytechain/vscode-colaview.git
198
+ cd vscode-colaview
199
+ npm install
200
+
201
+ # Build (esbuild bundles all deps into out/)
202
+ npm run build
203
+
204
+ # Watch mode
205
+ npm run watch
206
+
207
+ # Package .vsix
208
+ npm run package
209
+
210
+ # Debug: press F5 in VS Code to launch Extension Development Host
211
+ ```
212
+
213
+ ### Build System
214
+
215
+ The project uses **esbuild** for bundling — the extension side (`out/extension.js`) is a small CJS bundle with only VS Code API imports. The WebView side (`out/preview/webview/app.js`) is an IIFE bundle containing the full ColaMD 2.7.9 rendering engine (CodeMirror 6 + Mermaid + KaTeX) — approximately 3.4MB unminified, gzip ~400KB. Resource files (CSS, WebView HTML, KaTeX stylesheet, Mermaid script) are copied to `out/` during build so they survive `.vscodeignore` packaging.
216
+
217
+ ## Changelog
218
+
219
+ ### v0.3.0 (Current)
220
+
221
+ - **📝 Word Export (`.docx`)** — Ported from ColaMD-extend. High-fidelity Word export with headings, paragraphs, inline styles, code blocks, lists, tables, blockquotes, horizontal rules, images, footnotes, and rasterized KaTeX/Mermaid diagrams.
222
+ - **🎨 Theme-Faithful Export** — New `theme-style.ts` conversion layer maps editor-only theme selectors (`#editor .cm-content .cm-md-*`) to semantic HTML selectors, so PDF/HTML/Word exports inherit the current preview theme's fonts, accent colors, table header styling and blockquote padding.
223
+ - **🐛 PDF Blank Export Fixed** — Stripped ColaMD's Electron `@media print` rule that hid the exported `<article>` element, so PDF (and HTML) export no longer renders blank.
224
+ - **🐛 HTML Export Theme Fix** — Fixed exported HTML not applying preview theme styles due to the editor-only selector mismatch.
225
+ - **📦 New Dependencies** — `docx`, `katex`, `remark-parse`, `remark-gfm`, `unified`.
226
+ - **🔧 Engine Upgrade — ColaMD 2.7.9 (CodeMirror 6)** — Migrated from Milkdown/ProseMirror to CodeMirror 6. Source buffer is now the single source of truth with zero serialization loss on export.
227
+ - **🎨 12 Built-in Themes** — Expanded from 4 to 12 themes: Light, Dark, Elegant, Sepia, Notion, Bear, Writer, Solarized Dark, Nord, Gruvbox, Dracula, Midnight. Default theme changed to Elegant.
228
+ - **📤 Async HTML Export** — `buildExportHTML()` is now asynchronous, automatically waits for Mermaid diagrams and KaTeX fonts to render before producing the final HTML.
229
+ - **🗑️ Removed Plugin Toggle** — Math and Mermaid are now integral to the ColaMD engine; `colaview.plugins.math` and `colaview.plugins.mermaid` settings are no longer functional.
230
+ - **📰 Removed Newsprint Theme** — Newsprint is not available in ColaMD 2.7.9.
231
+ - **🔄 DOM Structure Changed** — The preview container uses `.cm-editor` / `.cm-scroller` / `.cm-content` instead of `.ProseMirror`. Scroll sync target updated to `.cm-scroller`.
232
+ - **📦 Dependency Bump** — `@bytechain.cn/colamd` upgraded from `^1.5.2` to `^2.7.9`. TypeScript type declarations added locally since 2.7.9 npm package does not publish `.d.ts` files.
233
+ - **🖼️ KaTeX Fonts Inlined** — KaTeX fonts are base64-encoded inside `colamd.css`, no additional resource paths needed for PDF export.
234
+
235
+ ### v0.2.0
236
+
237
+ - **🏗️ Architecture Overhaul** — Error-isolated activation, refactored PreviewManager, runtime plugin toggle sync for math/mermaid settings
238
+ - **🖱️ Right-Click Context Menu** — Export HTML/PDF, switch theme (with submenu), import custom theme — directly in the preview panel
239
+ - **🎨 New Custom Themes** — Academic Paper (GB/T 7713 standard) and Trae Blue (Trae IDE documentation style)
240
+ - **🧹 Cleanup** — Removed obsolete files (`debug-load.js`, `configuration.ts`, `file-utils.ts`)
241
+ - **🐛 Fixes** — h4 color consistency, code block border color, print margin width
242
+
243
+ ### v0.1.3
244
+
245
+ - **🔄 Experimental Scroll Sync** — Bidirectional scroll synchronization between editor and preview panel. Enable via `colaview.scrollSync` setting.
246
+ - Enhanced error handling in extension activation and preview manager initialization
247
+
248
+ ### v0.1.2
249
+
250
+ - **🐛 Blockquote Background Fix** — Fixed blockquote background color being overridden by page background in Dark, Light, and Newsprint themes
251
+
252
+ ### v0.1.1
253
+
254
+ - **🎨 Theme Consistency Fix** — Unified `--code-color` and `--code-block-text` CSS variables across all 4 built-in themes (Light, Dark, Elegant, Newsprint), eliminating inconsistent inline code / code block text colors
255
+ - **📰 Newsprint Theme Alignment** — Fully aligned Newsprint theme variables with [ColaMD-extend](https://github.com/byteuser1977/ColaMD-extend) base.css, including font family (PT Serif serif stack), code color inheritance, and all semantic color tokens
256
+ - **🔧 Light Theme Completion** — Added missing `--table-border` variable to Light theme for consistent table styling
257
+ - **📦 Dependency Migration** — Switched from local ColaMD project reference to npm package `@bytechain.cn/colamd` (^1.5.2)
258
+
259
+ ### v0.1.0
260
+
261
+ - Initial release with WYSIWYG preview, PDF/HTML export, 4 built-in themes, custom theme support
262
+
263
+ ## License
264
+
265
+ [MIT](LICENSE)