Remove trailing hyphen from auto heading ID
authorJoe Mooring <joe.mooring@veriphor.com>
Sat, 4 Jul 2020 21:02:00 +0000 (17:02 -0400)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 5 Jul 2020 12:13:02 +0000 (14:13 +0200)
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

markup/goldmark/autoid.go
markup/goldmark/autoid_test.go

index 72cb79f714e347b08160e4e0ad40e7da05e69083..1ca1ba5e0518fe23739748b3feaffe771023e558 100644 (file)
@@ -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 {
index 0ddf5e886ab42ad7b32a94ac607e087027da07c7..7acae9f4774dad3d496fb8b9eb0e187f9edcd033 100644 (file)
@@ -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")
        }