revert all system-user-interruption changes

This commit is contained in:
Levi Neely 2026-08-03 00:41:49 +02:00
parent 64883cf9b8
commit 7cb809fad2
1 changed files with 3 additions and 26 deletions

View File

@ -193,41 +193,18 @@ QString ChatBlockModel::highlightCode(const QString &code, const QString &langua
QString ChatBlockModel::renderMarkdown(const QString &markdown) const
{
// Pre-process: render <system-user-interruption> blocks as styled boxes.
// Manual global-match loop instead of replace-with-lambda, which requires
// Qt 6.5+ and isn't available on all target systems.
static const QRegularExpression interruptionRe(
R"(<system-user-interruption>\n([\s\S]*?)\n</system-user-interruption>)");
QString processed;
{
int cursor = 0;
auto it = interruptionRe.globalMatch(markdown);
while (it.hasNext()) {
const auto match = it.next();
processed += markdown.mid(cursor, match.capturedStart() - cursor);
const QString content = match.captured(1).toHtmlEscaped();
processed += QStringLiteral(
"<div style=\"background:#fff8e1;border:1px solid #ffca28;"
"border-radius:4px;padding:8px;margin:8px 0;white-space:pre-wrap;\">"
"\u26A0\uFE0F <strong>User interruption</strong>\n")
+ content + QStringLiteral("</div>");
cursor = match.capturedEnd();
}
processed += markdown.mid(cursor);
}
static const QRegularExpression fenceRe(
R"(```([A-Za-z0-9_+.-]*)[^\n]*\n([\s\S]*?)\n```(\n|$))");
QString result;
int cursor = 0;
auto it = fenceRe.globalMatch(processed);
auto it = fenceRe.globalMatch(markdown);
while (it.hasNext()) {
const auto match = it.next();
// Prose before this fence: HTML-escape and wrap in pre-wrap div to
// preserve newlines and whitespace. QTextDocument::setMarkdown would
// collapse single newlines (standard Markdown behavior).
const QString prose = processed.mid(cursor, match.capturedStart() - cursor);
const QString prose = markdown.mid(cursor, match.capturedStart() - cursor);
if (!prose.isEmpty())
result += QStringLiteral("<div style=\"white-space:pre-wrap\">")
+ prose.toHtmlEscaped() + QStringLiteral("</div>");
@ -241,7 +218,7 @@ QString ChatBlockModel::renderMarkdown(const QString &markdown) const
static const QRegularExpression openFenceRe(
R"(^```([A-Za-z0-9_+.-]*)[^\n]*\n([\s\S]*)$)",
QRegularExpression::MultilineOption);
const auto tail = processed.mid(cursor);
const auto tail = markdown.mid(cursor);
if (!tail.isEmpty()) {
const auto open = openFenceRe.match(tail);
if (open.hasMatch()) {