Handle Windows line endings and verify empty code blocks
This commit is contained in:
1 parent
77186c4392
commit
c19750a800
4 files changed
+27
-16
No files matched your search
@@ -1,6 +1,8 @@
|
||||
#include "message_text.h"
|
||||
#include "messagedelegate.h"
|
||||
#include "debug_ui.h"
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <QCache>
|
||||
#include <QFontDatabase>
|
||||
#include <QFontMetricsF>
|
||||
@@ -13,11 +15,11 @@
|
||||
#include <KSyntaxHighlighting/Theme>
|
||||
|
||||
bool MessageText::isCode(int position) const {
|
||||
for (const auto& block : code) {
|
||||
if (position < block.start) break;
|
||||
if (position <= block.start + block.length) return true;
|
||||
}
|
||||
return false;
|
||||
auto next = std::upper_bound(code.cbegin(), code.cend(), position,
|
||||
[](int offset, const MessageCodeBlock& block) { return offset < block.start; });
|
||||
if (next == code.cbegin()) return false;
|
||||
const auto& block = *--next;
|
||||
return position <= block.start + block.length;
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -94,7 +96,7 @@ public:
|
||||
for (offset = block.start; offset < end;) {
|
||||
int newline = message.text.indexOf('\n', offset);
|
||||
if (newline < 0 || newline > end) newline = end;
|
||||
state = highlightLine(QStringView(message.text).mid(offset, newline - offset), state);
|
||||
state = highlightLine(message.text.mid(offset, newline - offset), state);
|
||||
offset = newline + 1;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +116,8 @@ protected:
|
||||
|
||||
MessageText parseMessageText(const QString& source) {
|
||||
MessageText result;
|
||||
const auto lines = source.split('\n');
|
||||
QString normalized = source; normalized.replace("\r\n", "\n");
|
||||
const auto lines = normalized.split('\n');
|
||||
static const QRegularExpression fence(QStringLiteral("^```([A-Za-z0-9_+#.-]{0,32})$"));
|
||||
QVector<int> closing(lines.size(), -1);
|
||||
int next = -1;
|
||||
|
||||
Reference in new issue
Block a user