doocs-md WeChat Markdown Editor

repository·main·Indexed 11 days ago

https://github.com/doocs/md

A concise Markdown editor designed to transform standard Markdown into styled content optimized for WeChat Official Accounts. Version 2.1.0 supports KaTeX, Mermaid, custom themes, and AI assistance. The ecosystem includes a Cloudflare Workers-based API (@md/api) for incremental synchronization, a uTools plugin, and a VS Code extension for real-time WeChat-style rendering previews.

Tokens
55.5K
Snippets
193
Records
263
Agent score
94%

What's inside doocs-md

  1. Overview of WeChat Markdown Editor

    main
    doocs/md is a Markdown editor designed to automatically render Markdown documents into beautiful, WeChat-compatible rich text. It allows content creators to focus on writing using standard Markdown syntax while handling the complex layout and styling required for WeChat Official Accounts.
  2. Overview of WeChat Markdown Editor

    main

    WeChat Markdown Editor is a tool designed to instantly render standard Markdown into WeChat-ready articles. It eliminates the need for manual formatting in the WeChat Official Account editor by providing clean, well-styled output using standard Markdown syntax.

    Key features include:

    • Support for math formulas (KaTeX), Mermaid diagrams, PlantUML, and GFM alert blocks.
    • Ruby annotation extensions: [text]{ruby} and [text]^(ruby).
    • Customizable code highlight themes and CSS.
    • Local draft management with auto-save and cloud sync capabilities.
    • Extensive image hosting support (GitHub, S3, OSS, etc.).
    • AI assistant integration (OpenAI, DeepSeek, etc.).
  3. Use @md/core to render Markdown for WeChat Official Accounts

    main

    The @md/core package is a Markdown rendering engine designed to convert Markdown into HTML optimized for WeChat Official Accounts. It provides tools to initialize a renderer, convert Markdown to HTML, and apply specific themes via CSS injection.

    import { initRenderer, renderMarkdown } from '@md/core'
    import { postProcessHtml } from '@md/core/utils'
    
    const renderer = initRenderer({
      isMacCodeBlock: true,
      isShowLineNumber: true,
    })
    
    const html = postProcessHtml(renderMarkdown(renderer, markdown))
  4. Understand the doocs/md Monorepo structure

    main

    The project is organized as a monorepo containing several specialized packages and applications. Developers can identify the relevant package based on their target platform:

    • Web Application (@md/web): The Vue 3 main application, WXT-based browser extensions (Chrome/Firefox), and Cloudflare Workers deployment.
    • API Service (@md/api): Handles accounts, cloud sync, billing, upload proxies, sharing, and the Marketplace (built with Cloudflare Workers, Hono, and D1).
    • VS Code Extension (doocs-md): A VS Code extension built with webpack (Marketplace ID: doocs.doocs-md).
    • uTools Plugin (@md/utools): A uTools plugin wrapper using builds from @md/web.
    • Markdown Engine (@md/core): The core Markdown-to-HTML rendering engine.
    • Shared Utilities (@md/shared): Contains configurations, types, CodeMirror editor wrappers, and theme CSS.
    • CLI Tool (@doocs/md-cli): An npm-published CLI providing an Express-based static service.
    • MCP Server (@md/mcp-server): An MCP service providing tools like render_markdown.
  5. Import from @md/shared

    main

    The @md/shared package provides shared configurations, types, utilities, and CodeMirror editor encapsulation used across different applications in the ecosystem. You can import specific modules based on your needs:

    • @md/shared: Main entry point.
    • @md/shared/configs: Default configurations and option lists for themes, fonts, colors, etc.
    • @md/shared/constants: Constants used across the project.
    • @md/shared/types: Shared TypeScript type definitions.
    • @md/shared/utils: Utility functions such as fetch and tokenTools.
    • @md/shared/editor: CodeMirror 6 setup, formatting commands, and keyboard shortcuts.
  6. How cloud synchronization and settings work

    main

    Cloud synchronization in the Web application uses a Last Write Wins (LWW) merge strategy.

    • Settings Sync: Only keys defined in SYNC_SETTING_KEYS (found in apps/web/src/services/sync/settings.ts) are synchronized. This includes items like marketplace_installed_themes and marketplace_installed_components.
    • Metadata: Synchronization metadata is stored in sync_settings_meta.
    • Hot Updates: Remote settings can be applied without a page refresh via hydrateSyncedSettings (in services/sync/hydrate.ts), which writes directly to the local Store (including locale).
  7. How cloud synchronization works in the editor

    main

    After logging into your account, certain editor preferences are synchronized to the cloud to allow recovery on other devices.

    Synchronization Strategy: The system uses a Last Write Wins (LWW) policy. If the same setting is modified on two different devices, the version with the most recent update timestamp will be used. There is no merge dialog; the later save will overwrite the previous one.

  8. Apply themes to rendered HTML

    main

    To ensure the rendered HTML matches the desired visual style, you must inject CSS. This is done using either:

    • @md/core/theme's applyTheme method.
    • In Web environments, using useThemeStore.applyCurrentTheme() to inject CSS variables.
  9. Key Features of doocs/md

    main

    The editor provides several advanced features for content creation:

    • Syntax Support: Standard Markdown, KaTeX (mathematical formulas), Mermaid diagrams, PlantUML, and GFM alert blocks.
    • Ruby Annotations: Supports Ruby text with formats [text]{annotation} and [text]^(annotation).
    • Code Blocks: Multiple highlighting themes with customizable theme colors and CSS.
    • Content Management: Built-in local draft management with auto-save and cloud synchronization for editor preferences.
    • Image Hosting: Supports various image hosting services (see Image Hosting Services).
    • AI Integration: Integrated with mainstream AI models like DeepSeek, OpenAI, Tongyi Qianwen, Tencent Hunyuan, Volcengine Ark, and 302.AI to assist in writing.
  10. How to use Callouts and Environments

    main

    You can highlight key points or create academic environments using two syntaxes: > [!type] (Blockquote style) or ::: type ... ::: (Container style).

    Callout Types

    Common built-in types include:

    • [!NOTE]: Informational.
    • [!TIP]: Helpful advice.
    • [!IMPORTANT]: Critical information. You can add a custom title: > [!IMPORTANT] Custom Title.
    • [!WARNING]: Critical attention required.

    Academic Environments

    Supports specialized containers for academic writing:

    • ::: theorem [Title]
    • ::: definition
    • ::: proof
    • ::: lemma

    Unrecognized types will render as a titled box using the provided name.

    > [!TIP]
    > This is a tip.
    
    ::: theorem Pythagorean theorem
    $a^2 + b^2 = c^2$
    :::
  11. Advanced Markdown: LaTeX Math Formulas

    main

    The editor supports embedding LaTeX syntax for mathematical expressions.

    Inline Formulas

    Wrap the formula with single dollar signs $: $E = mc^2$. Alternatively, use the standard LaTeX format: \(x^2 + y^2 = z^2\).

    Block Formulas

    Wrap the formula with double dollar signs $$:

    $$ \begin{aligned} d_{i, j} &\leftarrow d_{i, j} + 1 \end{aligned} $$

    Alternatively, use the standard LaTeX format: \[ \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} \].

    Tip: In the preview area, you can click on LaTeX formulas to open a built-in formula editor for quick modifications.

    $E = mc^2$
    
    $$
    \chi^2 = \sum \frac{(O - E)^2}{E}
    $$
    
    \(x^2 + y^2 = z^2\)
    
    \[
    \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
    \]
  12. How incremental synchronization works

    main

    The @md/api uses an incremental synchronization model to keep articles and preferences in sync between the client and the cloud.

    Core Logic:

    • Strategy: Uses last-write-wins (LWW) based on the updateDatetime field.
    • Deletions: Uses "soft delete tombstones" to ensure deletions are propagated across clients.
    • Client Workflow: The frontend follows a "pull then push" pattern:
      1. Call GET /sync/pull?since=<timestamp> to fetch all changes since the last sync.
      2. Apply changes locally.
      3. Call POST /sync/push to upload local changes. The server returns the accepted records and a new cursor.

    Data Scope: Syncs include articles (and history) and a whitelist of preference settings. Crucially, it does not sync image hosting keys or AI keys.