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
|
QString ChatBlockModel::renderMarkdown(const QString &markdown) const
|
||||||
{
|
{
|
||||||
// Pre-process: render <system-user-interruption> blocks as styled boxes.
|
// 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(
|
static const QRegularExpression interruptionRe(
|
||||||
R"(<system-user-interruption>\n([\s\S]*?)\n</system-user-interruption>)");
|
R"(<system-user-interruption>\n([\s\S]*?)\n</system-user-interruption>)");
|
||||||
QString processed = markdown;
|
QString processed;
|
||||||
processed.replace(interruptionRe, [](const QString &match) -> QString {
|
{
|
||||||
// Extract content between the tags (after opening "<system-user-interruption>\n"
|
int cursor = 0;
|
||||||
// and before trailing "\n</system-user-interruption>").
|
auto it = interruptionRe.globalMatch(markdown);
|
||||||
const int start = QStringLiteral("<system-user-interruption>\n").size();
|
while (it.hasNext()) {
|
||||||
const int end = match.size() - QStringLiteral("\n</system-user-interruption>").size();
|
const auto match = it.next();
|
||||||
const QString content = match.mid(start, end - start).toHtmlEscaped();
|
processed += markdown.mid(cursor, match.capturedStart() - cursor);
|
||||||
return QStringLiteral(
|
const QString content = match.captured(1).toHtmlEscaped();
|
||||||
"<div style=\"background:#fff8e1;border:1px solid #ffca28;"
|
processed += QStringLiteral(
|
||||||
"border-radius:4px;padding:8px;margin:8px 0;white-space:pre-wrap;\">"
|
"<div style=\"background:#fff8e1;border:1px solid #ffca28;"
|
||||||
"\u26A0\uFE0F <strong>User interruption</strong>\n") + content +
|
"border-radius:4px;padding:8px;margin:8px 0;white-space:pre-wrap;\">"
|
||||||
QStringLiteral("</div>");
|
"\u26A0\uFE0F <strong>User interruption</strong>\n")
|
||||||
});
|
+ content + QStringLiteral("</div>");
|
||||||
|
cursor = match.capturedEnd();
|
||||||
|
}
|
||||||
|
processed += markdown.mid(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
static const QRegularExpression fenceRe(
|
static const QRegularExpression fenceRe(
|
||||||
R"(```([A-Za-z0-9_+.-]*)[^\n]*\n([\s\S]*?)\n```(\n|$))");
|
R"(```([A-Za-z0-9_+.-]*)[^\n]*\n([\s\S]*?)\n```(\n|$))");
|
||||||
|
|
|
||||||
Reference in New Issue