From 7d75ba8524eb4bcf60e2aae292df025db8208994 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sat, 1 Aug 2026 12:00:14 +0200 Subject: [PATCH] gui: preserve original indentation in fenced code/diff blocks - C++: Use
instead ofwith
so raw newlines are preserved through to the HTML renderer - QML: Use TextEdit (preserves whitespace) instead of Label (collapses it) for rendering blockRenderedHtml --- gui/chatblockmodel.cpp | 18 +++++++++--------- gui/main.qml | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gui/chatblockmodel.cpp b/gui/chatblockmodel.cpp index 53a0bb5..e83dd1d 100644 --- a/gui/chatblockmodel.cpp +++ b/gui/chatblockmodel.cpp @@ -151,7 +151,7 @@ QString ChatBlockModel::highlightCode(const QString &code, const QString &langua if (!def.isValid()) { delete repo; - return QStringLiteral("") + escapeHtml(code).replace('\n', QStringLiteral(""); + return QStringLiteral("
")) + QStringLiteral("") + escapeHtml(code) + QStringLiteral(""); } HtmlHighlighter builder; @@ -163,29 +163,29 @@ QString ChatBlockModel::highlightCode(const QString &code, const QString &langua for (int i = 0; i < lines.size(); ++i) { state = builder.processLine(lines[i], state); if (i < lines.size() - 1) - builder.html += QStringLiteral("
"); + builder.html += '\n'; } delete repo; - return QStringLiteral("") + builder.html + QStringLiteral(""); + return QStringLiteral("") + builder.html + QStringLiteral(""); } QString ChatBlockModel::renderDiff(const QString &diff) const { - QString html = QStringLiteral(""); + QString html = QStringLiteral(""); + html += QStringLiteral(""); return html; } diff --git a/gui/main.qml b/gui/main.qml index 0636087..639cbde 100644 --- a/gui/main.qml +++ b/gui/main.qml @@ -716,12 +716,13 @@ ApplicationWindow { spacing: 0 // Rendered HTML (fenced code/diff) — shown when available - Label { + TextEdit { Layout.fillWidth: true visible: blockRenderedHtml && blockRenderedHtml.length > 0 text: blockRenderedHtml textFormat: Text.RichText - wrapMode: Text.WordWrap + readOnly: true + wrapMode: TextEdit.Wrap font.family: theme.fontFamily || "monospace" font.pointSize: theme.fontSize > 0 ? theme.fontSize : 12 color: theme.textColor"); const QStringList lines = diff.split('\n'); for (const QString &line : lines) { if (line.startsWith('+')) { - html += QStringLiteral("") + escapeHtml(line) + QStringLiteral("
"); + html += QStringLiteral("") + escapeHtml(line) + QStringLiteral("\n"); } else if (line.startsWith('-')) { - html += QStringLiteral("") + escapeHtml(line) + QStringLiteral("
"); + html += QStringLiteral("") + escapeHtml(line) + QStringLiteral("\n"); } else if (line.startsWith("@@")) { - html += QStringLiteral("") + escapeHtml(line) + QStringLiteral("
"); + html += QStringLiteral("") + escapeHtml(line) + QStringLiteral("\n"); } else { - html += escapeHtml(line) + QStringLiteral("
"); + html += escapeHtml(line) + '\n'; } } - html += QStringLiteral("