diff options
Diffstat (limited to 'docs/content/en/functions/anchorize.md')
-rw-r--r-- | docs/content/en/functions/anchorize.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/content/en/functions/anchorize.md b/docs/content/en/functions/anchorize.md new file mode 100644 index 000000000..b5bd22e07 --- /dev/null +++ b/docs/content/en/functions/anchorize.md @@ -0,0 +1,27 @@ +--- +title: anchorize +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. +date: 2018-10-13 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [markdown,strings] +signature: ["anchorize INPUT"] +hugoversion: "0.39" +workson: [] +relatedfuncs: [humanize] +--- + +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). If [Blackfriday](https://gohugo.io/getting-started/configuration-markup#blackfriday) is set as `defaultMarkdownHandler`, this template function uses the [`SanitizedAnchorName` logic from Blackfriday](https://github.com/russross/blackfriday#sanitized-anchor-names) (the same applies when `markup.goldmark.parser.autoHeadingIDType` is set to `blackfriday`). + +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. + +```go-html-template +{{ anchorize "This is a header" }} --> "this-is-a-header" +{{ anchorize "This is also a header" }} --> "this-is-also----a-header" +{{ anchorize "main.go" }} --> "maingo" +{{ anchorize "Article 123" }} --> "article-123" +{{ anchorize "<- Let's try this, shall we?" }} --> "--lets-try-this-shall-we" +{{ anchorize "Hello, 世界" }} --> "hello-世界" +``` |