$ show Tencent/cherry-markdown
This repository is the monorepo for Cherry Markdown, a rich, extensible WYSIWYG markdown editor library developed by Tencent. The core package (`packages/cherry-markdown`) provides a modular parsing engine with a plugin-based syntax hook system, a comprehensive toolbar, streaming rendering for AI chat, and support for diagrams (Mermaid, PlantUML, ECharts), math (KaTeX/MathJax), tables, and code blocks. The repository also includes a desktop client built with Tauri (Vue 3 + Pinia + Rust) that adds file management, local versioning, and native integrations; a VS Code extension; a WeChat Mini Program renderer; and various example applications. The architecture is well-structured with clear separation of concerns (engine, previewer, editor, toolbar, addons), extensive unit tests, and a consistent event-driven pattern. While the core library is JavaScript with JSDoc types, the client and plugins are TypeScript. Some technical drift exists due to vendored third-party assets (e.g., drawio library), a partially implemented Milkdown adapter, and a few deprecated code paths. Overall, this is a mature, actively maintained editor framework with high reusability in its hook system, utility classes, and composable patterns.
The LLM identified 6 files worth highlighting for reuse:
A generic, well-tested LRU cache implementation with capacity limits, manual eviction, and size tracking. It is used internally by the engine for caching rendered blocks but is fully self-contained and could be extracted into any JavaScript project needing a bounded cache.
Implements the classic Myers diff algorithm for computing the shortest edit script between two sequences. It is used for virtual DOM patching in the previewer and for local version diffs. The implementation is self-contained, handles both array and string inputs, and returns structured edit operations (insert/delete/update). Can be reused in any project needing diffing.
The central registry for all markdown syntax hooks. It manages internal hooks, custom syntax classes, and provides lifecycle methods (before/after insertion, force override). The pattern is extensible and decoupled: any hook implementing the rule/makeHtml interface can be registered. This architectural pattern is reusable for any plugin-based processing pipeline.
Base class for all toolbar buttons and menus. Provides icon creation (iconfont/SVG/image), selection handling via CodeMirror, shortcut key binding, submenu support, and a consistent fire() → onClick() execution loop. The abstraction is clean and could be extracted to build a custom toolbar for any editor or application.
A local versioning service using IndexedDB that stores document snapshots with bucket granularity (minute/hour/day) and lazy compaction. It provides CRUD operations for versions and tracks the latest content via max createdAt. This pattern is reusable for any application needing offline draft history or autosave.
A Vue 3 composable that manages a resizable side panel: persists width and active panel in localStorage, handles mouse drag for resizing, and exposes reactive state. It is self-contained, well-typed, and demonstrates a clean separation of UI state from rendering. Could be reused in any Vue application needing a collapsible/resizable sidebar.