aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-19 00:24:27 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-19 00:24:27 +0200
commit6beaa000d590db342bc0198590686cbbd6304eb4 (patch)
treed0b91fa35c19ae366677ed810025c8f4923e2033
parent9cbba813ff41549467af38a9f0ce3eb28d4c157b (diff)
Disable mention formatting in single line code blocks
-rw-r--r--plugins/Matrix.hpp1
-rw-r--r--src/plugins/Matrix.cpp16
2 files changed, 10 insertions, 7 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 0e96fd7..0c90587 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -585,6 +585,7 @@ namespace QuickMedia {
// No-op if sync is cache or if |room| is not the currently enabled event queue room
void trigger_event(RoomData *room, std::unique_ptr<MatrixEvent> event);
+ void formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str);
void replace_mentions(RoomData *room, std::string &text);
std::string body_to_formatted_body(RoomData *room, const std::string &body);
std::string create_formatted_body_for_message_reply(RoomData *room, const Message *message, const std::string &body);
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index bf988ca..4328888 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -2751,14 +2751,16 @@ namespace QuickMedia {
return std::string::npos;
}
- static void formatted_body_add_line(std::string &formatted_body, const std::string &line_str) {
+ void Matrix::formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str) {
size_t index = 0;
while(true) {
size_t backquote_start_index = find_backquote_index_with_escape(line_str, index);
if(backquote_start_index != std::string::npos) {
size_t backquote_end_index = find_backquote_index_with_escape(line_str, backquote_start_index + 1);
if(backquote_end_index != std::string::npos) {
- formatted_body += line_str.substr(index, backquote_start_index - index);
+ std::string str_to_append = line_str.substr(index, backquote_start_index - index);
+ replace_mentions(room, str_to_append);
+ formatted_body += std::move(str_to_append);
formatted_body += "<code>";
formatted_body += line_str.substr(backquote_start_index + 1, backquote_end_index - (backquote_start_index + 1));
formatted_body += "</code>";
@@ -2767,7 +2769,9 @@ namespace QuickMedia {
}
}
- formatted_body += line_str.substr(index);
+ std::string str_to_append = line_str.substr(index);
+ replace_mentions(room, str_to_append);
+ formatted_body += std::move(str_to_append);
break;
}
}
@@ -2856,15 +2860,13 @@ namespace QuickMedia {
} else {
if(!is_inside_code_block && size > 0 && str[0] == '>') {
formatted_body += "<font color=\"#789922\">";
- replace_mentions(room, line_str);
- formatted_body_add_line(formatted_body, line_str);
+ formatted_body_add_line(room, formatted_body, line_str);
formatted_body += "</font>";
} else {
if(is_inside_code_block) {
formatted_body += line_str;
} else {
- replace_mentions(room, line_str);
- formatted_body_add_line(formatted_body, line_str);
+ formatted_body_add_line(room, formatted_body, line_str);
}
}
is_first_line = false;