From 44558b8109e43b2d20ec125bebf2ce14f24cd573 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 23 May 2021 01:05:53 +0100 Subject: [PATCH] Discord: Remove extra newlines around links Since links are converted into embeds, links put on their own line often lead to extra newlines that looks pretty weird. They should now be stripped. --- stripmd.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stripmd.go b/stripmd.go index caed8ea..46a9a15 100644 --- a/stripmd.go +++ b/stripmd.go @@ -44,6 +44,16 @@ func StripAltText(md string, links bool) (string, []*dg.MessageEmbed) { out += md[URLStart : URLEnd+1] } previousURLEnd = URLEnd + // Removing links often leaves a load of extra newlines which look weird, this removes them. + if links { + next := 2 + for md[URLEnd+next] == '\n' { + next++ + } + if next >= 3 { + previousURLEnd += next - 2 + } + } altTextStart, URLStart, URLEnd = -1, -1, -1 continue }