Skip to content

Commit

Permalink
v4.2.0: string.MarkdownEncode() extension added
Browse files Browse the repository at this point in the history
  • Loading branch information
justdmitry committed Dec 15, 2017
1 parent 1fa9d80 commit 03e6ccf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions NetTelegramBotApi/NetTelegramBotApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<Description>Telegram Bot API library</Description>
<AssemblyTitle>NetTelegramBotApi</AssemblyTitle>
<VersionPrefix>4.1.0</VersionPrefix>
<Version>4.2.0</Version>
<TargetFrameworks>net45;net46;netstandard1.3</TargetFrameworks>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<AssemblyName>NetTelegramBotApi</AssemblyName>
<PackageId>NetTelegramBotApi</PackageId>
<PackageTags>telegram;bot;api</PackageTags>
<PackageReleaseNotes>See https://github.com/justdmitry/NetTelegramBotApi/releases/tag/v4.0.0</PackageReleaseNotes>
<PackageReleaseNotes>See https://github.com/justdmitry/NetTelegramBotApi/releases/tag/v4.2.0</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/justdmitry/NetTelegramBotApi/master/package-icon.gif</PackageIconUrl>
<PackageProjectUrl>https://github.com/justdmitry/NetTelegramBotApi</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
Expand Down
19 changes: 19 additions & 0 deletions NetTelegramBotApi/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace System
{
using System.Text.RegularExpressions;

public static class StringExtensions
{
private static readonly Regex WrongChars = new Regex(@"([\*_`\[\]\(\)])");

public static string MarkdownEncode(this string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return value;
}

return WrongChars.Replace(value, @"\$1");
}
}
}
2 changes: 1 addition & 1 deletion TelegramBotDemo-vNext/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static void RunBot(string accessToken)
{
bot.MakeRequestAsync(new SendMessage(
update.Message.Chat.Id,
"You wrote *" + update.Message.Text.Length + " characters*")
"You wrote: \r\n" + update.Message.Text.MarkdownEncode())
{
ParseMode = SendMessage.ParseModeEnum.Markdown
}).Wait();
Expand Down
2 changes: 1 addition & 1 deletion TelegramBotDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static void RunBot(string accessToken)
{
bot.MakeRequestAsync(new SendMessage(
update.Message.Chat.Id,
"You wrote *" + update.Message.Text.Length + " characters*")
"You wrote: \r\n_" + update.Message.Text.MarkdownEncode() + "_")
{
ParseMode = SendMessage.ParseModeEnum.Markdown
}).Wait();
Expand Down

0 comments on commit 03e6ccf

Please sign in to comment.