Skip to content

Commit 4837cf5

Browse files
authored
Merge pull request #1440 from TelegramBots/develop
ToHtml/ToMarkdown: support for ExpandableBlockquote
2 parents 454f298 + 81fe54c commit 4837cf5

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.azure-pipelines/variables.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
variables:
1+
variables:
22
- group: Integration Tests Variables
33
- name: versionPrefix
4-
value: 22.1.0
4+
value: 22.1.1
55
- name: versionSuffix
66
value: ''
77
- name: ciVersionSuffix

src/Telegram.Bot/Extensions/FormatExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static string ToMarkdown(string message, MessageEntity[]? entities)
3636
var md = closings[0].md;
3737
closings.RemoveAt(0);
3838
if (i > 0 && md[0] == '_' && sb[i - 1] == '_') md = '\r' + md;
39-
if (md[0] == '>') { inBlockQuote = false; if (lastCh != '\n' && i < sb.Length && sb[i] != '\n') md = "\n"; else continue; }
39+
if (md[0] == '>') { inBlockQuote = false; md = md[1..]; if (lastCh != '\n' && i < sb.Length && sb[i] != '\n') md += '\n'; }
4040
sb.Insert(i, md); i += md.Length;
4141
}
4242
if (i == sb.Length) break;
@@ -56,7 +56,7 @@ public static string ToMarkdown(string message, MessageEntity[]? entities)
5656
closing.md = $"](tg://emoji?id={nextEntity.CustomEmojiId})";
5757
}
5858
else if (md[0] == '>')
59-
{ inBlockQuote = true; if (lastCh is not '\n' and not '\0') md = "\n>"; }
59+
{ inBlockQuote = true; md = lastCh is not '\n' and not '\0' ? "\n>" : ">"; }
6060
else if (nextEntity.Type is MessageEntityType.Pre)
6161
md = $"```{nextEntity.Language}\n";
6262
int index = ~closings.BinarySearch(closing, Comparer<(int, string)>.Create((x, y) => x.Item1.CompareTo(y.Item1) | 1));
@@ -92,6 +92,7 @@ public static string ToMarkdown(string message, MessageEntity[]? entities)
9292
[MessageEntityType.Spoiler] = "||",
9393
[MessageEntityType.CustomEmoji] = "![",
9494
[MessageEntityType.Blockquote] = ">",
95+
[MessageEntityType.ExpandableBlockquote] = ">||",
9596
};
9697

9798
/// <summary>Insert backslashes in front of MarkdownV2 reserved characters</summary>
@@ -168,6 +169,8 @@ public static string ToHtml(string message, MessageEntity[]? entities)
168169
closing.Item2 = "</code></pre>";
169170
tag = $"<pre><code class=\"language-{nextEntity.Language}\">";
170171
}
172+
else if (nextEntity.Type is MessageEntityType.ExpandableBlockquote)
173+
tag = "<blockquote expandable>";
171174
else
172175
tag = $"<{tag}>";
173176
int index = ~closings.BinarySearch(closing, Comparer<(int, string)>.Create((x, y) => x.Item1.CompareTo(y.Item1) | 1));
@@ -198,6 +201,7 @@ public static string ToHtml(string message, MessageEntity[]? entities)
198201
[MessageEntityType.Spoiler] = "tg-spoiler",
199202
[MessageEntityType.CustomEmoji] = "tg-emoji",
200203
[MessageEntityType.Blockquote] = "blockquote",
204+
[MessageEntityType.ExpandableBlockquote] = "blockquote",
201205
};
202206

203207
/// <summary>Replace special HTML characters with their &amp;xx; equivalent</summary>

test/Telegram.Bot.Tests.Integ/Framework/RetryTelegramBotClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ namespace Telegram.Bot.Tests.Integ.Framework;
1616
internal class RetryTelegramBotClient(TestConfiguration configuration, IMessageSink diagnosticMessageSink, CancellationToken ct = default)
1717
: WTelegramBotClient(MakeOptions(configuration.ApiToken, configuration.ClientApiToken.Split(':')), cancellationToken: ct)
1818
{
19+
private static StreamWriter WTelegramLogs = new StreamWriter("WTelegramBot.log", true, System.Text.Encoding.UTF8) { AutoFlush = true };
1920
private static WTelegramBotClientOptions MakeOptions(string botToken, string[] api)
2021
{
2122
var connection = new Microsoft.Data.Sqlite.SqliteConnection($"Data Source=WTelegramBot.{botToken.Split(':')[0]}.sqlite");
2223
WTelegram.Helpers.Log = (lvl, str) => System.Diagnostics.Trace.WriteLine(str);
24+
WTelegram.Helpers.Log += (lvl, str) => WTelegramLogs.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} [{"TDIWE!"[lvl]}] {str}");
2325
return new(botToken, int.Parse(api[0]), api[1], connection);
2426
}
2527
public void WithStreams(Stream[] _) { }

0 commit comments

Comments
 (0)