Skip to content

Commit

Permalink
Documents strings.TrimSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Oct 19, 2024
1 parent d325308 commit 72e5dfd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 38 deletions.
1 change: 1 addition & 0 deletions content/en/functions/strings/Chomp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ action:
aliases: [chomp]
related:
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimRight
Expand Down
39 changes: 1 addition & 38 deletions content/en/functions/strings/Trim.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ action:
aliases: [trim]
related:
- functions/strings/Chomp
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimRight
Expand All @@ -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" }}
```
1 change: 1 addition & 0 deletions content/en/functions/strings/TrimLeft.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimPrefix
- functions/strings/TrimRight
- functions/strings/TrimSuffix
Expand Down
1 change: 1 addition & 0 deletions content/en/functions/strings/TrimPrefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimRight
- functions/strings/TrimSuffix
Expand Down
1 change: 1 addition & 0 deletions content/en/functions/strings/TrimRight.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimSuffix
Expand Down
26 changes: 26 additions & 0 deletions content/en/functions/strings/TrimSpace.md
Original file line number Diff line number Diff line change
@@ -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.137.0 >}}

Whitespace characters include `\t`, `\n`, `\v`, `\f`, `\r`, and characters in the [Space Separator] category.

[Space Separator]: https://www.compart.com/en/unicode/category/Zs

```go-html-template
{{ strings.TrimSpace "\n\r\t foo \n\r\t" }} → foo
```
1 change: 1 addition & 0 deletions content/en/functions/strings/TrimSuffix.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ action:
related:
- functions/strings/Chomp
- functions/strings/Trim
- functions/strings/TrimSpace
- functions/strings/TrimLeft
- functions/strings/TrimPrefix
- functions/strings/TrimRight
Expand Down

0 comments on commit 72e5dfd

Please sign in to comment.