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) + } +}