Merge commit '74309fe5699a595080fdb3a14711e0869babce99'

This commit is contained in:
Bjørn Erik Pedersen
2018-10-29 09:23:25 +01:00
59 changed files with 306 additions and 127 deletions

View File

@@ -0,0 +1,26 @@
---
title: anchorize
description: Takes a string and sanitizes it the same way as Blackfriday 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]
---
The template function uses the [`SanitizedAnchorName` logic from Blackfriday](https://github.com/russross/blackfriday#sanitized-anchor-names).
Since the same sanitizing logic is used as the markdown parser, you can determine the ID of a header for linking with anchor tags.
```
{{anchorize "This is a header"}} → "this-is-a-header"
{{anchorize "This is also a header"}} → "this-is-also-a-header"
{{anchorize "main.go"}} → "main-go"
{{anchorize "Article 123"}} → "article-123"
{{anchorize "<- Let's try this, shall we?"}} → "let-s-try-this-shall-we"
{{anchorize "Hello, 世界"}} → "hello-世界"
```

View File

@@ -14,7 +14,7 @@ keywords: [strings,casing]
signature: ["humanize INPUT"]
workson: []
hugoversion:
relatedfuncs: []
relatedfuncs: [anchorize]
deprecated: false
aliases: []
---
@@ -28,4 +28,3 @@ If the input is either an int64 value or the string representation of an integer
{{humanize "52"}} → "52nd"
{{humanize 103}} → "103rd"
```

View File

@@ -22,4 +22,4 @@ aliases: []
Just like in the Go programming language, Go and Hugo templates make heavy use of `range` to iterate over a map, array or slice.
`range` is fundamental to templating in Hugo. (See the [Introduction to Hugo Templates](/templates/introduction/) for more examples.
`range` is fundamental to templating in Hugo. (See the [Introduction to Hugo Templates](/templates/introduction/) for more examples.)