markup/goldmark: Adjust auto ID space handling
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 5 Jan 2020 14:58:14 +0000 (15:58 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 5 Jan 2020 14:58:14 +0000 (15:58 +0100)
GitHub does not consider tabs as delimiter, see https://github.com/bep/portable-hugo-links/blob/master/blog/p2.md

Closes #6710

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

index 950d4a5778ee89239d9bd48e62b2253a70553474..72cb79f714e347b08160e4e0ad40e7da05e69083 100644 (file)
@@ -58,7 +58,7 @@ func sanitizeAnchorNameWithHook(b []byte, idType string, hook func(buf *bytes.Bu
                        r, size := utf8.DecodeRune(b)
                        switch {
                        case asciiOnly && size != 1:
-                       case r == '-' || isSpace(r):
+                       case r == '-' || r == ' ':
                                buf.WriteRune('-')
                        case isAlphaNumeric(r):
                                buf.WriteRune(unicode.ToLower(r))
@@ -85,10 +85,6 @@ func isAlphaNumeric(r rune) bool {
        return r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r)
 }
 
-func isSpace(r rune) bool {
-       return r == ' ' || r == '\t'
-}
-
 var _ parser.IDs = (*idFactory)(nil)
 
 type idFactory struct {
index 1257b348250ed66b2b719b0a0aa9b528ae1628fa..0ddf5e886ab42ad7b32a94ac607e087027da07c7 100644 (file)
@@ -40,6 +40,8 @@ Many   spaces  here
 Forward/slash
 Backward\slash
 Under_score
+Nonbreaking Space
+Tab    Space
 `
 
        expect := `
@@ -56,6 +58,8 @@ many---spaces--here
 forwardslash
 backwardslash
 under_score
+nonbreakingspace
+tabspace
 `
 
        tests, expect = strings.TrimSpace(tests), strings.TrimSpace(expect)