Skip to content

feat: support Mermaid Add-On widget (block_type=40) to preserve editable mermaid source code #1834

Description

@yifei-travel

Summary

When inserting mermaid diagrams into Lark documents via lark-cli, the current implementation converts mermaid source into a whiteboard block (block_type=43). This is a one-way conversion — the mermaid source code is parsed into editable nodes and the original source is lost. Users can no longer modify the diagram by editing mermaid code.

Lark documents natively support a "Text Drawing" widget (block_type=40, Add-On) that preserves the mermaid source code and supports three view modes: codeChart, chart, and code. This widget allows users to edit mermaid source directly in the document UI. lark-cli does not currently support creating, reading, or updating this block type.

Expected Behavior

lark-cli should support creating mermaid diagrams as Add-On widgets (block_type=40) so that:

  1. The mermaid source code is preserved and remains editable in the document
  2. Users can switch between code view and chart view
  3. The source can be updated programmatically via docs +update or whiteboard +update

Proposed XML Schema

Extend the existing <whiteboard> tag with a mode attribute, or introduce a new <widget> tag:

<!-- Option A: extend whiteboard -->
<whiteboard type="mermaid" mode="widget">
graph TD
    A[Start] --> B{Decision}
    B -- Yes --> C[Execute]
    B -- No --> D[End]
</whiteboard>

<!-- Option B: new widget tag -->
<widget type="mermaid" view="codeChart">
graph TD
    A[Start] --> B{Decision}
    B -- Yes --> C[Execute]
    B -- No --> D[End]
</widget>

Use Case

I maintain a set of architecture diagrams as .mmd files. I want to:

  1. Insert them into Lark documents via lark-cli
  2. Later update the mermaid source and push the changes back
  3. Have team members edit the mermaid source directly in the Lark doc UI

Currently, after insertion, the only way to update is to delete the whiteboard block and re-insert — losing any manual adjustments and breaking the edit-in-place workflow.

Implementation Notes

Suggested Rollout

  1. Short-term: Add a --preserve-mermaid-code flag that keeps mermaid as a code block (block_type=14, language="mermaid") instead of converting to whiteboard — source is preserved even without widget support
  2. Medium-term: Implement block_type=40 create/read/update for the Mermaid widget specifically
  3. Long-term: Extend to other widget subtypes (HTML, timeline, etc.) as the record format becomes documented

Environment

  • lark-cli version: 1.0.67
  • OS: macOS (Darwin arm64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions