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,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,4 @@
1
+ {
2
+ "colaview.autoPreview": false,
3
+ "colaview.theme": "elegant"
4
+ }
@@ -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,141 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.3.2] - 2026-11-07
6
+
7
+ ### Fixed
8
+ - Fixed **PDF/HTML export failing with `md is not defined`** β€” the export CSS injected by `patchExportHTML` lives in a JS template literal, and a CSS comment inside it contained unescaped backticks (`` `.cm-md-mermaid` ``). The first backtick closed the template literal early, so the rest of the comment was parsed as JavaScript (`…template.cm - md - mermaid…`), throwing `ReferenceError: md is not defined` at export time β€” surfacing to the user as "PDF export failed: md is not defined". The backticks are now escaped, so the comment stays a comment. (Only the packaged/minified build hit it in a confusing way; `tsc` flags it as `Cannot find name 'md'`.)
9
+ - Fixed **Mermaid diagrams left-aligned in PDF/HTML exports** β€” the engine serializes mermaid blocks as class-stripped `<p><svg class="pele pele-…">…</svg></p>`, so the previous export rule (`div:has(> svg.pele)`) never matched and its `text-align: center` never applied: diagrams were centered in the preview but flush-left on paper. Centering now lives on `svg.pele` itself (`display: block; margin: 0 auto`), independent of the wrapper element.
10
+ - Fixed **Mermaid diagram background not matching ColaMD-extend** β€” diagram colors are derived from the theme's code-block background (`--code-block-bg`), and in ColaMD the diagram sits on that block background. ColaView preview and export rendered it on the plain page background instead. Both now paint the same block behind the diagram (code-block background, 6px radius, `0.8em 1em` padding), so Elegant/Bear (light themes with dark code blocks) match ColaMD's dark diagram block.
11
+ - Fixed **Mermaid diagram colors drifting from the preview in PDF/HTML exports for non-Elegant themes** β€” exports re-derived the `--pele-*` tokens on a wrapper selector that never matched the serialized `<p><svg class="pele">` markup, so diagrams fell back to pele's built-in light palette (dark nodes/edges on dark themes, light gray surfaces where the theme wanted the code-block tone). Exports now use the runtime `--pele-*` values that `buildExportHTML` collects from the preview's `.cm-md-mermaid` into `:root`; a token block using the engine's own derivation is injected only when those runtime values are absent (e.g. no rendered mermaid node at export time).
12
+ - Fixed **preview blocks vanishing after viewing their source** β€” the engine (ColaMD 2.7.11) rendered mermaid diagrams and multi-line block math as *inline* replace decorations spanning multiple lines; CodeMirror 6 only honors such decorations on the initial build, so after clicking into a diagram/formula (source revealed) and clicking away, the widget was never recreated and the whole block disappeared. Fixed with `block: true` for whole-line-covering replace decorations (mermaid always, block math when covering full lines). Patched via `patch-package` (`patches/`); the same fix is applied upstream in ColaMD-extend `live-preview.ts`.
13
+ - Fixed **Word export producing broken images** β€” puppeteer v25's `screenshot()` returns a `Uint8Array`; calling `.toString('base64')` on a TypedArray yields a comma-joined decimal byte string instead of base64, so every formula/diagram image embedded in the `.docx` was corrupt and exported as placeholder text. Screenshots are now converted with `Buffer.from()`.
14
+ - Fixed **Word-exported formulas rendering with wrong glyphs** β€” the formula screenshot page inlines `katex.min.css`, but its relative `url(fonts/*.woff2)` references can't resolve on a `page.setContent` (about:blank) page, so KaTeX fell back to system fonts. KaTeX fonts are now inlined as base64 data URIs at render time (and the font files are copied to `out/assets/katex-fonts/` by the build).
15
+
16
+ ### Changed
17
+ - **Export HTML/PDF now carries the engine's theme-scoped body rules** β€” the per-theme accent rules (`body.theme-x .cm-content .cm-md-strong`, inline code colors, heading colors, table header styling...) that live in the engine's `colamd.css` are extracted and translated to semantic selectors (`body.theme-x .colamd-document strong` ...) and injected into exports, so exported documents match the preview and ColaMD-extend rendering for all 12 built-in themes.
18
+ - `src/preview/webview/index.html` gives `.cm-md-mermaid` the code-block background in the preview; `src/preview/preview-manager.ts` applies the same block, plus the centering rule, to the serialized mermaid wrapper in HTML/PDF exports, and no longer redeclares `--pele-*` on the exported SVG.
19
+
20
+ ### Removed
21
+ - Ineffective settings removed from the extension manifest: `colaview.plugins.math` and `colaview.plugins.mermaid` (no-ops since v0.3.0 β€” math and Mermaid are built into the engine), `colaview.pdfMethod` and `colaview.customThemesPath` (never read by the extension). The dead `togglePlugin` message plumbing and the no-op `onDidChangeConfiguration` listeners they fed are gone too. Remaining settings: `colaview.theme`, `colaview.autoPreview`, `colaview.scrollSync`.
22
+
23
+ ## [0.3.1] - 2026-11-07
24
+
25
+ ### Changed
26
+ - **Engine upgrade: ColaMD 2.7.11** β€” `@bytechain.cn/colamd` bumped from 2.7.9 to 2.7.11, bringing upstream fixes: inline math rendered as formulas inside table cells, list indent handled purely by CSS (source spaces hidden), cursor misalignment with multi-digit ordered lists, block-level widget layout (no margin placeholders, diagram height re-measured after async render), and Enter/Backspace restored to official CodeMirror commands.
27
+
28
+ ### Fixed
29
+ - Fixed **Word-exported code blocks breaking on Windows** β€” ported ColaMD-extend #202 fixes: code font now written into all four `w:rFonts` slots with a platform-appropriate mono font (Menlo/Consolas/DejaVu Sans Mono) plus a dedicated CJK `eastAsia` font (so Chinese comments no longer garble); explicit left alignment prevents justify-stretched lines; code blocks get a light border and `noProof` (no spell-check squiggles on identifiers, inline code included).
30
+ - Fixed **Word-exported Mermaid diagrams not following the preview theme** β€” diagram colors are now derived from the current theme's tokens (surface/border mixes at 18%/28%/45%, same ratios as the editor), with dark themes falling back to the light palette. Previously hardcoded to mermaid's `neutral` theme.
31
+ - Fixed **inline formulas wrapping in Word export** β€” the measurement viewport was widened to 2000px so wider formulas are not line-wrapped by KaTeX before capture (mirrors ColaMD-extend `MEASURE_WIDTH`).
32
+ - Fixed **exported HTML/PDF diagrams losing theme colors and carrying zoom controls** β€” injected export CSS now matches serialized `<div><svg class="pele pele-…">` wrappers to restore the `--pele-*` variable mapping (mirrors ColaMD-extend a25b3f8), and hides the editor-only `.pele-zoom` controls that Chromium print cannot remove via scripts (mirrors `print-layout.ts`).
33
+
34
+ ## [0.3.0] - 2026-11-06
35
+
36
+ ### Added
37
+ - 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.
38
+ - 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`.
39
+ - Added `src/export/render-export-images.ts` β€” headless-Chrome (puppeteer-core) rasterizes KaTeX and Mermaid to PNG, rewriting the source Markdown to image placeholders.
40
+ - Added direct dependencies: `docx`, `katex`, `remark-parse`, `remark-gfm`, `unified`.
41
+ - 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
42
+ - 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
43
+ - 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.
44
+
45
+ ### Changed
46
+ - **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.
47
+ - **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.
48
+ - **12 built-in themes** total, up from 4. Default theme changed from `"light"` to `"elegant"`.
49
+ - **DOM structure changed** β€” Preview container uses `.cm-editor` / `.cm-scroller` / `.cm-content` (CM6) instead of `.ProseMirror`. Scroll sync target updated to `.cm-scroller`.
50
+ - **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.
51
+ - **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).
52
+
53
+ ### Removed
54
+ - **Removed Newsprint theme** β€” Not available in ColaMD 2.7.9. Users who had `colaview.theme: "newsprint"` will fall back to the default ("elegant").
55
+ - **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.
56
+ - **Removed local `colamd-renderer.js` copy** β€” The WebView now imports ColaMD directly from the npm package via esbuild bundling.
57
+
58
+ ### Fixed
59
+ - 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.
60
+ - 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.
61
+ - Fixed scroll sync listening to wrong DOM node β€” CM6 uses `.cm-scroller` for scrolling instead of the container `#editor` element
62
+
63
+ ### Files Changed
64
+ - `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`
65
+ - `src/export/docx-exporter.ts` β€” New Word export converter
66
+ - `src/export/render-export-images.ts` β€” New KaTeX/Mermaid β†’ PNG renderer for Word export
67
+ - `src/export/theme-style.ts` β€” New theme CSS β†’ semantic HTML style converter for exports
68
+ - `src/preview/preview-manager.ts` β€” Strip Electron print rule from inlined CSS, add Word export message handler
69
+ - `src/types/colamd-renderer.d.ts` β€” New local type declarations
70
+ - `src/themes/theme-manager.ts` β€” Expand `BUILTIN_THEMES` to 12, update `THEME_CLASS_MAP`
71
+ - `src/themes/built-in/*.css` β€” 9 new theme CSS files
72
+ - `src/preview/webview/app.ts` β€” Complete rewrite for CM6 API
73
+ - `src/preview/webview/index.html` β€” CM6 DOM styles, hide cursor/selection, default white-space:pre-wrap
74
+ - `src/preview/preview-manager.ts` β€” Fix scrollSync message type
75
+ - `src/preview/webview/colamd-renderer.js` β€” Deleted (old Milkdown renderer copy)
76
+
77
+ ---
78
+
79
+ ## [0.2.0] - 2025-05-30
80
+
81
+ ### Added
82
+ - 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
83
+ - 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
84
+ - 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)
85
+ - Added **read-only mode styling** for ProseMirror editor: hides cursor and disables selection highlights in preview mode
86
+
87
+ ### Changed
88
+ - **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
89
+ - **Refactored PreviewManager**: split monolithic `setupEventListeners()` into dedicated methods: `registerActiveEditorListener()`, `registerScrollSyncListeners()`, `registerConfigurationListener()`
90
+ - **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
91
+ - Improved scroll sync error resilience: errors in scroll sync handlers are now silently ignored to prevent cascading failures
92
+
93
+ ### Removed
94
+ - Removed obsolete `debug-load.js` development helper
95
+ - Removed unused `src/config/configuration.ts` module
96
+ - Removed unused `src/utils/file-utils.ts` module
97
+ - Cleaned up unused scroll sync message fields (`scrollTop`, `scrollHeight`, `clientHeight`, `scrollPercent`) from shared types
98
+
99
+ ### Fixed
100
+ - Fixed h4 heading color inconsistency in exports
101
+ - Fixed code block border color mismatch after theme changes
102
+ - Fixed print margin width issue (reduced from 60px to 28px)
103
+
104
+ ## [0.1.3] - 2025-05-29
105
+
106
+ ### Added
107
+ - Added **experimental** scroll sync feature between editor and preview panel
108
+ - Added `colaview.scrollSync` configuration option (**experimental**) to enable/disable scroll synchronization
109
+ - Implemented bidirectional scroll tracking: editor cursor position syncs to preview and vice versa
110
+ - Added `topRatio` calculation for precise scroll positioning based on visible editor area
111
+
112
+ ### Improved
113
+ - Enhanced error handling in extension activation and preview manager initialization
114
+ - Enhanced scroll sync algorithm using relative position mapping instead of simple percentage
115
+ - Added debouncing to scroll events to prevent performance issues
116
+ - Added circular reference prevention to avoid infinite scroll loops
117
+ - Optimized scroll position calculation to handle content wrapping and screen width variations
118
+
119
+ ### Fixed
120
+ - Fixed list indentation and symbol alignment issues in HTML/PDF exports
121
+
122
+ ## [0.1.2] - 2025-05-28
123
+
124
+ ### Fixed
125
+ - Fixed blockquote background color being overwritten by page background in dark/light/newsprint themes
126
+
127
+ ## [0.1.1] - 2025-05-27
128
+
129
+ ### Added
130
+ - Initial release with Markdown preview and PDF/HTML export support
131
+ - 4 built-in themes: Light, Dark, Elegant, Newsprint
132
+ - Custom theme support via `.themes/` directory
133
+ - KaTeX math formula rendering
134
+ - Mermaid diagram rendering (17+ chart types)
135
+ - Plugin toggle for math/mermaid via settings
136
+
137
+ ### Changed
138
+ - Switched from local ColaMD project reference to npm package `@bytechain.cn/colamd` (^1.5.2)
139
+ - Unified `--code-color` and `--code-block-text` CSS variables across all 4 built-in themes
140
+ - Aligned Newsprint theme with ColaMD-extend base.css (PT Serif font stack, code color inheritance)
141
+ - 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,279 @@
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.2-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.autoPreview` | `boolean` | `false` | Auto-open preview for `.md` files |
109
+ | `colaview.scrollSync` | `boolean` | `false` | **Experimental** β€” Enable scroll sync between editor and preview |
110
+
111
+ ## Supported Syntax
112
+
113
+ **Standard Markdown** β€” Headings, bold, italic, strikethrough, code blocks, links, images, lists, blockquotes
114
+
115
+ **GFM Extensions** β€” Tables, task lists, footnotes, autolinks
116
+
117
+ **Math (KaTeX)**
118
+
119
+ ```markdown
120
+ Inline: $E = mc^2$
121
+
122
+ Display:
123
+ $$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$
124
+ ```
125
+
126
+ **Diagrams (Mermaid)**
127
+
128
+ ````markdown
129
+ ```mermaid
130
+ graph LR
131
+ A[Markdown] --> B[ColaView]
132
+ B --> C[PDF]
133
+ B --> D[HTML]
134
+ ```
135
+ ````
136
+
137
+ Supports: flowchart, sequence, class, state, ER, journey, pie, Gantt, gitGraph, mindmap, timeline, quadrant, XY, C4, Sankey, block, architecture
138
+
139
+ ## Architecture
140
+
141
+ ```
142
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” postMessage β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
143
+ β”‚ Extension β”‚ ◄──────────────────► β”‚ WebView β”‚
144
+ β”‚ (Node.js) β”‚ β”‚ (CodeMirror 6/ β”‚
145
+ β”‚ β”‚ raw markdown ──► β”‚ ColaMD renderer)β”‚
146
+ β”‚ ThemeManagerβ”‚ theme/css ──► β”‚ β”‚
147
+ β”‚ Exporters β”‚ ◄── complete HTML β”‚ Read-only rich β”‚
148
+ β”‚ β”‚ β”‚ preview + Menu β”‚
149
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
150
+ ```
151
+
152
+ **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.
153
+
154
+ ### Security Model
155
+
156
+ The WebView uses a strict Content-Security-Policy (CSP):
157
+
158
+ 1. `style-src 'unsafe-inline'` is required for CodeMirror 6's dynamic styling and KaTeX's inline fonts
159
+ 2. `script-src 'unsafe-inline'` is required for esbuild's IIFE bundle format
160
+ 3. All resource URIs are resolved through `webview.asWebviewUri()` for sandbox isolation
161
+ 4. This prevents XSS injection even if markdown content contains malicious scripts
162
+
163
+ ### Project Structure
164
+
165
+ ```
166
+ src/
167
+ β”œβ”€β”€ extension.ts # Entry point (activate/deactivate), error isolation
168
+ β”œβ”€β”€ commands/commands.ts # Command registration (showPreview, exportHTML, exportPDF, etc.)
169
+ β”œβ”€β”€ preview/
170
+ β”‚ β”œβ”€β”€ preview-manager.ts # WebView lifecycle, message handling, debounce sync
171
+ β”‚ └── webview/
172
+ β”‚ β”œβ”€β”€ index.html # WebView template + context menu styles
173
+ β”‚ └── app.ts # ColaMD (CM6) init + context menu + scroll sync
174
+ β”œβ”€β”€ export/
175
+ β”‚ β”œβ”€β”€ pdf-exporter.ts # Puppeteer PDF generation (A4, print background)
176
+ β”‚ β”œβ”€β”€ html-exporter.ts # Standalone HTML export (embedded CSS)
177
+ β”‚ β”œβ”€β”€ docx-exporter.ts # Word (.docx) export via docx + remark-parse/remark-gfm
178
+ β”‚ β”œβ”€β”€ render-export-images.ts # KaTeX/Mermaid β†’ PNG (headless Chrome) for Word export
179
+ β”‚ └── theme-style.ts # Theme CSS β†’ semantic HTML style converter for exports
180
+ β”œβ”€β”€ themes/
181
+ β”‚ β”œβ”€β”€ theme-manager.ts # Theme loading, switching, .themes/ directory scanning, import
182
+ β”‚ β”œβ”€β”€ foundation.css # Base CSS variables (colors, spacing)
183
+ β”‚ └── built-in/ # 12 built-in themes (light.css, dark.css, elegant.css, sepia.css, ...)
184
+ └── types/
185
+ └── colamd-renderer.d.ts # Local type declarations for ColaMD 2.7.9 npm package
186
+ ```
187
+
188
+ ## Development
189
+
190
+ ```bash
191
+ git clone https://github.com/bytechain/vscode-colaview.git
192
+ cd vscode-colaview
193
+ npm install
194
+
195
+ # Build (esbuild bundles all deps into out/)
196
+ npm run build
197
+
198
+ # Watch mode
199
+ npm run watch
200
+
201
+ # Package .vsix
202
+ npm run package
203
+
204
+ # Debug: press F5 in VS Code to launch Extension Development Host
205
+ ```
206
+
207
+ ### Build System
208
+
209
+ 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.11 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.
210
+
211
+ ## Changelog
212
+
213
+ ### v0.3.2 (Current)
214
+
215
+ - **πŸ› PDF/HTML Export Fixed (`md is not defined`)** β€” exporting failed with "PDF export failed: md is not defined": a CSS comment inside the export stylesheet template literal contained unescaped backticks, which closed the literal early and made the parser treat part of the comment as JavaScript. Backticks are now escaped.
216
+ - **πŸ› PDF/HTML Mermaid Diagrams Centered** β€” the engine serializes mermaid blocks as class-stripped `<p><svg class="pele pele-…">…</svg></p>`, so the previous `div:has(> svg.pele)` export rule never matched and diagrams were left-aligned on paper. Centering now applies to `svg.pele` itself (`display: block; margin: 0 auto`), independent of the wrapper element.
217
+ - **🎨 Mermaid Diagram Background Matches ColaMD-extend** β€” diagrams are now drawn on the code-block background (`--code-block-bg`, 6px radius, `0.8em 1em` padding) in both the preview and HTML/PDF exports, matching ColaMD instead of floating on the plain page background (most visible with Elegant/Bear, whose dark code blocks sit on light pages).
218
+ - **🎨 Mermaid Colors Match the Preview in Every Theme** β€” non-Elegant themes exported diagrams with different node/edge/label colors because the export re-declared `--pele-*` on a `div:has(> svg.pele)` selector that never matched the serialized `<p><svg class="pele">` markup, leaving pele's built-in palette in effect. Exports now use the runtime values collected from the preview into `:root`, with the derived token block injected only when those values are absent.
219
+ - **🧹 Removed Ineffective Settings** β€” `colaview.plugins.math` / `colaview.plugins.mermaid` (no-ops since v0.3.0) and `colaview.pdfMethod` / `colaview.customThemesPath` (never read) are gone; remaining settings: `colaview.theme`, `colaview.autoPreview`, `colaview.scrollSync`.
220
+ - **πŸ› Preview Blocks No Longer Vanish After Source View** β€” Fixed an engine bug (multi-line inline replace decorations are ignored by CodeMirror 6 on incremental updates): clicking a mermaid diagram / multi-line block formula to view its source, then clicking away, no longer makes the whole block disappear. Patched via `patch-package`; fix also applied upstream in ColaMD-extend.
221
+ - **πŸ› Word Export Images Fixed** β€” puppeteer v25 screenshot returns `Uint8Array`; the previous base64 conversion produced corrupt data so formulas/diagrams appeared as placeholder text in the `.docx`. Now converted with `Buffer.from()`.
222
+ - **πŸ› Word Formula Glyphs Fixed** β€” KaTeX fonts are inlined as base64 into the screenshot page (the relative `fonts/*.woff2` URLs could not resolve), so formulas render with proper KaTeX fonts.
223
+ - **🎨 Exports Match Preview Colors** β€” The engine's theme-scoped body rules (bold/inline-code/heading accent colors per theme) are translated to semantic selectors and injected into HTML/PDF exports for all 12 themes.
224
+
225
+ ### v0.3.1
226
+
227
+ - **πŸ”§ Engine Upgrade β€” ColaMD 2.7.11** β€” Inline math in table cells, CSS-driven list indent, block widget layout fixes, official CM6 typing commands.
228
+ - **🎨 Word Mermaid Diagrams Follow Theme** β€” Diagram colors derived from the current preview theme's tokens (dark themes fall back to light), instead of mermaid's hardcoded `neutral`.
229
+ - **πŸ› Windows Word Code Blocks Fixed** β€” Platform mono font in all four `w:rFonts` slots + CJK `eastAsia` font, explicit left alignment, light border, `noProof` (port of ColaMD-extend #202).
230
+ - **πŸ› Inline Formulas No Longer Wrap** β€” Wider (2000px) measurement viewport before capture.
231
+ - **πŸ› HTML/PDF Diagrams Follow Theme + No Zoom Controls** β€” Export CSS matches serialized pele SVG wrappers to restore `--pele-*` variables; editor-only zoom controls hidden on paper.
232
+
233
+ ### v0.3.0
234
+
235
+ - **πŸ“ 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.
236
+ - **🎨 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.
237
+ - **πŸ› 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.
238
+ - **πŸ› HTML Export Theme Fix** β€” Fixed exported HTML not applying preview theme styles due to the editor-only selector mismatch.
239
+ - **πŸ“¦ New Dependencies** β€” `docx`, `katex`, `remark-parse`, `remark-gfm`, `unified`.
240
+ - **πŸ”§ 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.
241
+ - **🎨 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.
242
+ - **πŸ“€ Async HTML Export** β€” `buildExportHTML()` is now asynchronous, automatically waits for Mermaid diagrams and KaTeX fonts to render before producing the final HTML.
243
+ - **πŸ—‘οΈ 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.
244
+ - **πŸ“° Removed Newsprint Theme** β€” Newsprint is not available in ColaMD 2.7.9.
245
+ - **πŸ”„ DOM Structure Changed** β€” The preview container uses `.cm-editor` / `.cm-scroller` / `.cm-content` instead of `.ProseMirror`. Scroll sync target updated to `.cm-scroller`.
246
+ - **πŸ“¦ 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.
247
+ - **πŸ–ΌοΈ KaTeX Fonts Inlined** β€” KaTeX fonts are base64-encoded inside `colamd.css`, no additional resource paths needed for PDF export.
248
+
249
+ ### v0.2.0
250
+
251
+ - **πŸ—οΈ Architecture Overhaul** β€” Error-isolated activation, refactored PreviewManager, runtime plugin toggle sync for math/mermaid settings
252
+ - **πŸ–±οΈ Right-Click Context Menu** β€” Export HTML/PDF, switch theme (with submenu), import custom theme β€” directly in the preview panel
253
+ - **🎨 New Custom Themes** β€” Academic Paper (GB/T 7713 standard) and Trae Blue (Trae IDE documentation style)
254
+ - **🧹 Cleanup** β€” Removed obsolete files (`debug-load.js`, `configuration.ts`, `file-utils.ts`)
255
+ - **πŸ› Fixes** β€” h4 color consistency, code block border color, print margin width
256
+
257
+ ### v0.1.3
258
+
259
+ - **πŸ”„ Experimental Scroll Sync** β€” Bidirectional scroll synchronization between editor and preview panel. Enable via `colaview.scrollSync` setting.
260
+ - Enhanced error handling in extension activation and preview manager initialization
261
+
262
+ ### v0.1.2
263
+
264
+ - **πŸ› Blockquote Background Fix** β€” Fixed blockquote background color being overridden by page background in Dark, Light, and Newsprint themes
265
+
266
+ ### v0.1.1
267
+
268
+ - **🎨 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
269
+ - **πŸ“° 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
270
+ - **πŸ”§ Light Theme Completion** β€” Added missing `--table-border` variable to Light theme for consistent table styling
271
+ - **πŸ“¦ Dependency Migration** β€” Switched from local ColaMD project reference to npm package `@bytechain.cn/colamd` (^1.5.2)
272
+
273
+ ### v0.1.0
274
+
275
+ - Initial release with WYSIWYG preview, PDF/HTML export, 4 built-in themes, custom theme support
276
+
277
+ ## License
278
+
279
+ [MIT](LICENSE)