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
This commit is contained in:
Joe Mooring 2020-07-04 17:02:00 -04:00 committed by Bjørn Erik Pedersen
parent a1c3e3c1f3
commit 58c0f5e617
2 changed files with 5 additions and 0 deletions

View 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 {

View 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")
}