mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-27 19:00:30 -04:00
fix: Check readable symbols for markdown
This commit is contained in:
parent
43adc95857
commit
9225c0c1a9
@ -29,4 +29,25 @@ void ChatUtils::copyToClipboard(const QString &text)
|
|||||||
QGuiApplication::clipboard()->setText(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
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
: QObject(parent) {};
|
: QObject(parent) {};
|
||||||
|
|
||||||
Q_INVOKABLE void copyToClipboard(const QString &text);
|
Q_INVOKABLE void copyToClipboard(const QString &text);
|
||||||
|
Q_INVOKABLE QString getSafeMarkdownText(const QString &text) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -158,9 +158,12 @@ Rectangle {
|
|||||||
height: implicitHeight + 10
|
height: implicitHeight + 10
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
leftPadding: 10
|
leftPadding: 10
|
||||||
text: itemData.text
|
text: utils.getSafeMarkdownText(itemData.text)
|
||||||
}
|
|
||||||
|
|
||||||
|
ChatUtils {
|
||||||
|
id: utils
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
component CodeBlockComponent : CodeBlock {
|
component CodeBlockComponent : CodeBlock {
|
||||||
id: codeblock
|
id: codeblock
|
||||||
|
Loading…
Reference in New Issue
Block a user