nip54: update d-tag normalization rules.
This commit is contained in:
+12
-8
@@ -11,20 +11,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NormalizeIdentifier(name string) string {
|
func NormalizeIdentifier(name string) string {
|
||||||
name = strings.TrimSpace(strings.ToLower(name))
|
|
||||||
res, _, _ := transform.Bytes(norm.NFKC, []byte(name))
|
res, _, _ := transform.Bytes(norm.NFKC, []byte(name))
|
||||||
runes := []rune(string(res))
|
runes := []rune(strings.ToLower(string(res)))
|
||||||
|
|
||||||
b := make([]rune, len(runes))
|
words := make([]string, 0, 3)
|
||||||
for i, letter := range runes {
|
word := make([]rune, 0, 12)
|
||||||
|
for _, letter := range runes {
|
||||||
if unicode.IsLetter(letter) || unicode.IsNumber(letter) {
|
if unicode.IsLetter(letter) || unicode.IsNumber(letter) {
|
||||||
b[i] = letter
|
word = append(word, letter)
|
||||||
} else {
|
} else if len(word) > 0 {
|
||||||
b[i] = '-'
|
words = append(words, string(word))
|
||||||
|
word = make([]rune, 0, 12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(word) > 0 {
|
||||||
|
words = append(words, string(word))
|
||||||
|
}
|
||||||
|
|
||||||
return string(b)
|
return strings.Join(words, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ArticleAsHTML(content string) string {
|
func ArticleAsHTML(content string) string {
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ func TestNormalization(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{" hello ", "hello"},
|
{" hello ", "hello"},
|
||||||
{"Goodbye", "goodbye"},
|
{"Goodbye", "goodbye"},
|
||||||
{"the long and winding road / that leads to your door", "the-long-and-winding-road---that-leads-to-your-door"},
|
{"the long and winding road / that leads to your door", "the-long-and-winding-road-that-leads-to-your-door"},
|
||||||
{"it's 平仮名", "it-s-平仮名"},
|
{"it's 平仮名", "it-s-平仮名"},
|
||||||
} {
|
} {
|
||||||
if norm := NormalizeIdentifier(vector.before); norm != vector.after {
|
if norm := NormalizeIdentifier(vector.before); norm != vector.after {
|
||||||
|
|||||||
Reference in New Issue
Block a user