From 9b6e61464b09ffe3423fb8d7c72bddb7a9ed5b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 5 Jan 2020 15:58:14 +0100 Subject: [PATCH] markup/goldmark: Adjust auto ID space handling 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 | 6 +----- markup/goldmark/autoid_test.go | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/markup/goldmark/autoid.go b/markup/goldmark/autoid.go index 950d4a577..72cb79f71 100644 --- a/markup/goldmark/autoid.go +++ b/markup/goldmark/autoid.go @@ -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 { diff --git a/markup/goldmark/autoid_test.go b/markup/goldmark/autoid_test.go index 1257b3482..0ddf5e886 100644 --- a/markup/goldmark/autoid_test.go +++ b/markup/goldmark/autoid_test.go @@ -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)