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.
This commit is contained in:
parent
a598d0c5cc
commit
c76a144de2
|
|
@ -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("<svg"))
|
||||
QByteArray data = reply->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"));
|
||||
|
|
|
|||
Reference in New Issue