diff --git a/plugin/markdown/markdown.go b/plugin/markdown/markdown.go index e74b7e99a..06cc9429e 100644 --- a/plugin/markdown/markdown.go +++ b/plugin/markdown/markdown.go @@ -134,8 +134,8 @@ func (s *service) ExtractTags(content []byte) ([]string, error) { return nil, err } - // Deduplicate and normalize tags - return uniqueLowercase(tags), nil + // Deduplicate tags while preserving original case + return uniquePreserveCase(tags), nil } // ExtractProperties computes boolean properties about the content. @@ -334,8 +334,8 @@ func (s *service) ExtractAll(content []byte) (*ExtractedData, error) { return nil, err } - // Deduplicate and normalize tags - data.Tags = uniqueLowercase(data.Tags) + // Deduplicate tags while preserving original case + data.Tags = uniquePreserveCase(data.Tags) return data, nil } @@ -372,16 +372,15 @@ func (s *service) RenameTag(content []byte, oldTag, newTag string) (string, erro return mdRenderer.Render(root, content), nil } -// uniqueLowercase returns unique lowercase strings from input. -func uniqueLowercase(strs []string) []string { - seen := make(map[string]bool) +// uniquePreserveCase returns unique strings from input while preserving case. +func uniquePreserveCase(strs []string) []string { + seen := make(map[string]struct{}) var result []string for _, s := range strs { - lower := strings.ToLower(s) - if !seen[lower] { - seen[lower] = true - result = append(result, lower) + if _, exists := seen[s]; !exists { + seen[s] = struct{}{} + result = append(result, s) } } diff --git a/plugin/markdown/markdown_test.go b/plugin/markdown/markdown_test.go index 01d87a7cc..3b642b289 100644 --- a/plugin/markdown/markdown_test.go +++ b/plugin/markdown/markdown_test.go @@ -223,7 +223,7 @@ func TestExtractTags(t *testing.T) { name: "duplicate tags", content: "#work is important. #Work #WORK", withExt: true, - expected: []string{"work"}, // Deduplicated and lowercased + expected: []string{"work", "Work", "WORK"}, }, { name: "tags with hyphens and underscores", @@ -315,7 +315,7 @@ func TestExtractTags(t *testing.T) { } } -func TestUniqueLowercase(t *testing.T) { +func TestUniquePreserveCase(t *testing.T) { tests := []struct { name string input []string @@ -334,18 +334,18 @@ func TestUniqueLowercase(t *testing.T) { { name: "duplicates", input: []string{"tag", "TAG", "Tag"}, - expected: []string{"tag"}, + expected: []string{"tag", "TAG", "Tag"}, }, { name: "mixed", input: []string{"Work", "work", "Important", "work"}, - expected: []string{"work", "important"}, + expected: []string{"Work", "work", "Important"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := uniqueLowercase(tt.input) + result := uniquePreserveCase(tt.input) assert.ElementsMatch(t, tt.expected, result) }) }