diff options
Diffstat (limited to 'telegram/formatter/formatter.go')
-rw-r--r-- | telegram/formatter/formatter.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/telegram/formatter/formatter.go b/telegram/formatter/formatter.go index 5ea5cdb..8ab4281 100644 --- a/telegram/formatter/formatter.go +++ b/telegram/formatter/formatter.go @@ -20,7 +20,9 @@ type InsertionStack []*Insertion var boldRunesMarkdown = []rune("**") var boldRunesXEP0393 = []rune("*") var italicRunes = []rune("_") -var codeRunes = []rune("\n```\n") +var codeRunes = []rune("`") +var preRuneStart = []rune("```\n") +var preRuneEnd = []rune("\n```") // rebalance pumps all the values until the given offset to current stack (growing // from start) from given stack (growing from end); should be called @@ -131,8 +133,10 @@ func EntityToMarkdown(entity *client.TextEntity) (*Insertion, *Insertion) { return markupBraces(entity, boldRunesMarkdown, boldRunesMarkdown) case client.TypeTextEntityTypeItalic: return markupBraces(entity, italicRunes, italicRunes) - case client.TypeTextEntityTypeCode, client.TypeTextEntityTypePre: + case client.TypeTextEntityTypeCode: return markupBraces(entity, codeRunes, codeRunes) + case client.TypeTextEntityTypePre: + return markupBraces(entity, preRuneStart, preRuneEnd) case client.TypeTextEntityTypePreCode: preCode, _ := entity.Type.(*client.TextEntityTypePreCode) return markupBraces(entity, []rune("\n```"+preCode.Language+"\n"), codeRunes) @@ -155,11 +159,13 @@ func EntityToXEP0393(entity *client.TextEntity) (*Insertion, *Insertion) { return markupBraces(entity, boldRunesXEP0393, boldRunesXEP0393) case client.TypeTextEntityTypeItalic: return markupBraces(entity, italicRunes, italicRunes) - case client.TypeTextEntityTypeCode, client.TypeTextEntityTypePre: + case client.TypeTextEntityTypeCode: + // inline code is non-standard return markupBraces(entity, codeRunes, codeRunes) + case client.TypeTextEntityTypePre: + return markupBraces(entity, preRuneStart, preRuneEnd) case client.TypeTextEntityTypePreCode: preCode, _ := entity.Type.(*client.TextEntityTypePreCode) - // TODO: inline code support (non-standard too) return markupBraces(entity, []rune("\n```"+preCode.Language+"\n"), codeRunes) case client.TypeTextEntityTypeTextUrl: textURL, _ := entity.Type.(*client.TextEntityTypeTextUrl) |