Ignore multiline literals when detecting code language

This commit is contained in:
evgeny committed 2026-11-02 23:08:37 +01:00
1 parent 6ea6bf20a8
commit 34b71c040e
2 files changed
+8 -1

No files matched your search

+3 -1
View File
@@ -66,7 +66,9 @@ QString detectCodeLanguage(QStringView source) {
return language;
}
// Убираем строки и комментарии перед поиском конструкций, сохраняя границы строк.
static const QRegularExpression ignored(R"re(/\*[\s\S]*?(?:\*/|$)|<!--[\s\S]*?(?:-->|$)|//[^\n]*|"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*')re");
static const QRegularExpression ignored(
R"re(/\*[\s\S]*?(?:\*/|$)|<!--[\s\S]*?(?:-->|$)|//[^\n]*|"""[\s\S]*?(?:"""|$))re"
R"re(|`(?:\\[\s\S]|[^`\\])*(?:`|$)|"(?:\\.|[^"\\\n])*(?:"|$)|'(?:\\.|[^'\\\n])*(?:'|$))re");
QString code = sample;
auto matches = ignored.globalMatch(sample);
while (matches.hasNext()) {