aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-03-11 20:54:03 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-03-11 20:54:03 +0300
commit5514bc9d16ae4f6c4d26cb66945a5027b93ebcfe (patch)
treea3ee46f2e783e8dabcc9da63a2fd253827d047ac /telegram
parentcdbd960ff4337e2ee3bab877958c99ce6d63958d (diff)
Add strikethrough formatting
Diffstat (limited to 'telegram')
-rw-r--r--telegram/formatter/formatter.go6
-rw-r--r--telegram/formatter/formatter_test.go26
2 files changed, 32 insertions, 0 deletions
diff --git a/telegram/formatter/formatter.go b/telegram/formatter/formatter.go
index 8ab4281..6d40720 100644
--- a/telegram/formatter/formatter.go
+++ b/telegram/formatter/formatter.go
@@ -20,6 +20,8 @@ type InsertionStack []*Insertion
var boldRunesMarkdown = []rune("**")
var boldRunesXEP0393 = []rune("*")
var italicRunes = []rune("_")
+var strikeRunesMarkdown = []rune("~~")
+var strikeRunesXEP0393 = []rune("~")
var codeRunes = []rune("`")
var preRuneStart = []rune("```\n")
var preRuneEnd = []rune("\n```")
@@ -133,6 +135,8 @@ func EntityToMarkdown(entity *client.TextEntity) (*Insertion, *Insertion) {
return markupBraces(entity, boldRunesMarkdown, boldRunesMarkdown)
case client.TypeTextEntityTypeItalic:
return markupBraces(entity, italicRunes, italicRunes)
+ case client.TypeTextEntityTypeStrikethrough:
+ return markupBraces(entity, strikeRunesMarkdown, strikeRunesMarkdown)
case client.TypeTextEntityTypeCode:
return markupBraces(entity, codeRunes, codeRunes)
case client.TypeTextEntityTypePre:
@@ -159,6 +163,8 @@ func EntityToXEP0393(entity *client.TextEntity) (*Insertion, *Insertion) {
return markupBraces(entity, boldRunesXEP0393, boldRunesXEP0393)
case client.TypeTextEntityTypeItalic:
return markupBraces(entity, italicRunes, italicRunes)
+ case client.TypeTextEntityTypeStrikethrough:
+ return markupBraces(entity, strikeRunesXEP0393, strikeRunesXEP0393)
case client.TypeTextEntityTypeCode:
// inline code is non-standard
return markupBraces(entity, codeRunes, codeRunes)
diff --git a/telegram/formatter/formatter_test.go b/telegram/formatter/formatter_test.go
index 5e3cdf0..c988b10 100644
--- a/telegram/formatter/formatter_test.go
+++ b/telegram/formatter/formatter_test.go
@@ -366,3 +366,29 @@ func TestFormattingXEP0393InlineCode(t *testing.T) {
t.Errorf("Wrong intersecting formatting: %v", markup)
}
}
+
+func TestFormattingMarkdownStrikethrough(t *testing.T) {
+ markup := Format("Everyone dislikes cake.", []*client.TextEntity{
+ &client.TextEntity{
+ Offset: 9,
+ Length: 3,
+ Type: &client.TextEntityTypeStrikethrough{},
+ },
+ }, EntityToMarkdown)
+ if markup != "Everyone ~~dis~~likes cake." {
+ t.Errorf("Wrong strikethrough formatting: %v", markup)
+ }
+}
+
+func TestFormattingXEP0393Strikethrough(t *testing.T) {
+ markup := Format("Everyone dislikes cake.", []*client.TextEntity{
+ &client.TextEntity{
+ Offset: 9,
+ Length: 3,
+ Type: &client.TextEntityTypeStrikethrough{},
+ },
+ }, EntityToXEP0393)
+ if markup != "Everyone ~dis~likes cake." {
+ t.Errorf("Wrong strikethrough formatting: %v", markup)
+ }
+}