anchorize.md (1236B)
1 ---
2 title: anchorize
3 description: Takes a string and sanitizes it the same way as the [`defaultMarkdownHandler`](https://gohugo.io/getting-started/configuration-markup#configure-markup) does for markdown headers.
4 date: 2018-10-13
5 categories: [functions]
6 menu:
7 docs:
8 parent: "functions"
9 keywords: [markdown,strings]
10 signature: ["anchorize INPUT"]
11 hugoversion: "0.39"
12 workson: []
13 relatedfuncs: [humanize]
14 ---
15
16 If [Goldmark](https://gohugo.io/getting-started/configuration-markup#goldmark) is set as `defaultMarkdownHandler`, the sanitizing logic adheres to the setting [`markup.goldmark.parser.autoHeadingIDType`](https://gohugo.io/getting-started/configuration-markup#goldmark).
17
18 Since the `defaultMarkdownHandler` and this template function use the same sanitizing logic, you can use the latter to determine the ID of a header for linking with anchor tags.
19
20 ```go-html-template
21 {{ anchorize "This is a header" }} --> "this-is-a-header"
22 {{ anchorize "This is also a header" }} --> "this-is-also----a-header"
23 {{ anchorize "main.go" }} --> "maingo"
24 {{ anchorize "Article 123" }} --> "article-123"
25 {{ anchorize "<- Let's try this, shall we?" }} --> "--lets-try-this-shall-we"
26 {{ anchorize "Hello, 世界" }} --> "hello-世界"
27 ```