fix build: replace-with-lambda requires Qt 6.5+, use manual global-match loop
This commit is contained in:
parent
1fdae741c3
commit
e08b69c152
|
|
@ -194,21 +194,27 @@ 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 = markdown;
|
||||
processed.replace(interruptionRe, [](const QString &match) -> QString {
|
||||
// Extract content between the tags (after opening "<system-user-interruption>\n"
|
||||
// and before trailing "\n</system-user-interruption>").
|
||||
const int start = QStringLiteral("<system-user-interruption>\n").size();
|
||||
const int end = match.size() - QStringLiteral("\n</system-user-interruption>").size();
|
||||
const QString content = match.mid(start, end - start).toHtmlEscaped();
|
||||
return 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>");
|
||||
});
|
||||
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|$))");
|
||||
|
|
|
|||
Reference in New Issue