Overview of Cherry-Markdown Client
devcherry-markdown engine. It provides a user interface for interacting with markdown content using the Cherry Markdown rendering capabilities.repository·dev·Indexed 26 days ago
https://github.com/tencent/cherry-markdownA lightweight, extensible JavaScript-based Markdown editor for browser and Node.js environments. It features optimized streaming rendering for AI chat, a VSCode extension, and a specialized @cherry-markdown/miniprogram package for WeChat MiniPrograms. Key capabilities include multi-cursor editing, VIM mode, Mermaid diagrams, math formulas, and support for CommonMark and GFM.
cherry-markdown engine. It provides a user interface for interacting with markdown content using the Cherry Markdown rendering capabilities.Cherry Markdown Writer is a lightweight, extensible JavaScript Markdown editor that runs in the browser or on a server via Node.js.
If you want to use Cherry Markdown directly within Visual Studio Code, you can install the official extension from the VSCode Marketplace. This provides the same rich editing and preview experience as the web version.
https://marketplace.visualstudio.com/items?itemName=cherryMarkdownPublisher.cherry-markdownThe @cherry-markdown/miniprogram package exports the CherryStream class. It converts Markdown into structured, WXML-friendly data (blocks and runs) instead of updating a DOM.
Key behaviors:
setMarkdown(markdown, options): Accepts the full accumulated Markdown string. It re-renders the entire content to ensure unclosed syntax is handled correctly.{ deferImages: true } to render image placeholders. Once the stream is complete, call setMarkdown again with { deferImages: false } to render the actual images.setData updates (e.g., once every 50-100ms) rather than calling it for every chunk.CherryStream.import CherryStream from '@cherry-markdown/miniprogram';
const page = this;
const cherry = new CherryStream();
let markdownContent = '';
function render(streaming) {
page.setData({
blocks: cherry.setMarkdown(markdownContent, { deferImages: !streaming }),
streaming,
});
}
function finishStream() {
render(false);
}
// Business-side SSE client extracts Markdown string and calls this:
function onMarkdownChunk(chunk) {
markdownContent += chunk;
render(true);
}
function onStreamComplete() {
finishStream();
}Install the package via npm to use Cherry Markdown in your WeChat Mini Program. Note that this package provides ESM and requires your application source code to be built into a Mini Program runtime format (e.g., using Rollup) because Mini Programs cannot execute ESM directly.
npm install @cherry-markdown/miniprogramYou can download the latest releases of the Cherry-Markdown Client from the official GitHub releases page.
https://github.com/Tencent/cherry-markdown/releases?q=client&expanded=trueTo run the official WeChat MiniProgram demo:
examples/miniProgram.yarn --cwd examples/miniProgram build.examples/miniProgram folder in WeChat DevTools.Refer to the Demo README for more details on local-package and preview-tarball verification.
The @cherry-markdown/miniprogram package exposes CherryStream, which converts Markdown into structured, WXML-friendly view data.
setMarkdown(markdownContent, options) to pass the accumulated Markdown string.{ deferImages: true } to render image placeholders. When the stream completes, call setMarkdown once with { deferImages: false } to render actual images.setData calls (e.g., every 50-100 ms) instead of updating on every single chunk.import CherryStream from '@cherry-markdown/miniprogram';
const page = this;
const cherry = new CherryStream();
let markdownContent = '';
function render(streaming) {
page.setData({
blocks: cherry.setMarkdown(markdownContent, { deferImages: !streaming }),
streaming,
});
}
function finishStream() {
render(false);
}
// Your SSE client extracts Markdown strings from the transport.
function onMarkdownChunk(chunk) {
markdownContent += chunk;
render(true);
}
function onStreamComplete() {
finishStream();
}You can install the cherry-markdown package using either npm or yarn to integrate the editor into your project.
npm install cherry-markdown --saveyarn add cherry-markdownNote that Cherry provides multiple build artifacts (Full, Core, Stream, and Engine) to support different environments like browsers, Node.js, and AI Chat streaming scenarios. Refer to the Build Artifacts Guide for details on choosing the right bundle.
The gfmUnicode configuration object defines how GitHub Flavored Markdown (GFM) emoji shortcodes are mapped to Unicode codepoints and how their corresponding images are retrieved.
It contains:
defaultURL: A template string used to fetch emoji images. It uses the ${code} placeholder to inject the Unicode codepoint.emojis: A mapping of emoji shortcodes (e.g., +1, apple, angry) to their specific Unicode codepoints (e.g., 1f44d, 1f34e, 1f620).export const gfmUnicode = {
defaultURL: 'https://github.githubassets.com/images/icons/emoji/unicode/${code}.png?v8',
emojis: {
'+1': '1f44d',
'-1': '1f44e',
// ... other emoji mappings
}
};The editor object defines the user interface and interaction model of the editor.
defaultModel: Sets the initial view mode: 'edit&preview' (split), 'editOnly' (editor only), or 'previewOnly' (preview only).keyMap: Sets the keyboard shortcut style ('sublime' or 'vim').writingStyle: Sets the writing mode: 'normal', 'typewriter', or 'focus'.convertWhenPaste: If true, automatically converts pasted HTML to Markdown.suggester: Configures the autocomplete/suggestion system. You can:systemSuggestList.extendSystemSuggestList.@user, $variable) via the suggester array using keyword and suggestList functions.editor: {
defaultModel: 'edit&preview',
keyMap: 'sublime',
writingStyle: 'typewriter',
suggester: [
{
keyword: '@',
suggestList(word, callback) {
// Custom logic for @mentions
callback([{ label: 'User A', value: '@User A ', icon: 'user' }]);
}
}
]
}