Skip to content

Draw Mermaid diagrams as pictures in generated Word, PDF and PowerPoint files - #1989

Merged
Paul Lizer (paullizer) merged 3 commits into
microsoft:Developmentfrom
paullizer:claude/diagram-png-rendering-issue-bba501
Nov 30, 2026
Merged

Paul Lizer (paullizer) merged 3 commits into
microsoft:Developmentfrom
paullizer:claude/diagram-png-rendering-issue-bba501

Conversation

@paullizer

@paullizer Paul Lizer (paullizer) commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When the assistant creates a Word document, PDF, or PowerPoint deck that includes a flowchart or another Mermaid diagram, the file shows the diagram's raw Mermaid code instead of a picture. This was reported from the V2 interface. Exporting an existing chat message was not affected, because that path already draws diagrams.

Cause

Generated files are rendered by functions_office_file_renderers.py from prepared content, and nothing on that path turned a diagram into a picture:

  • Word and PDF: markdown2 turned each ```mermaid fence into an ordinary code block.
  • PowerPoint: the prepared slide deck schema had no diagram shape, so the composing model could only put the code in a text box.

Fix

Diagrams are drawn with the server's existing Chromium renderer (functions_mermaid_server_render.py, the same one the message export uses).

  • Word and PDF: PreparedReport has a new diagrams map (normalized source to PNG). Each top-level fence that has a picture becomes the same export-inline-diagram figure the message export uses, with the diagram's title as a caption. The report's text is unchanged, so the character-count completeness check still holds. Diagrams count toward the image limits and use at most half the pixel budget; a diagram over the budget stays code instead of failing the file.
  • PowerPoint: a new diagram slide shape (box, source, alt). At render time it becomes a picture fitted to its box. Validation before the deck is saved checks structure and geometry only, without starting Chromium.
  • A diagram that cannot be drawn (Chromium off, or Mermaid that doesn't parse) keeps its code, and the file is still produced.

Version 0.261.498. Fix doc: docs/explanation/fixes/GENERATED_OFFICE_FILE_DIAGRAM_PNG_FIX.md.

Testing

  • New functional_tests/test_office_diagram_png_rendering.py: 13 tests, all passing. They use synthetic PNGs, so they don't need a browser.
  • Existing test files for the touched modules all pass: test_generated_file_office_bridge, test_office_file_renderers, test_document_transform_rendering, test_pptx_render_file_mitigation, test_orchestration_services, test_orchestration_deliverables, test_orchestration_compose_output_retry, test_orchestration_dependency_runtime, test_orchestration_export_integration, test_orchestration_tabular_reconciliation, test_orchestration_v2_plan_backend, and test_workflow_merge_task.
  • Checked by hand with real Chromium: a Word file and a PDF embedded a titled flowchart and a sequence diagram as PNGs with their labels drawn, and a slide deck's flowchart became a picture.
  • The full suite was not run locally; CI runs it.

Not covered

  • The older non-orchestrated path that writes a DOCX straight from a chat reply (_render_docx_file_export) writes plain paragraphs without converting Markdown, so it is unchanged.
  • A code fence indented inside a list item already makes a generated Word or PDF report fail, before and after this change.

🤖 Generated with Claude Code

…nt files

Files the assistant generates showed each Mermaid diagram as its raw code.
Word and PDF reports now swap each top-level mermaid fence for a PNG drawn by
the server's Chromium renderer, with its title as a caption. Slide decks gain a
diagram shape that becomes a picture fitted to its box. A diagram that cannot
be drawn keeps its code and the file is still produced.

Version 0.261.497.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…into claude/diagram-png-rendering-issue-bba501

# Conflicts:
#	application/single_app/config.py
@paullizer
Paul Lizer (paullizer) merged commit fa14902 into microsoft:Development Nov 30, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant