Add strikethrough formatting

This commit is contained in:
Bohdan Horbeshko 2022-03-11 12:54:03 -05:00
parent cdbd960ff4
commit 5514bc9d16
2 changed files with 32 additions and 0 deletions

View file

@ -20,6 +20,8 @@ type InsertionStack []*Insertion
var boldRunesMarkdown = []rune("**") var boldRunesMarkdown = []rune("**")
var boldRunesXEP0393 = []rune("*") var boldRunesXEP0393 = []rune("*")
var italicRunes = []rune("_") var italicRunes = []rune("_")
var strikeRunesMarkdown = []rune("~~")
var strikeRunesXEP0393 = []rune("~")
var codeRunes = []rune("`") var codeRunes = []rune("`")
var preRuneStart = []rune("```\n") var preRuneStart = []rune("```\n")
var preRuneEnd = []rune("\n```") var preRuneEnd = []rune("\n```")
@ -133,6 +135,8 @@ func EntityToMarkdown(entity *client.TextEntity) (*Insertion, *Insertion) {
return markupBraces(entity, boldRunesMarkdown, boldRunesMarkdown) return markupBraces(entity, boldRunesMarkdown, boldRunesMarkdown)
case client.TypeTextEntityTypeItalic: case client.TypeTextEntityTypeItalic:
return markupBraces(entity, italicRunes, italicRunes) return markupBraces(entity, italicRunes, italicRunes)
case client.TypeTextEntityTypeStrikethrough:
return markupBraces(entity, strikeRunesMarkdown, strikeRunesMarkdown)
case client.TypeTextEntityTypeCode: case client.TypeTextEntityTypeCode:
return markupBraces(entity, codeRunes, codeRunes) return markupBraces(entity, codeRunes, codeRunes)
case client.TypeTextEntityTypePre: case client.TypeTextEntityTypePre:
@ -159,6 +163,8 @@ func EntityToXEP0393(entity *client.TextEntity) (*Insertion, *Insertion) {
return markupBraces(entity, boldRunesXEP0393, boldRunesXEP0393) return markupBraces(entity, boldRunesXEP0393, boldRunesXEP0393)
case client.TypeTextEntityTypeItalic: case client.TypeTextEntityTypeItalic:
return markupBraces(entity, italicRunes, italicRunes) return markupBraces(entity, italicRunes, italicRunes)
case client.TypeTextEntityTypeStrikethrough:
return markupBraces(entity, strikeRunesXEP0393, strikeRunesXEP0393)
case client.TypeTextEntityTypeCode: case client.TypeTextEntityTypeCode:
// inline code is non-standard // inline code is non-standard
return markupBraces(entity, codeRunes, codeRunes) return markupBraces(entity, codeRunes, codeRunes)

View file

@ -366,3 +366,29 @@ func TestFormattingXEP0393InlineCode(t *testing.T) {
t.Errorf("Wrong intersecting formatting: %v", markup) 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)
}
}