From 28f4ec3af2afafe258130a2f4f3c26dc4b61bf6d Mon Sep 17 00:00:00 2001 From: Erik <90757653+GeneralUser01@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:12:45 +0100 Subject: [PATCH] FEAT(client,markdown): Support multiple code-blocks per message The way code-blocks are handled was here changed to support multiple code-blocks per message. This allows content that is not formatted as code between code-blocks, whereas previously everything between the first start of a code-block and the last end of a code-block would become part of one code-block. The only other change is to only end a code-block on the end-signature when it is right after a new line, so triple backticks may also be included as long as they are not at the start of a line. For explanation on how the regex functions, see [perl - Regex to match any character including new lines](https://stackoverflow.com/a/8303507) --- src/mumble/Markdown.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mumble/Markdown.cpp b/src/mumble/Markdown.cpp index 0d1ba6839a4..46afdbcc602 100644 --- a/src/mumble/Markdown.cpp +++ b/src/mumble/Markdown.cpp @@ -257,7 +257,7 @@ bool processMarkdownInlineCode(QString &str, qsizetype &offset) { bool processMarkdownCodeBlock(QString &str, qsizetype &offset) { // Code blocks are marked as ```code``` // Also consume a potential following newline as the
tag will cause a linebreak anyways - static const QRegularExpression s_regex(QLatin1String("```.*\\n((?:[^`]|``?[^`]?)*)```(\\r\\n|\\n|\\r)?")); + static const QRegularExpression s_regex(QLatin1String("```.*\\n((.|\\n)+?)\\n```(\\r\\n|\\n|\\r)?")); const QRegularExpressionMatch match = regexMatch(s_regex, str, offset); if (match.hasMatch()) {