From c76a144de2e628731403b546e231b3059a75e11e Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 29 Jul 2026 16:40:18 +0200 Subject: [PATCH] diagrams: re-enable mermaid server via /img/ (raster) endpoint The mermaid container has been replaced with a proper mermaid.ink server. Use /img/ endpoint (returns JPEG) instead of /svg/ since Qt's SVG renderer can't handle CSS class-based styles. Falls back to mmdc CLI with PNG output if server is unavailable. --- gui/chatblockmodel.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/gui/chatblockmodel.cpp b/gui/chatblockmodel.cpp index 6a916b5..2b5a0ac 100644 --- a/gui/chatblockmodel.cpp +++ b/gui/chatblockmodel.cpp @@ -827,11 +827,11 @@ static bool fetchFromPlantUmlServer(const QString &source, const QString &svgPat return true; } -// Fetch SVG from a local Mermaid server (mermaid.ink API), returns true on success -static bool fetchFromMermaidServer(const QString &source, const QString &svgPath) +// Fetch rendered diagram from local mermaid.ink server as JPEG (Qt-compatible raster). +static bool fetchFromMermaidServer(const QString &source, const QString &outPath) { QByteArray encoded = source.toUtf8().toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); - QUrl url(QStringLiteral("http://localhost:8081/svg/") + QString::fromLatin1(encoded)); + QUrl url(QStringLiteral("http://localhost:8081/img/") + QString::fromLatin1(encoded)); QNetworkAccessManager nam; QNetworkRequest req(url); @@ -851,14 +851,14 @@ static bool fetchFromMermaidServer(const QString &source, const QString &svgPath if (!reply->isFinished() || reply->error() != QNetworkReply::NoError) return false; - QByteArray svg = reply->readAll(); - if (svg.isEmpty() || !svg.contains("readAll(); + if (data.isEmpty() || data.size() < 100) return false; - QFile out(svgPath); + QFile out(outPath); if (!out.open(QIODevice::WriteOnly)) return false; - out.write(svg); + out.write(data); return true; } @@ -947,9 +947,10 @@ QString ChatBlockModel::diagramUrl(const QString &source, const QString &languag QFile::rename(actualOutput, outPath); } } else if (lang == QStringLiteral("mermaid")) { - // Mermaid — try local server first (localhost:8081), fall back to mmdc CLI - // Note: server returns SVG which Qt can't render (CSS classes), so skip it - // and always use CLI with PNG output for Qt compatibility. + // Mermaid — try local server first (localhost:8081 /img/ endpoint for raster), + // fall back to mmdc CLI with PNG output. + if (fetchFromMermaidServer(source, outPath)) + return QUrl::fromLocalFile(outPath).toString(); QTemporaryFile input; input.setFileTemplate(QStringLiteral("/tmp/ollie-diagram-XXXXXX.mmd"));