Skip to content

Edit as Code

Edit as Code turns an existing diagram into Mermaid/D2 code and opens it in an editor with a live preview. The code comes pre-filled; when you make changes and apply them, the diagram is updated in place (a single undo step). This lets you do the “draw → convert to code → edit → apply back” round trip in a single step.

Edit as Code: source editor and live preview

More tools (⋯) → Edit as Code in the bottom toolbar. If there is no shape on the canvas, this item appears disabled.

  1. If you like, first select the shapes you want to edit. If the selection contains diagram nodes, only that part is used; if not, the whole canvas is used.
  2. Open More tools → Edit as Code. The code opens pre-filled in a line-numbered editor; a live preview appears on the right.
  3. Change the code (add a box, fix a label, change an arrow direction).
  4. Press Update; the changes are applied over the same shapes.

If the selection is a part that structural extraction cannot fully represent (e.g. a few classes pulled from a class diagram), you can regenerate the source from an AI image reading with the Read from image button above the editor. This path uses a provider/quota.

  • The source language follows a previous import: if the part came from D2 it opens as D2, otherwise as Mermaid.
  • If you want to produce only code (without applying in place), use Diagram to Code.