From: Joe Mooring Date: Sat, 4 Jul 2020 21:02:00 +0000 (-0400) Subject: Remove trailing hyphen from auto heading ID X-Git-Tag: v0.74.0~10 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=58c0f5e6171cbf8e3ed8d73ac95a7b85168c5b2f;p=brevno-suite%2Fhugo Remove trailing hyphen from auto heading ID Applicable when autoHeadingIDType is either `github` or `github-ascii`. When autoHeadingIDType is `blackfriday`, the existing code removes trailing whitespace while iterating through the characters, using a boolean "futureDash" mechanism. Fixes #6798 --- diff --git a/markup/goldmark/autoid.go b/markup/goldmark/autoid.go index 72cb79f7..1ca1ba5e 100644 --- a/markup/goldmark/autoid.go +++ b/markup/goldmark/autoid.go @@ -54,6 +54,8 @@ func sanitizeAnchorNameWithHook(b []byte, idType string, hook func(buf *bytes.Bu b = text.RemoveAccents(b) } + b = bytes.TrimSpace(b) + for len(b) > 0 { r, size := utf8.DecodeRune(b) switch { diff --git a/markup/goldmark/autoid_test.go b/markup/goldmark/autoid_test.go index 0ddf5e88..7acae9f4 100644 --- a/markup/goldmark/autoid_test.go +++ b/markup/goldmark/autoid_test.go @@ -66,6 +66,9 @@ tabspace testlines, expectlines := strings.Split(tests, "\n"), strings.Split(expect, "\n") + testlines = append(testlines, "Trailing Space ") + expectlines = append(expectlines, "trailing-space") + if len(testlines) != len(expectlines) { panic("test setup failed") }