fix: Check readable symbols for markdown

This commit is contained in:
Petr Mironychev 2025-04-29 21:55:44 +02:00
parent 43adc95857
commit 9225c0c1a9
3 changed files with 27 additions and 2 deletions

View File

@ -29,4 +29,25 @@ void ChatUtils::copyToClipboard(const QString &text)
QGuiApplication::clipboard()->setText(text);
}
QString ChatUtils::getSafeMarkdownText(const QString &text) const
{
// TODO replace to QTextMarkdownImporter after QtC on Qt6.9.0
QString safeText;
safeText.reserve(text.size());
for (QChar ch : text) {
if (ch.isNull()) {
safeText.append(' ');
} else if (ch == '\n' || ch == '\t' || ch == '\r' || ch == ' ') {
safeText.append(ch);
} else if (ch.isPrint()) {
safeText.append(ch);
} else {
safeText.append(QChar(0xFFFD));
}
}
return safeText;
}
} // namespace QodeAssist::Chat

View File

@ -34,6 +34,7 @@ public:
: QObject(parent) {};
Q_INVOKABLE void copyToClipboard(const QString &text);
Q_INVOKABLE QString getSafeMarkdownText(const QString &text) const;
};
} // namespace QodeAssist::Chat

View File

@ -158,9 +158,12 @@ Rectangle {
height: implicitHeight + 10
verticalAlignment: Text.AlignVCenter
leftPadding: 10
text: itemData.text
}
text: utils.getSafeMarkdownText(itemData.text)
ChatUtils {
id: utils
}
}
component CodeBlockComponent : CodeBlock {
id: codeblock