mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit 'de0df119b504a91c9e1f442b07954f366ffb2932'
This commit is contained in:
@@ -7,6 +7,7 @@ action:
|
||||
aliases: [trim]
|
||||
related:
|
||||
- functions/strings/Chomp
|
||||
- functions/strings/TrimSpace
|
||||
- functions/strings/TrimLeft
|
||||
- functions/strings/TrimPrefix
|
||||
- functions/strings/TrimRight
|
||||
@@ -19,41 +20,3 @@ aliases: [/functions/trim]
|
||||
```go-html-template
|
||||
{{ trim "++foo--" "+-" }} → foo
|
||||
```
|
||||
|
||||
To remove leading and trailing newline characters and carriage returns:
|
||||
|
||||
```go-html-template
|
||||
{{ trim "\nfoo\n" "\n\r" }} → foo
|
||||
{{ trim "\n\nfoo\n\n" "\n\r" }} → foo
|
||||
|
||||
{{ trim "\r\nfoo\r\n" "\n\r" }} → foo
|
||||
{{ trim "\r\n\r\nfoo\r\n\r\n" "\n\r" }} → foo
|
||||
```
|
||||
|
||||
The `strings.Trim` function is commonly used in shortcodes to remove leading and trailing newlines characters and carriage returns from the content within the opening and closing shortcode tags.
|
||||
|
||||
For example, with this Markdown:
|
||||
|
||||
```text
|
||||
{{</* my-shortcode */>}}
|
||||
Able was I ere I saw Elba.
|
||||
{{</* /my-shortcode */>}}
|
||||
```
|
||||
|
||||
The value of `.Inner` in the shortcode template is:
|
||||
|
||||
```text
|
||||
\nAble was I ere I saw Elba.\n
|
||||
```
|
||||
|
||||
If authored on a Windows system the value of `.Inner` might, depending on the editor configuration, be:
|
||||
|
||||
```text
|
||||
\r\nAble was I ere I saw Elba.\r\n
|
||||
```
|
||||
|
||||
This construct is common in shortcode templates:
|
||||
|
||||
```go-html-template
|
||||
{{ trim .Inner "\n\r" }}
|
||||
```
|
||||
|
Reference in New Issue
Block a user