diff --git a/lib/common/src/version.h b/lib/common/src/version.h index f57da302..e23bda7c 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "4.35" +#define NCHAT_VERSION "4.36" diff --git a/lib/ncutil/src/strutil.cpp b/lib/ncutil/src/strutil.cpp index 39064100..de2a02c9 100644 --- a/lib/ncutil/src/strutil.cpp +++ b/lib/ncutil/src/strutil.cpp @@ -1,6 +1,6 @@ // strutil.cpp // -// Copyright (c) 2020-2023 Kristofer Berggren +// Copyright (c) 2020-2024 Kristofer Berggren // All rights reserved. // // nchat is distributed under the MIT license, see LICENSE for details. @@ -55,6 +55,36 @@ std::string StrUtil::Emojize(const std::string& p_Str, bool p_Pad /*= false*/) return EmojiUtil::Emojize(p_Str, p_Pad); } +std::string StrUtil::EscapeRawUrls(const std::string& p_Str) +{ + std::string str = p_Str; + std::string rv; + std::regex rg("\\(?\\[?(http|https):\\/\\/([^\\s]+)"); + std::smatch sm; + while (regex_search(str, sm, rg)) + { + rv += sm.prefix().str(); + + std::string url = sm.str(); + if (url.size() >= 2) + { + if ((url.front() == '(') || (url.front() == '[')) + { + rv += url; + } + else + { + rv += "[" + url + "]"; + } + } + str = sm.suffix(); + } + + rv += str; + + return rv; +} + std::vector StrUtil::ExtractUrlsFromStr(const std::string& p_Str) { std::string str = p_Str; diff --git a/lib/ncutil/src/strutil.h b/lib/ncutil/src/strutil.h index f2c71b70..7c43c82e 100644 --- a/lib/ncutil/src/strutil.h +++ b/lib/ncutil/src/strutil.h @@ -1,6 +1,6 @@ // strutil.h // -// Copyright (c) 2020-2023 Kristofer Berggren +// Copyright (c) 2020-2024 Kristofer Berggren // All rights reserved. // // nchat is distributed under the MIT license, see LICENSE for details. @@ -19,6 +19,7 @@ class StrUtil static void DeleteToNextMatch(std::wstring& p_Str, int& p_Pos, int p_Offs, std::wstring p_Chars); static void DeleteToPrevMatch(std::wstring& p_Str, int& p_Pos, int p_Offs, std::wstring p_Chars); static std::string Emojize(const std::string& p_Str, bool p_Pad = false); + static std::string EscapeRawUrls(const std::string& p_Str); static std::vector ExtractUrlsFromStr(const std::string& p_Str); static std::string GetPass(); static std::string GetPhoneNumber(); diff --git a/lib/tgchat/src/tgchat.cpp b/lib/tgchat/src/tgchat.cpp index 010e4bb9..55330672 100644 --- a/lib/tgchat/src/tgchat.cpp +++ b/lib/tgchat/src/tgchat.cpp @@ -1,6 +1,6 @@ // tgchat.cpp // -// Copyright (c) 2020-2023 Kristofer Berggren +// Copyright (c) 2020-2024 Kristofer Berggren // All rights reserved. // // nchat is distributed under the MIT license, see LICENSE for details. @@ -2668,10 +2668,12 @@ td::td_api::object_ptr TgChat::Impl::GetFormattedText static const int32_t markdownVersion = (m_Config.Get("markdown_version") == "1") ? 1 : 2; if (markdownEnabled) { + const std::string text = StrUtil::EscapeRawUrls(p_Text); + auto textParseMarkdown = td::td_api::make_object(markdownVersion); auto parseTextEntities = - td::td_api::make_object(p_Text, + td::td_api::make_object(text, std::move(textParseMarkdown)); td::Client::Request parseRequest{ 1, std::move(parseTextEntities) }; auto parseResponse = td::Client::execute(std::move(parseRequest)); diff --git a/src/nchat.1 b/src/nchat.1 index cbf11423..0592c9dd 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "January 2024" "nchat v4.35" "User Commands" +.TH NCHAT "1" "January 2024" "nchat v4.36" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS