mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-01 08:00:05 +03:00
Merge commit '8b9803425e
'
This commit is contained in:
commit
af0cb57aaf
475 changed files with 7408 additions and 4720 deletions
|
@ -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's White Space property.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
|
@ -24,7 +24,7 @@ aliases: [/functions/strings.containsnonspace]
|
|||
{{ strings.ContainsNonSpace "\n abc" }} → true
|
||||
```
|
||||
|
||||
Common white space characters include:
|
||||
Common whitespace characters include:
|
||||
|
||||
```text
|
||||
'\t', '\n', '\v', '\f', '\r', ' '
|
||||
|
|
|
@ -21,4 +21,4 @@ In contrast with the [`strings.RuneCount`] function, which counts every rune in
|
|||
{{ "Hello, 世界" | strings.CountRunes }} → 8
|
||||
```
|
||||
|
||||
[`strings.RuneCount`]: /functions/strings/runecount
|
||||
[`strings.RuneCount`]: /functions/strings/runecount/
|
||||
|
|
BIN
docs/content/en/functions/strings/Diff/diff-screen-capture.png
Normal file
BIN
docs/content/en/functions/strings/Diff/diff-screen-capture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
33
docs/content/en/functions/strings/Diff/index.md
Normal file
33
docs/content/en/functions/strings/Diff/index.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: strings.Diff
|
||||
description: Returns an anchored diff of the two texts OLD and NEW in the unified diff format. If OLD and NEW are identical, returns an empty string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: [strings.Diff OLDNAME OLD NEWNAME NEW]
|
||||
---
|
||||
|
||||
{{< new-in 0.125.0 >}}
|
||||
|
||||
Use `strings.Diff` to compare two strings and render a highlighted diff:
|
||||
|
||||
```go-html-template
|
||||
{{ $want := `
|
||||
<p>The product of 6 and 7 is 42.</p>
|
||||
<p>The product of 7 and 6 is 42.</p>
|
||||
`}}
|
||||
|
||||
{{ $got := `
|
||||
<p>The product of 6 and 7 is 42.</p>
|
||||
<p>The product of 7 and 6 is 13.</p>
|
||||
`}}
|
||||
|
||||
{{ $diff := strings.Diff "want" $want "got" $got }}
|
||||
{{ transform.Highlight $diff "diff" }}
|
||||
```
|
||||
|
||||
Rendered:
|
||||
|
||||

|
|
@ -30,7 +30,7 @@ By default, `findRESubmatch` finds all matches. You can limit the number of matc
|
|||
|
||||
## Practical example
|
||||
|
||||
This markdown:
|
||||
This Markdown:
|
||||
|
||||
```text
|
||||
- [Example](https://example.org)
|
||||
|
|
|
@ -21,4 +21,4 @@ In contrast with the [`strings.CountRunes`] function, which excludes whitespace,
|
|||
{{ "Hello, 世界" | strings.RuneCount }} → 9
|
||||
```
|
||||
|
||||
[`strings.CountRunes`]: /functions/strings/countrunes
|
||||
[`strings.CountRunes`]: /functions/strings/countrunes/
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
---
|
||||
title: strings.SliceString
|
||||
description: Creates a slice of a half-open range, including start and end indices.
|
||||
description: Returns a substring of the given string, beginning with the start position and ending before the end position.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [slicestr]
|
||||
related: []
|
||||
related:
|
||||
- functions/strings/Substr
|
||||
returnType: string
|
||||
signatures: ['strings.SliceString STRING START [END]']
|
||||
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.
|
||||
The START and END positions are zero-based, where `0` represents the first character of the string. If START is not specified, the substring will begin at position `0`. If END is not specified, the substring will end after the last character.
|
||||
|
||||
```go-html-template
|
||||
{{ slicestr "BatMan" 3 }}` → Man
|
||||
{{ slicestr "BatMan" 0 3 }}` → Bat
|
||||
{{ slicestr "BatMan" }} → BatMan
|
||||
{{ slicestr "BatMan" 3 }} → Man
|
||||
{{ slicestr "BatMan" 0 3 }} → Bat
|
||||
```
|
||||
|
||||
The START and END arguments represent the endpoints of a [half-open interval], a concept that may be difficult to grasp when first encountered. You may find that the [`strings.Substr`] function is easier to understand.
|
||||
|
||||
[half-open interval]: /getting-started/glossary/#interval
|
||||
[`strings.Substr`]: /functions/strings/substr/
|
||||
|
|
|
@ -22,5 +22,5 @@ Examples:
|
|||
{{% 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
|
||||
[`collections.Delimit`]: /functions/collections/delimit/
|
||||
{{% /note %}}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
---
|
||||
title: strings.Substr
|
||||
description: Extracts parts of a string from a specified character's position and returns the specified number of characters.
|
||||
description: Returns a substring of the given string, beginning with the start position and ending after the given length.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [substr]
|
||||
related: []
|
||||
related:
|
||||
- functions/strings/SliceString
|
||||
returnType: string
|
||||
signatures: ['strings.Substr STRING START [LENGTH]']
|
||||
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.
|
||||
The start position is zero-based, where `0` represents the first character of the string. If START is not specified, the substring will begin at position `0`. Specify a negative START position to extract characters from the end of the string.
|
||||
|
||||
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.
|
||||
If LENGTH is not specified, the substring will include all characters from the START position to the end of the string. If negative, that number of characters will be omitted from the end of string.
|
||||
|
||||
```go-html-template
|
||||
{{ substr "abcdef" 0 }} → abcdef
|
||||
|
|
|
@ -32,7 +32,7 @@ To remove leading and trailing newline characters and carriage returns:
|
|||
|
||||
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:
|
||||
For example, with this Markdown:
|
||||
|
||||
```text
|
||||
{{</* my-shortcode */>}}
|
||||
|
|
|
@ -20,5 +20,5 @@ Since Go templates are HTML-aware, `truncate` will intelligently handle normal s
|
|||
{{% 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
|
||||
[`safeHTML`]: /functions/safe/html/
|
||||
{{% /note %}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue