How tencent/cherry-markdown works
Main Components
• Core Engine (packages/cherry-markdown): This is the heart of the editor and contains the syntax parser, renderer (Engine.js, Previewer.js), configuration (Cherry.config.js), hooks (for transforming markdown syntax), and libraries for sanitization and logging.
• UI Editor Layer: This layer uses the core engine to render an interactive markdown editor. It involves components like the toolbar, bubble toolbar, and previewer. In addition, there is a “client” package (packages/client) that implements the UI using frameworks like Vue (as per its App.vue and main.ts) or uses a Tauri integration for desktop apps.
• VSCode Plugin (packages/vscodePlugin): Presented as an integration module that leverages the core functionality of Cherry Markdown to provide an editing experience in VS Code. It has a distinct file set (extension.ts, webview.ts, etc.) and uses similar underlying libraries.
Relationships and Interactions
• The Client layer (browser UI and Tauri desktop application) and the VSCode extension are “consumers” of the core engine.
• The configuration files and build scripts (e.g., in packages/cherry-markdown/build, gulpfile.js, rollup configs) are used to compile and bundle the different parts of the system, so include a “Build & Deployment” module node that interacts with each package.
• The examples and tests demonstrate integration points and validate the overall system functionality.
Architectural Patterns and Design Principles
• Modular design – Each main feature (core engine, plugin system, UI components) is separated into its own module or package.
• Plugin architecture – The engine is designed to use dynamic imports and allow plugin registration prior to instantiation.
• Separation of concerns – Notice the division between markdown processing (syntax, sanitization, parsing) and the UI/editor components (toolbars, preview panels).
• Support for multiple modes – The system supports both browser-based and server-based rendering (Node.js engine mode) along with integrations for desktop (Tauri) and IDE (VSCode).
Technologies and Frameworks
• JavaScript/TypeScript – The core code is written in JavaScript with some modules indicating TypeScript usage.
• CSS/SCSS – There are style sheets for the editor theme, syntax highlighting, and UI customization.
• Build Tools – Tools like Rollup, gulp, and webpack (especially for the VSCode plugin) are used to bundle the modules.
• Tauri – In the client package’s “src-tauri” directory, indicating desktop application support.
Detailing Essential Architectural Elements
• To show how configuration and build scripts connect to both core engine and client packages.
• Test and example layers to indicate quality checks (e.g., Jest tests, CommonMark specifications).
• That the extension points are designed for easy modification (custom syntax, toolbar adjustments, etc.).