This commit is contained in:
Bjørn Erik Pedersen 2024-11-13 11:07:57 +01:00
commit 3477d9fcec
No known key found for this signature in database
89 changed files with 745 additions and 856 deletions

View file

@ -7,6 +7,7 @@ action:
aliases: [chomp]
related:
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimRight
@ -19,9 +20,9 @@ aliases: [/functions/chomp]
If the argument is of type `template.HTML`, returns `template.HTML`, else returns a `string`.
```go-html-template
{{ chomp | "foo\n" }} → foo
{{ chomp | "foo\n\n" }} → foo
{{ chomp "foo\n" }} → foo
{{ chomp "foo\n\n" }} → foo
{{ chomp | "foo\r\n" }} → foo
{{ chomp | "foo\r\n\r\n" }} → foo
{{ chomp "foo\r\n" }} → foo
{{ chomp "foo\r\n\r\n" }} → foo
```

View file

@ -1,6 +1,6 @@
---
title: strings.ContainsNonSpace
description: Reports whether the given string contains any non-space characters as defined by Unicode's White Space property.
description: Reports whether the given string contains any non-space characters as defined by Unicode.
categories: []
keywords: []
action:
@ -18,18 +18,12 @@ aliases: [/functions/strings.containsnonspace]
{{< new-in 0.111.0 >}}
Whitespace characters include `\t`, `\n`, `\v`, `\f`, `\r`, and characters in the [Unicode Space Separator] category.
[Unicode Space Separator]: https://www.compart.com/en/unicode/category/Zs
```go-html-template
{{ strings.ContainsNonSpace "\n" }} → false
{{ strings.ContainsNonSpace " " }} → false
{{ strings.ContainsNonSpace "\n abc" }} → true
```
Common whitespace characters include:
```text
'\t', '\n', '\v', '\f', '\r', ' '
```
See the [Unicode Character Database] for a complete list.
[Unicode Character Database]: https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt

View file

@ -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" }}
```

View file

@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimPrefix
- functions/strings/TrimRight
- functions/strings/TrimSuffix

View file

@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimRight
- functions/strings/TrimSuffix

View file

@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimSuffix

View file

@ -0,0 +1,26 @@
---
title: strings.TrimSpace
description: Returns the given string, removing leading and trailing whitespace as defined by Unicode.
categories: []
keywords: []
action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimRight
- functions/strings/TrimSuffix
returnType: string
signatures: [strings.TrimSpace INPUT]
---
{{< new-in 0.136.3 >}}
Whitespace characters include `\t`, `\n`, `\v`, `\f`, `\r`, and characters in the [Unicode Space Separator] category.
[Unicode Space Separator]: https://www.compart.com/en/unicode/category/Zs
```go-html-template
{{ strings.TrimSpace "\n\r\t foo \n\r\t" }} → foo
```

View file

@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimRight