X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/5bb22ac2fc501bad7327c119f1d3ac514e3d5398..522d7fd117285e4e4ce3ea5ec9b5a1722521b681:/telegram_markdown.go?ds=sidebyside diff --git a/telegram_markdown.go b/telegram_markdown.go index 8738bcd..712cf28 100644 --- a/telegram_markdown.go +++ b/telegram_markdown.go @@ -31,6 +31,7 @@ var ( // change the rest of the reply. func telegramMarkdownEntities(markdown string) (string, []TelegramEntity) { var out TelegramMarkdownText + lines := strings.Split(markdown, "\n") for index := 0; index < len(lines); index++ { if index > 0 { @@ -144,6 +145,7 @@ type TelegramMarkdownText struct { // add appends text. func (m *TelegramMarkdownText) add(text string) { m.text.WriteString(text) + m.units += telegramUTF16Units(text) } @@ -164,6 +166,7 @@ func (m *TelegramMarkdownText) inline(line string) { for index < len(line) { if line[index] == '\\' && index+1 < len(line) && strings.IndexByte(telegramMarkdownPunctuation, line[index+1]) >= 0 { m.add(line[plain:index]) + plain = index + 1 index += 2 @@ -177,6 +180,7 @@ func (m *TelegramMarkdownText) inline(line string) { } m.add(line[plain:index]) + start := m.units if span.kind == "code" { m.add(span.content) @@ -256,6 +260,7 @@ func telegramHeadingText(line string) string { // close runs to the end, as in Markdown. func telegramRewriteProse(markdown string, rewrite func(string) string) string { var out strings.Builder + lines := strings.Split(markdown, "\n") for index := 0; index < len(lines); index++ { if index > 0 { @@ -266,6 +271,7 @@ func telegramRewriteProse(markdown string, rewrite func(string) string) string { _, fence := telegramCodeFence(line) if fence == "" { telegramRewriteLineProse(&out, line, rewrite) + continue } @@ -275,6 +281,7 @@ func telegramRewriteProse(markdown string, rewrite func(string) string) string { } out.WriteString(strings.Join(lines[index:end+1], "\n")) + index = end } @@ -302,6 +309,7 @@ func telegramRewriteLineProse(out *strings.Builder, line string, rewrite func(st out.WriteString(rewrite(line[prose:index])) out.WriteString(line[index:end]) + index = end prose = end