diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-27 10:47:28 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-27 10:47:28 +0100 |
commit | fc7de7136acbcf0aef54ae8460c7702bc83709be (patch) | |
tree | c109bb4dd1f1b054db476e7e4117f79bdd62ec9e /docs/content/en/functions/strings | |
parent | 1083bf7c08e6f35826279065b8a09a16cc991c7f (diff) | |
download | hugo-fc7de7136acbcf0aef54ae8460c7702bc83709be.tar.gz hugo-fc7de7136acbcf0aef54ae8460c7702bc83709be.zip |
docs: Prepare for new sub tree
See #11925
Diffstat (limited to 'docs/content/en/functions/strings')
29 files changed, 0 insertions, 832 deletions
diff --git a/docs/content/en/functions/strings/Chomp.md b/docs/content/en/functions/strings/Chomp.md deleted file mode 100644 index 349f1e9b7..000000000 --- a/docs/content/en/functions/strings/Chomp.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: strings.Chomp -description: Returns the given string, removing all trailing newline characters and carriage returns. -categories: [] -keywords: [] -action: - aliases: [chomp] - related: - - functions/strings/Trim - - functions/strings/TrimLeft - - functions/strings/TrimPrefix - - functions/strings/TrimRight - - functions/strings/TrimSuffix - returnType: any - signatures: [strings.Chomp STRING] -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\r\n" }} → foo -{{ chomp | "foo\r\n\r\n" }} → foo -``` diff --git a/docs/content/en/functions/strings/Contains.md b/docs/content/en/functions/strings/Contains.md deleted file mode 100644 index 0344b2981..000000000 --- a/docs/content/en/functions/strings/Contains.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: strings.Contains -description: Reports whether the given string contains the given substring. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/ContainsAny - - functions/strings/ContainsNonSpace - - functions/strings/HasPrefix - - functions/strings/HasSuffix - - functions/collections/In - returnType: bool - signatures: [strings.Contains STRING SUBSTRING] -aliases: [/functions/strings.contains] ---- - -```go-html-template -{{ strings.Contains "Hugo" "go" }} → true -``` - -The check is case sensitive: - -```go-html-template -{{ strings.Contains "Hugo" "Go" }} → false -``` diff --git a/docs/content/en/functions/strings/ContainsAny.md b/docs/content/en/functions/strings/ContainsAny.md deleted file mode 100644 index f331d09f7..000000000 --- a/docs/content/en/functions/strings/ContainsAny.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: strings.ContainsAny -description: Reports whether the given string contains any character within the given set. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Contains - - functions/strings/ContainsNonSpace - - functions/strings/HasPrefix - - functions/strings/HasSuffix - - functions/collections/In - returnType: bool - signatures: [strings.ContainsAny STRING SET] -aliases: [/functions/strings.containsany] ---- - -```go-html-template -{{ strings.ContainsAny "Hugo" "gm" }} → true -``` - -The check is case sensitive: - -```go-html-template -{{ strings.ContainsAny "Hugo" "Gm" }} → false -``` diff --git a/docs/content/en/functions/strings/ContainsNonSpace.md b/docs/content/en/functions/strings/ContainsNonSpace.md deleted file mode 100644 index 188aa14ba..000000000 --- a/docs/content/en/functions/strings/ContainsNonSpace.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: strings.ContainsNonSpace -description: Reports whether the given string contains any non-space characters as defined by Unicode’s White Space property. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Contains - - functions/strings/ContainsAny - - functions/strings/HasPrefix - - functions/strings/HasSuffix - - functions/collections/In - returnType: bool - signatures: [strings.ContainsNonSpace STRING] -aliases: [/functions/strings.containsnonspace] ---- - -{{< new-in 0.111.0 >}} - -```go-html-template -{{ strings.ContainsNonSpace "\n" }} → false -{{ strings.ContainsNonSpace " " }} → false -{{ strings.ContainsNonSpace "\n abc" }} → true -``` - -Common white space 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/docs/content/en/functions/strings/Count.md b/docs/content/en/functions/strings/Count.md deleted file mode 100644 index 43b5baeff..000000000 --- a/docs/content/en/functions/strings/Count.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: strings.Count -description: Returns the number of non-overlapping instances of the given substring within the given string. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/go-template/len - - functions/strings/CountRunes - - functions/strings/CountWords - - functions/strings/RuneCount - returnType: int - signatures: [strings.Count SUBSTR STRING] -aliases: [/functions/strings.count] ---- - -If `SUBSTR` is an empty string, this function returns 1 plus the number of Unicode code points in `STRING`. - -```go-html-template -{{ "aaabaab" | strings.Count "a" }} → 5 -{{ "aaabaab" | strings.Count "aa" }} → 2 -{{ "aaabaab" | strings.Count "aaa" }} → 1 -{{ "aaabaab" | strings.Count "" }} → 8 -``` diff --git a/docs/content/en/functions/strings/CountRunes.md b/docs/content/en/functions/strings/CountRunes.md deleted file mode 100644 index 10788e174..000000000 --- a/docs/content/en/functions/strings/CountRunes.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: strings.CountRunes -description: Returns the number of runes in the given string excluding whitespace. -categories: [] -keywords: [] -action: - aliases: [countrunes] - related: - - functions/go-template/len - - functions/strings/Count - - functions/strings/CountWords - - functions/strings/RuneCount - returnType: int - signatures: [strings.CountRunes INPUT] -aliases: [/functions/countrunes] ---- - -In contrast with the [`strings.RuneCount`] function, which counts every rune in a string, `strings.CountRunes` excludes whitespace. - -```go-html-template -{{ "Hello, 世界" | strings.CountRunes }} → 8 -``` - -[`strings.RuneCount`]: /functions/strings/runecount diff --git a/docs/content/en/functions/strings/CountWords.md b/docs/content/en/functions/strings/CountWords.md deleted file mode 100644 index 3e4ec0465..000000000 --- a/docs/content/en/functions/strings/CountWords.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: strings.CountWords -description: Returns the number of words in the given string. -categories: [] -keywords: [] -action: - aliases: [countwords] - related: - - functions/go-template/len - - functions/strings/Count - - functions/strings/CountRunes - - functions/strings/RuneCount - returnType: int - signatures: [strings.CountWords INPUT] -aliases: [/functions/countwords] ---- - -```go-html-template -{{ "Hugo is a static site generator." | countwords }} → 6 -``` diff --git a/docs/content/en/functions/strings/FindRESubmatch.md b/docs/content/en/functions/strings/FindRESubmatch.md deleted file mode 100644 index 302d1d9b4..000000000 --- a/docs/content/en/functions/strings/FindRESubmatch.md +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: strings.FindRESubmatch -description: Returns a slice of all successive matches of the regular expression. Each element is a slice of strings holding the text of the leftmost match of the regular expression and the matches, if any, of its subexpressions. -categories: [] -keywords: [] -action: - aliases: [findRESubmatch] - related: - - functions/strings/FindRE - - functions/strings/Replace - - functions/strings/ReplaceRE - returnType: '[][]string' - signatures: ['strings.FindRESubmatch PATTERN INPUT [LIMIT]'] -aliases: [/functions/findresubmatch] ---- - -By default, `findRESubmatch` finds all matches. You can limit the number of matches with an optional LIMIT argument. A return value of nil indicates no match. - -{{% include "functions/_common/regular-expressions.md" %}} - -## Demonstrative examples - -```go-html-template -{{ findRESubmatch `a(x*)b` "-ab-" }} → [["ab" ""]] -{{ findRESubmatch `a(x*)b` "-axxb-" }} → [["axxb" "xx"]] -{{ findRESubmatch `a(x*)b` "-ab-axb-" }} → [["ab" ""] ["axb" "x"]] -{{ findRESubmatch `a(x*)b` "-axxb-ab-" }} → [["axxb" "xx"] ["ab" ""]] -{{ findRESubmatch `a(x*)b` "-axxb-ab-" 1 }} → [["axxb" "xx"]] -``` - -## Practical example - -This markdown: - -```text -- [Example](https://example.org) -- [Hugo](https://gohugo.io) -``` - -Produces this HTML: - -```html -<ul> - <li><a href="https://example.org">Example</a></li> - <li><a href="https://gohugo.io">Hugo</a></li> -</ul> -``` - -To match the anchor elements, capturing the link destination and text: - -```go-html-template -{{ $regex := `<a\s*href="(.+?)">(.+?)</a>` }} -{{ $matches := findRESubmatch $regex .Content }} -``` - -Viewed as JSON, the data structure of `$matches` in the code above is: - -```json -[ - [ - "<a href=\"https://example.org\"></a>Example</a>", - "https://example.org", - "Example" - ], - [ - "<a href=\"https://gohugo.io\">Hugo</a>", - "https://gohugo.io", - "Hugo" - ] -] -``` - -To render the `href` attributes: - -```go-html-template -{{ range $matches }} - {{ index . 1 }} -{{ end }} -``` - -Result: - -```text -https://example.org -https://gohugo.io -``` - -{{% note %}} -You can write and test your regular expression using [regex101.com](https://regex101.com/). Be sure to select the Go flavor before you begin. -{{% /note %}} diff --git a/docs/content/en/functions/strings/FindRe.md b/docs/content/en/functions/strings/FindRe.md deleted file mode 100644 index 861f38a12..000000000 --- a/docs/content/en/functions/strings/FindRe.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: strings.FindRE -description: Returns a slice of strings that match the regular expression. -categories: [] -keywords: [] -action: - aliases: [findRE] - related: - - functions/strings/FindRESubmatch - - functions/strings/Replace - - functions/strings/ReplaceRE - returnType: '[]string' - signatures: ['strings.FindRE PATTERN INPUT [LIMIT]'] -aliases: [/functions/findre] ---- -By default, `findRE` finds all matches. You can limit the number of matches with an optional LIMIT argument. - -{{% include "functions/_common/regular-expressions.md" %}} - -This example returns a slice of all second level headings (`h2` elements) within the rendered `.Content`: - -```go-html-template -{{ findRE `(?s)<h2.*?>.*?</h2>` .Content }} -``` - -The `s` flag causes `.` to match `\n` as well, allowing us to find an `h2` element that contains newlines. - -To limit the number of matches to one: - -```go-html-template -{{ findRE `(?s)<h2.*?>.*?</h2>` .Content 1 }} -``` - -{{% note %}} -You can write and test your regular expression using [regex101.com](https://regex101.com/). Be sure to select the Go flavor before you begin. -{{% /note %}} diff --git a/docs/content/en/functions/strings/FirstUpper.md b/docs/content/en/functions/strings/FirstUpper.md deleted file mode 100644 index 8826b4f18..000000000 --- a/docs/content/en/functions/strings/FirstUpper.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: strings.FirstUpper -description: Returns the given string, capitalizing the first character. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Title - - functions/strings/ToLower - - functions/strings/ToUpper - returnType: string - signatures: [strings.FirstUpper STRING] -aliases: [/functions/strings.firstupper] ---- - -```go-html-template -{{ strings.FirstUpper "foo" }} → Foo -``` diff --git a/docs/content/en/functions/strings/HasPrefix.md b/docs/content/en/functions/strings/HasPrefix.md deleted file mode 100644 index 455de0586..000000000 --- a/docs/content/en/functions/strings/HasPrefix.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: strings.HasPrefix -description: Reports whether the given string begins with the given prefix. -categories: [] -keywords: [] -action: - aliases: [hasPrefix] - related: - - functions/strings/Contains - - functions/strings/ContainsAny - - functions/strings/ContainsNonSpace - - functions/strings/HasSuffix - - functions/collections/In - returnType: bool - signatures: [strings.HasPrefix STRING PREFIX] -aliases: [/functions/hasprefix,/functions/strings.hasprefix] ---- - -```go-html-template -{{ hasPrefix "Hugo" "Hu" }} → true -``` diff --git a/docs/content/en/functions/strings/HasSuffix.md b/docs/content/en/functions/strings/HasSuffix.md deleted file mode 100644 index 8fb12c527..000000000 --- a/docs/content/en/functions/strings/HasSuffix.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: strings.HasSuffix -description: Reports whether the given string ends with the given suffix. -categories: [] -keywords: [] -action: - aliases: [hasSuffix] - related: - - functions/strings/Contains - - functions/strings/ContainsAny - - functions/strings/ContainsNonSpace - - functions/strings/HasPrefix - - functions/collections/In - returnType: bool - signatures: [strings.HasSuffix STRING SUFFIX] -aliases: [/functions/hassuffix,/functions/strings/hassuffix] ---- - -```go-html-template -{{ hasSuffix "Hugo" "go" }} → true -``` diff --git a/docs/content/en/functions/strings/Repeat.md b/docs/content/en/functions/strings/Repeat.md deleted file mode 100644 index 530b0d14b..000000000 --- a/docs/content/en/functions/strings/Repeat.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: strings.Repeat -description: Returns a new string consisting of zero or more copies of another string. -categories: [] -keywords: [] -action: - aliases: [] - related: [] - returnType: string - signatures: [strings.Repeat COUNT INPUT] -aliases: [/functions/strings.repeat] ---- - -```go-html-template -{{ strings.Repeat 3 "yo" }} → yoyoyo -``` diff --git a/docs/content/en/functions/strings/Replace.md b/docs/content/en/functions/strings/Replace.md deleted file mode 100644 index 9add6e12b..000000000 --- a/docs/content/en/functions/strings/Replace.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: strings.Replace -description: Returns a copy of INPUT, replacing all occurrences of OLD with NEW. -categories: [] -keywords: [] -action: - aliases: [replace] - related: - - functions/strings/FindRE - - functions/strings/FindRESubmatch - - functions/strings/ReplaceRE - returnType: string - signatures: ['strings.Replace INPUT OLD NEW [LIMIT]'] -aliases: [/functions/replace] ---- - -```go-html-template -{{ $s := "Batman and Robin" }} -{{ replace $s "Robin" "Catwoman" }} → Batman and Catwoman -``` - -Limit the number of replacements using the `LIMIT` argument: - -```go-html-template -{{ replace "aabbaabb" "a" "z" 2 }} → zzbbaabb -``` diff --git a/docs/content/en/functions/strings/ReplaceRE.md b/docs/content/en/functions/strings/ReplaceRE.md deleted file mode 100644 index 1c32c34fb..000000000 --- a/docs/content/en/functions/strings/ReplaceRE.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: strings.ReplaceRE -description: Returns a copy of INPUT, replacing all occurrences of a regular expression with a replacement pattern. -categories: [] -keywords: [] -action: - aliases: [replaceRE] - related: - - functions/strings/FindRE - - functions/strings/FindRESubmatch - - functions/strings/Replace - returnType: string - signatures: ['strings.ReplaceRE PATTERN REPLACEMENT INPUT [LIMIT]'] -aliases: [/functions/replacere] ---- - -{{% include "functions/_common/regular-expressions.md" %}} - -```go-html-template -{{ $s := "a-b--c---d" }} -{{ replaceRE `(-{2,})` "-" $s }} → a-b-c-d -``` - -Limit the number of replacements using the LIMIT argument: - -```go-html-template -{{ $s := "a-b--c---d" }} -{{ replaceRE `(-{2,})` "-" $s 1 }} → a-b-c---d -``` - -Use `$1`, `$2`, etc. within the replacement string to insert the content of each capturing group within the regular expression: - -```go-html-template -{{ $s := "http://gohugo.io/docs" }} -{{ replaceRE "^https?://([^/]+).*" "$1" $s }} → gohugo.io -``` - -{{% note %}} -You can write and test your regular expression using [regex101.com](https://regex101.com/). Be sure to select the Go flavor before you begin. -{{% /note %}} - -[RE2]: https://github.com/google/re2/wiki/Syntax -[string literal]: https://go.dev/ref/spec#String_literals diff --git a/docs/content/en/functions/strings/RuneCount.md b/docs/content/en/functions/strings/RuneCount.md deleted file mode 100644 index 46fedf01f..000000000 --- a/docs/content/en/functions/strings/RuneCount.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: strings.RuneCount -description: Returns the number of runes in the given string. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/go-template/len - - functions/strings/Count - - functions/strings/CountRunes - - functions/strings/CountWords - returnType: int - signatures: [strings.RuneCount INPUT] -aliases: [/functions/strings.runecount] ---- - -In contrast with the [`strings.CountRunes`] function, which excludes whitespace, `strings.RuneCount` counts every rune in a string. - -```go-html-template -{{ "Hello, 世界" | strings.RuneCount }} → 9 -``` - -[`strings.CountRunes`]: /functions/strings/countrunes diff --git a/docs/content/en/functions/strings/SliceString.md b/docs/content/en/functions/strings/SliceString.md deleted file mode 100644 index 2f33f8f65..000000000 --- a/docs/content/en/functions/strings/SliceString.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: strings.SliceString -description: Creates a slice of a half-open range, including start and end indices. -categories: [] -keywords: [] -action: - aliases: [slicestr] - related: [] - returnType: string - signatures: ['strings.SliceString STRING START [END]'] -aliases: [/functions/slicestr] ---- - -For example, 1 and 4 creates a slice including elements 1 through 3. -The `end` index can be omitted; it defaults to the string's length. - -```go-html-template -{{ slicestr "BatMan" 3 }}` → Man -{{ slicestr "BatMan" 0 3 }}` → Bat -``` diff --git a/docs/content/en/functions/strings/Split.md b/docs/content/en/functions/strings/Split.md deleted file mode 100644 index a9973ea63..000000000 --- a/docs/content/en/functions/strings/Split.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: strings.Split -description: Returns a slice of strings by splitting the given string by a delimiter. -categories: [] -keywords: [] -action: - aliases: [split] - related: - - functions/collections/Delimit - returnType: string - signatures: [strings.Split STRING DELIM] -aliases: [/functions/split] ---- - -Examples: - -```go-html-template -{{ split "tag1,tag2,tag3" "," }} → ["tag1", "tag2", "tag3"] -{{ split "abc" "" }} → ["a", "b", "c"] -``` - -{{% note %}} -The `strings.Split` function essentially does the opposite of the [`collections.Delimit`] function. While `split` creates a slice from a string, `delimit` creates a string from a slice. - -[`collections.Delimit`]: /functions/collections/delimit -{{% /note %}} diff --git a/docs/content/en/functions/strings/Substr.md b/docs/content/en/functions/strings/Substr.md deleted file mode 100644 index 6c1852f58..000000000 --- a/docs/content/en/functions/strings/Substr.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -title: strings.Substr -description: Extracts parts of a string from a specified character's position and returns the specified number of characters. -categories: [] -keywords: [] -action: - aliases: [substr] - related: [] - returnType: string - signatures: ['strings.Substr STRING START [LENGTH]'] -aliases: [/functions/substr] ---- - -It normally takes two argument: `start` and `length`. It can also take one argument: `start`, i.e. `length` is omitted, in which case the substring starting from start until the end of the string will be returned. - -To extract characters from the end of the string, use a negative start number. - -If `length` is given and is negative, that number of characters will be omitted from the end of string. - -```go-html-template -{{ substr "abcdef" 0 }} → abcdef -{{ substr "abcdef" 1 }} → bcdef - -{{ substr "abcdef" 0 1 }} → a -{{ substr "abcdef" 1 1 }} → b - -{{ substr "abcdef" 0 -1 }} → abcde -{{ substr "abcdef" 1 -1 }} → bcde - -{{ substr "abcdef" -1 }} → f -{{ substr "abcdef" -2 }} → ef - -{{ substr "abcdef" -1 1 }} → f -{{ substr "abcdef" -2 1 }} → e - -{{ substr "abcdef" -3 -1 }} → de -{{ substr "abcdef" -3 -2 }} → d -``` diff --git a/docs/content/en/functions/strings/Title.md b/docs/content/en/functions/strings/Title.md deleted file mode 100644 index b7f1f9e5c..000000000 --- a/docs/content/en/functions/strings/Title.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: strings.Title -description: Returns the given string, converting it to title case. -categories: [] -keywords: [] -action: - aliases: [title] - related: - - functions/strings/FirstUpper - - functions/strings/ToLower - - functions/strings/ToUpper - returnType: string - signatures: [strings.Title STRING] -aliases: [/functions/title] ---- - -```go-html-template -{{ title "table of contents (TOC)" }} → Table of Contents (TOC) -``` - -By default, Hugo follows the capitalization rules published in the [Associated Press Stylebook]. Change your [site configuration] if you would prefer to: - -- Follow the capitalization rules published in the [Chicago Manual of Style] -- Capitalize the first letter of every word -- Capitalize the first letter of the first word -- Disable the effects of the `title` function - -The last option is useful if your theme uses the `title` function, and you would prefer to manually capitalize strings as needed. - -[Associated Press Stylebook]: https://www.apstylebook.com/ -[Chicago Manual of Style]: https://www.chicagomanualofstyle.org/home.html -[site configuration]: /getting-started/configuration/#configure-title-case diff --git a/docs/content/en/functions/strings/ToLower.md b/docs/content/en/functions/strings/ToLower.md deleted file mode 100644 index 3da047ae4..000000000 --- a/docs/content/en/functions/strings/ToLower.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: strings.ToLower -description: Returns the given string, converting all characters to lowercase. -categories: [] -keywords: [] -action: - aliases: [lower] - related: - - functions/strings/FirstUpper - - functions/strings/Title - - functions/strings/ToUpper - returnType: string - signatures: [strings.ToLower INPUT] -aliases: [/functions/lower] ---- - -```go-html-template -{{ lower "BatMan" }} → batman -``` diff --git a/docs/content/en/functions/strings/ToUpper.md b/docs/content/en/functions/strings/ToUpper.md deleted file mode 100644 index 617e1e68a..000000000 --- a/docs/content/en/functions/strings/ToUpper.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: strings.ToUpper -description: Returns the given string, converting all characters to uppercase. -categories: [] -keywords: [] -action: - aliases: [upper] - related: - - functions/strings/FirstUpper - - functions/strings/Title - - functions/strings/ToLower - returnType: string - signatures: [strings.ToUpper INPUT] -aliases: [/functions/upper] ---- - -```go-html-template -{{ upper "BatMan" }} → BATMAN -``` diff --git a/docs/content/en/functions/strings/Trim.md b/docs/content/en/functions/strings/Trim.md deleted file mode 100644 index 6dfac024b..000000000 --- a/docs/content/en/functions/strings/Trim.md +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: strings.Trim -description: Returns the given string, removing leading and trailing characters specified in the cutset. -categories: [] -keywords: [] -action: - aliases: [trim] - related: - - functions/strings/Chomp - - functions/strings/TrimLeft - - functions/strings/TrimPrefix - - functions/strings/TrimRight - - functions/strings/TrimSuffix - returnType: string - signatures: [strings.Trim INPUT CUTSET] -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" }} -``` diff --git a/docs/content/en/functions/strings/TrimLeft.md b/docs/content/en/functions/strings/TrimLeft.md deleted file mode 100644 index 07cdf0064..000000000 --- a/docs/content/en/functions/strings/TrimLeft.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: strings.TrimLeft -description: Returns the given string, removing leading characters specified in the cutset. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Chomp - - functions/strings/Trim - - functions/strings/TrimPrefix - - functions/strings/TrimRight - - functions/strings/TrimSuffix - returnType: string - signatures: [strings.TrimLeft CUTSET STRING] -aliases: [/functions/strings.trimleft] ---- - -```go-html-template -{{ strings.TrimLeft "a" "abba" }} → bba -``` - -The `strings.TrimLeft` function converts the arguments to strings if possible: - -```go-html-template -{{ strings.TrimLeft 21 12345 }} → 345 (string) -{{ strings.TrimLeft "rt" true }} → ue -``` diff --git a/docs/content/en/functions/strings/TrimPrefix.md b/docs/content/en/functions/strings/TrimPrefix.md deleted file mode 100644 index 917cf06f5..000000000 --- a/docs/content/en/functions/strings/TrimPrefix.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: strings.TrimPrefix -description: Returns the given string, removing the prefix from the beginning of the string. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Chomp - - functions/strings/Trim - - functions/strings/TrimLeft - - functions/strings/TrimRight - - functions/strings/TrimSuffix - returnType: string - signatures: [strings.TrimPrefix PREFIX STRING] -aliases: [/functions/strings.trimprefix] ---- - -```go-html-template -{{ strings.TrimPrefix "a" "aabbaa" }} → abbaa -{{ strings.TrimPrefix "aa" "aabbaa" }} → bbaa -{{ strings.TrimPrefix "aaa" "aabbaa" }} → aabbaa -``` diff --git a/docs/content/en/functions/strings/TrimRight.md b/docs/content/en/functions/strings/TrimRight.md deleted file mode 100644 index b244925ef..000000000 --- a/docs/content/en/functions/strings/TrimRight.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: strings.TrimRight -description: Returns the given string, removing trailing characters specified in the cutset. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Chomp - - functions/strings/Trim - - functions/strings/TrimLeft - - functions/strings/TrimPrefix - - functions/strings/TrimSuffix - returnType: string - signatures: [strings.TrimRight CUTSET STRING] -aliases: [/functions/strings.trimright] ---- - -```go-html-template -{{ strings.TrimRight "a" "abba" }} → abb -``` - -The `strings.TrimRight` function converts the arguments to strings if possible: - -```go-html-template -{{ strings.TrimRight 54 12345 }} → 123 (string) -{{ strings.TrimRight "eu" true }} → tr -``` diff --git a/docs/content/en/functions/strings/TrimSuffix.md b/docs/content/en/functions/strings/TrimSuffix.md deleted file mode 100644 index 704bbd2d2..000000000 --- a/docs/content/en/functions/strings/TrimSuffix.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: strings.TrimSuffix -description: Returns the given string, removing the suffix from the end of the string. -categories: [] -keywords: [] -action: - aliases: [] - related: - - functions/strings/Chomp - - functions/strings/Trim - - functions/strings/TrimLeft - - functions/strings/TrimPrefix - - functions/strings/TrimRight - returnType: string - signatures: [strings.TrimSuffix SUFFIX STRING] -aliases: [/functions/strings.trimsuffix] ---- - -```go-html-template -{{ strings.TrimSuffix "a" "aabbaa" }} → aabba -{{ strings.TrimSuffix "aa" "aabbaa" }} → aabb -{{ strings.TrimSuffix "aaa" "aabbaa" }} → aabbaa -``` diff --git a/docs/content/en/functions/strings/Truncate.md b/docs/content/en/functions/strings/Truncate.md deleted file mode 100644 index 17ae0afc6..000000000 --- a/docs/content/en/functions/strings/Truncate.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: strings.Truncate -description: Returns the given string, truncating it to a maximum length without cutting words or leaving unclosed HTML tags. -categories: [] -keywords: [] -action: - aliases: [truncate] - related: [] - returnType: template.HTML - signatures: ['strings.Truncate SIZE [ELLIPSIS] INPUT'] -aliases: [/functions/truncate] ---- - -Since Go templates are HTML-aware, `truncate` will intelligently handle normal strings vs HTML strings: - -```go-html-template -{{ "<em>Keep my HTML</em>" | safeHTML | truncate 10 }} → <em>Keep my …</em> -``` - -{{% note %}} -If you have a raw string that contains HTML tags you want to remain treated as HTML, you will need to convert the string to HTML using the [`safeHTML`]function before sending the value to `truncate`. Otherwise, the HTML tags will be escaped when passed through the `truncate` function. - -[`safeHTML`]: /functions/safe/html -{{% /note %}} diff --git a/docs/content/en/functions/strings/_index.md b/docs/content/en/functions/strings/_index.md deleted file mode 100644 index 364522a3a..000000000 --- a/docs/content/en/functions/strings/_index.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: String functions -linkTitle: strings -description: Template functions to work with strings. -categories: [] -keywords: [] -menu: - docs: - parent: functions ---- - -Use these functions to work with strings. |