diff --git a/content/en/functions/strings/Chomp.md b/content/en/functions/strings/Chomp.md index 349f1e9b7..087de1fb8 100644 --- a/content/en/functions/strings/Chomp.md +++ b/content/en/functions/strings/Chomp.md @@ -7,6 +7,7 @@ action: aliases: [chomp] related: - functions/strings/Trim + - functions/strings/TrimSpace - functions/strings/TrimLeft - functions/strings/TrimPrefix - functions/strings/TrimRight diff --git a/content/en/functions/strings/ContainsNonSpace.md b/content/en/functions/strings/ContainsNonSpace.md index d4c72eea0..81e11a5ba 100644 --- a/content/en/functions/strings/ContainsNonSpace.md +++ b/content/en/functions/strings/ContainsNonSpace.md @@ -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 diff --git a/content/en/functions/strings/Trim.md b/content/en/functions/strings/Trim.md index 9a87ff206..a8c4cf92d 100644 --- a/content/en/functions/strings/Trim.md +++ b/content/en/functions/strings/Trim.md @@ -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 -{{}} -Able was I ere I saw Elba. -{{}} -``` - -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" }} -``` diff --git a/content/en/functions/strings/TrimLeft.md b/content/en/functions/strings/TrimLeft.md index 07cdf0064..d94aa05a3 100644 --- a/content/en/functions/strings/TrimLeft.md +++ b/content/en/functions/strings/TrimLeft.md @@ -8,6 +8,7 @@ action: related: - functions/strings/Chomp - functions/strings/Trim + - functions/strings/TrimSpace - functions/strings/TrimPrefix - functions/strings/TrimRight - functions/strings/TrimSuffix diff --git a/content/en/functions/strings/TrimPrefix.md b/content/en/functions/strings/TrimPrefix.md index 917cf06f5..331c52a03 100644 --- a/content/en/functions/strings/TrimPrefix.md +++ b/content/en/functions/strings/TrimPrefix.md @@ -8,6 +8,7 @@ action: related: - functions/strings/Chomp - functions/strings/Trim + - functions/strings/TrimSpace - functions/strings/TrimLeft - functions/strings/TrimRight - functions/strings/TrimSuffix diff --git a/content/en/functions/strings/TrimRight.md b/content/en/functions/strings/TrimRight.md index b244925ef..f36597d3d 100644 --- a/content/en/functions/strings/TrimRight.md +++ b/content/en/functions/strings/TrimRight.md @@ -8,6 +8,7 @@ action: related: - functions/strings/Chomp - functions/strings/Trim + - functions/strings/TrimSpace - functions/strings/TrimLeft - functions/strings/TrimPrefix - functions/strings/TrimSuffix diff --git a/content/en/functions/strings/TrimSpace.md b/content/en/functions/strings/TrimSpace.md new file mode 100644 index 000000000..9ac19a1a5 --- /dev/null +++ b/content/en/functions/strings/TrimSpace.md @@ -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 [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 +``` diff --git a/content/en/functions/strings/TrimSuffix.md b/content/en/functions/strings/TrimSuffix.md index 704bbd2d2..d612ae695 100644 --- a/content/en/functions/strings/TrimSuffix.md +++ b/content/en/functions/strings/TrimSuffix.md @@ -8,6 +8,7 @@ action: related: - functions/strings/Chomp - functions/strings/Trim + - functions/strings/TrimSpace - functions/strings/TrimLeft - functions/strings/TrimPrefix - functions/strings/TrimRight diff --git a/content/en/methods/shortcode/Inner.md b/content/en/methods/shortcode/Inner.md index 9271adb34..a428720d7 100644 --- a/content/en/methods/shortcode/Inner.md +++ b/content/en/methods/shortcode/Inner.md @@ -29,7 +29,7 @@ With this shortcode:
{{ . }}
{{ end }}
- {{ trim .Inner "\r\n" }} + {{ .Inner | strings.TrimSpace }}
{{< /code >}} @@ -46,9 +46,9 @@ Is rendered to: ``` {{% note %}} -Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the Markdown. Use the [`trim`] function as shown above to remove both carriage returns and newlines. +Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the Markdown. Use the [`strings.TrimSpace`] function as shown above to remove both carriage returns and newlines. -[`trim`]: /functions/strings/trim/ +[`strings.TrimSpace`]: /functions/strings/trimspace/ {{% /note %}} {{% note %}} @@ -68,7 +68,7 @@ Let's modify the example above to pass the value returned by `Inner` through the
{{ . }}
{{ end }}
- {{ trim .Inner "\r\n" | .Page.RenderString }} + {{ .Inner | strings.TrimSpace | .Page.RenderString }}
{{< /code >}} @@ -119,7 +119,7 @@ Second, because we are rendering the entire shortcode as Markdown, we must adher {{ end }}
- {{ trim .Inner "\r\n" }} + {{ .Inner | strings.TrimSpace }}
{{< /code >}} @@ -136,9 +136,9 @@ The difference between this and the previous example is subtle but required. Not +
{{ . }}
{{ end }}
-- {{ trim .Inner "\r\n" | .Page.RenderString }} +- {{ .Inner | strings.TrimSpace | .Page.RenderString }} + -+ {{ trim .Inner "\r\n" }} ++ {{ .Inner | strings.TrimSpace }}
``` diff --git a/content/en/methods/shortcode/InnerDeindent.md b/content/en/methods/shortcode/InnerDeindent.md index b5f5cf206..ab4263709 100644 --- a/content/en/methods/shortcode/InnerDeindent.md +++ b/content/en/methods/shortcode/InnerDeindent.md @@ -38,7 +38,7 @@ With this shortcode, calling `Inner` instead of `InnerDeindent`: {{< code file=layouts/shortcodes/gallery.html >}} {{< /code >}} @@ -69,7 +69,7 @@ Although technically correct per the CommonMark specification, this is not what {{< code file=layouts/shortcodes/gallery.html >}} {{< /code >}} diff --git a/content/en/methods/shortcode/Parent.md b/content/en/methods/shortcode/Parent.md index c500af375..53fac8237 100644 --- a/content/en/methods/shortcode/Parent.md +++ b/content/en/methods/shortcode/Parent.md @@ -21,7 +21,7 @@ Welcome. Today is {{}}. {{< code file=layouts/shortcodes/greeting.html >}}
- {{ trim .Inner "\r\n" | .Page.RenderString }} + {{ .Inner | strings.TrimSpace | .Page.RenderString }}
{{< /code >}}