render system-user-interruption as styled yellow box in prose
This commit is contained in:
parent
e08b69c152
commit
4e455e2dd3
|
|
@ -194,26 +194,28 @@ 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.
|
||||
// These appear as prose between code fences (the server closes the tool
|
||||
// output fence before the interruption and reopens it after).
|
||||
static const QRegularExpression interruptionRe(
|
||||
R"(<system-user-interruption>\n([\s\S]*?)\n</system-user-interruption>)");
|
||||
QString processed;
|
||||
QString processed = markdown;
|
||||
{
|
||||
int cursor = 0;
|
||||
QString rebuilt;
|
||||
auto it = interruptionRe.globalMatch(markdown);
|
||||
while (it.hasNext()) {
|
||||
const auto match = it.next();
|
||||
processed += markdown.mid(cursor, match.capturedStart() - cursor);
|
||||
rebuilt += markdown.mid(cursor, match.capturedStart() - cursor);
|
||||
const QString content = match.captured(1).toHtmlEscaped();
|
||||
processed += QStringLiteral(
|
||||
rebuilt += 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);
|
||||
rebuilt += markdown.mid(cursor);
|
||||
processed = rebuilt;
|
||||
}
|
||||
|
||||
static const QRegularExpression fenceRe(
|
||||
|
|
|
|||
Reference in New Issue