Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion format/formatcore/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GFMCodeBlock(language, code string) string {
// Anchor produces an anchor for the provided link.
func Anchor(anchor string) string {
return fmt.Sprintf(
"<a name=\"%s\"></a>",
"<a id=\"%s\"></a>",
html.EscapeString(anchor),
)
}
Expand Down
22 changes: 22 additions & 0 deletions format/formatcore/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,25 @@ func TestEscape(t *testing.T) {
})
}
}

func TestAnchor(t *testing.T) {
tests := []struct {
in, out string
}{
{
in: "SimpleAnchor",
out: `<a id="SimpleAnchor"></a>`,
},
{
in: "Anchor With Spaces",
out: `<a id="Anchor With Spaces"></a>`,
},
}

for _, test := range tests {
t.Run(test.in, func(t *testing.T) {
is := is.New(t)
is.Equal(Anchor(test.in), test.out) // Wrong output for Anchor()
})
}
}