pandoc-ext / diagram

Generate diagrams from embedded code; supports Mermaid, Dot/GraphViz, PlantUML, Asymptote, CeTZ, and TikZ.
MIT License
90 stars 11 forks source link

Mermaid diagrams mangled in docx/odt #27

Closed reagle closed 3 months ago

reagle commented 3 months ago
❯ cat test-diagram.md
---
title: "Test: Diagram with mermaid"
date: 2024-08
diagram:
  cache: true
---

# Introduction

This is a test using
[diagram extension](https://github.com/pandoc-ext/diagram)
The
[results](test-mermaid.html)
of [mermaid-filter](https://github.com/raghur/mermaid-filter).
will be different.

``` mermaid
%%| filename: flowchart
%%| fig-cap: A simple flowchart.
graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;

❯ pandoc -s --lua-filter diagram.lua test-diagram.md -o test-diagram.docx -w docx



<img width="883" alt="SCR-20240813-lihz" src="https://github.com/user-attachments/assets/58526a2d-6ac5-42a0-88ce-8e8b0ca6a230">
tarleb commented 3 months ago

That's a bug: the filter produces a SVG image by default, but it seems that ODT does not support SVG images, and pandoc converts the image with an external program. It would be better if the filter would default to PNG images when targetting ODT.

As a temporary workaround, you can configure the mermaid engine to always produce PNG output:

diagram:
  cache: true
  engine:
    mermaid:
      mime-types: [image/png]
reagle commented 3 months ago

Thanks @tarleb, that does work. (I'll note that mermaid-filter also fails at SVG in docx/odt.)

tarleb commented 3 months ago

It seems that the patch didn't fully fix this, thus reopening.

tarleb commented 3 months ago

Now it's fixed.