Add code fence types (#2038)

* Add code fence types

* Revert back to html
This commit is contained in:
Will Faught 2023-03-31 21:05:20 -07:00 committed by GitHub
parent 856fa293c8
commit 928b945054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 56 additions and 56 deletions

View File

@ -19,7 +19,7 @@ aliases: []
The following shows `after` being used in conjunction with the [`slice` function][slice]:
```
```go-html-template
{{ $data := slice "one" "two" "three" "four" }}
{{ range after 2 $data }}
{{ . }}

View File

@ -37,7 +37,7 @@ names: [ "Derek Perkins", "Joe Bergevin", "Tanner Linsley" ]
You can then use `apply` as follows:
```
```go-html-template
{{ apply .Params.names "urlize" "." }}
```
@ -49,7 +49,7 @@ Which will result in the following:
This is *roughly* equivalent to using the following with [range]:
```
```go-html-template
{{ range .Params.names }}{{ . | urlize }}{{ end }}
```
@ -83,7 +83,7 @@ This works, but the complexity of `post-tag-list.html` is fairly high. The Hugo
This first version of `layouts/partials/post-tag-list.html` separates all of the operations for ease of reading. The combined and DRYer version is shown next:
```
```go-html-template
{{ with .Params.tags }}
<div class="tags-list">
Tags:

View File

@ -42,7 +42,7 @@ You can also pass other data types as arguments to the template function which t
Using base64 to decode and encode becomes really powerful if we have to handle
responses from APIs.
```
```go-html-template
{{ $resp := getJSON "https://api.github.com/repos/gohugoio/hugo/readme" }}
{{ $resp.content | base64Decode | markdownify }}
```

View File

@ -21,6 +21,6 @@ deprecated: false
Useful in a pipeline to remove newlines added by other processing (e.g., [`markdownify`](/functions/markdownify/)).
```
```go-html-template
{{ chomp "<p>Blockhead</p>\n"}} → "<p>Blockhead</p>"
```

View File

@ -17,7 +17,7 @@ draft: false
Example:
```
```go-html-template
{{ cond (eq (len $geese) 1) "goose" "geese" }}
```

View File

@ -20,7 +20,7 @@ deprecated: false
In contrast with `countwords` function, which counts every word in a string, the `countrunes` function determines the number of runes in the content and excludes any whitespace. This has specific utility if you are dealing with CJK-like languages.
```
```go-html-template
{{ "Hello, 世界" | countrunes }}
<!-- outputs a content length of 8 runes. -->
```

View File

@ -18,7 +18,7 @@ deprecated: false
The template function works similar to the [.WordCount page variable][pagevars].
```
```go-html-template
{{ "Hugo is a static site generator." | countwords }}
<!-- outputs a content length of 6 words. -->
```

View File

@ -42,7 +42,7 @@ newparam:
`default` can be written in more than one way:
```
```go-html-template
{{ index .Params "font" | default "Roboto" }}
{{ default "Roboto" (index .Params "font") }}
```
@ -58,7 +58,7 @@ A `default` value, however, does not need to be hard coded like the previous exa
Which would return:
```
```html
<p>The default function helps make your templating DRYer.</p>
```

View File

@ -21,7 +21,7 @@ aliases: []
`delimit` called in your template takes the form of
```
```go-html-template
{{ delimit array/slice/map delimiter optionallastdelimiter }}
```

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ echoParam .Params "project_url" }}
```

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ if eq .Section "blog" }}current{{ end }}
```

View File

@ -22,11 +22,11 @@ Any ERROR will also cause the build to fail (the `hugo` command will `exit -1`).
Both functions return an empty string, so the messages are only printed to the console.
```
```go-html-template
{{ errorf "Failed to handle page %q" .Path }}
```
```
```go-html-template
{{ warnf "You should update the shortcodes in %q" .Path }}
```
@ -38,7 +38,7 @@ Sometimes it may make sense to let the user suppress an ERROR and make the build
You can do this by using the `erroridf` function. This functions takes an error ID as the first argument.
```
```go-html-template
{{ erroridf "my-custom-error" "You should consider fixing this." }}
```

View File

@ -97,7 +97,7 @@ Spelled-out cardinal numbers (e.g. "one", "two", and "three") are not currently
Use the [`humanize`](/functions/humanize) function to render the day of the month as an ordinal number:
```
```go-html-template
{{ humanize .Date.Day }} of {{ .Date.Format "January 2006" }}
```

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ if ge 10 5 }}true{{ end }}
```

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ if gt 10 5 }}true{{ end }}
```

View File

@ -23,7 +23,7 @@ aliases: []
This translates a piece of content based on your `i18n/en-US.toml` files. You can use the [go-i18n](https://github.com/nicksnyder/go-i18n) tools to manage your translations. The translations can exist in both the theme and at the root of your repository.
```
```go-html-template
{{ i18n "translation_id" }}
```
@ -35,7 +35,7 @@ This translates a piece of content based on your `i18n/en-US.toml` files. You ca
Often you will want to use the page variables in the translation strings. To do so, pass the `.` context when calling `i18n`:
```
```go-html-template
{{ i18n "wordCount" . }}
```

View File

@ -22,11 +22,11 @@ The elements supported are strings, integers and floats, although only float64 w
In addition, `in` can also check if a substring exists in a string.
```
```go-html-template
{{ if in .Params.tags "Git" }}Follow me on GitHub!{{ end }}
```
```
```go-html-template
{{ if in "this string contains a substring" "substring" }}Substring found!{{ end }}
```

View File

@ -69,7 +69,7 @@ pop_metro = 1717900
The example we will use will be an article on Oslo, whose front matter should be set to exactly the same name as the corresponding file name in `data/locations/`:
```
```toml
title = "My Norwegian Vacation"
location = "oslo"
```
@ -81,8 +81,8 @@ This is where the `index` function is needed. `index` takes 2 parameters in this
1. The node path
2. A string corresponding to the desired data; e.g.&mdash;
```
{{ index .Site.Data.locations “oslo” }}
```go-html-template
{{ index .Site.Data.locations "oslo" }}
```
The variable for `.Params.location` is a string and can therefore replace `oslo` in the example above:

View File

@ -32,7 +32,7 @@ number representation.
The `strings.TrimLeft` can be used for this purpose.
```
```go-html-template
{{ int ("0987" | strings.TrimLeft "0") }}
{{ int ("00987" | strings.TrimLeft "0") }}
```

View File

@ -21,7 +21,7 @@ A useful example is to use it as `AND` filters when combined with where:
## AND filter in where query
```
```go-html-template
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
{{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
{{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}

View File

@ -20,7 +20,7 @@ aliases: []
Takes either a slice, array, or channel and an index or a map and a key as input.
```
```go-html-template
{{ if isset .Params "project_url" }} {{ index .Params "project_url" }}{{ end }}
```

View File

@ -26,7 +26,7 @@ the output will begin on a new line beginning with *prefix* followed by one or
more copies of *indent* according to the indentation nesting.
```
```go-html-template
{{ dict "title" .Title "content" .Plain | jsonify }}
{{ dict "title" .Title "content" .Plain | jsonify (dict "indent" " ") }}
{{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }}

View File

@ -20,7 +20,7 @@ draft: false
aliases: []
---
```
```go-html-template
{{ range last 10 .Pages }}
{{ .Render "summary" }}
{{ end }}

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ if le 5 10 }}true{{ end }}
```

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ if lt 5 10 }}true{{ end }}
```

View File

@ -15,7 +15,7 @@ deprecated: false
aliases: []
---
```
```go-html-template
{{ .Title | markdownify }}
```

View File

@ -18,7 +18,7 @@ deprecated: false
aliases: []
---
```
```go-html-template
{{ md5 "Hello world, gophers!" }}
<!-- returns the string "b3029f756f98f79e7f1b7f1d1f0dd53b" -->
```

View File

@ -19,6 +19,6 @@ aliases: []
---
```
```go-html-template
{{ if ne .Section "blog" }}current{{ end }}
```

View File

@ -22,7 +22,7 @@ See [`time.Time`](https://godoc.org/time#Time).
For example, building your site on June 24, 2017, with the following templating:
```
```go-html-template
<div>
<small>&copy; {{ now.Format "2006"}}</small>
</div>
@ -30,7 +30,7 @@ For example, building your site on June 24, 2017, with the following templating:
would produce the following:
```
```html
<div>
<small>&copy; 2017</small>
</div>

View File

@ -38,7 +38,7 @@ You can also pass additional parameters to `partialCached` to create *variants*
If you need to pass additional parameters to create unique variants, you can pass as many variant parameters as you need:
```
```go-html-template
{{ partialCached "footer.html" . .Params.country .Params.province }}
```

View File

@ -19,10 +19,10 @@ deprecated: false
See [the go doc](https://golang.org/pkg/fmt/) for additional information.
```
```go-html-template
{{ i18n ( printf "combined_%s" $var ) }}
```
```
```go-html-template
{{ printf "formatted %.2f" 3.1416 }}
```

View File

@ -23,7 +23,7 @@ This function is only available when applied to a single piece of content within
This example could render a piece of content using the content view located at `/layouts/_default/summary.html`:
```
```go-html-template
{{ range .Pages }}
{{ .Render "summary"}}
{{ end }}

View File

@ -33,7 +33,7 @@ copyright = "© 2015 Jane Doe. <a href=\"https://creativecommons.org/licenses/b
However, without the `safeHTML` function, html/template assumes `.Site.Copyright` to be unsafe and therefore escapes all HTML tags and renders the whole string as plain text:
```
```html
<p>© 2015 Jane Doe. &lt;a href=&#34;https://creativecommons.org/licenses by/4.0/&#34;&gt;Some rights reserved&lt;/a&gt;.</p>
```

View File

@ -33,14 +33,14 @@ It's named and used in the model of [GNU's seq].
You can use `seq` in combination with `range` and `after`. The following will return 19 elements:
```
```go-html-template
{{ range after 1 (seq 20)}}
{{ end }}
```
However, when ranging with an index, the following may be less confusing in that `$indexStartingAt1` and `$num` will return `1,2,3 ... 20`:
```
```go-html-template
{{ range $index, $num := (seq 20) }}
$indexStartingAt1 := (add $index 1)
{{ end }}

View File

@ -20,14 +20,14 @@ aliases: [sha1, sha256]
`sha1` hashes the given input and returns its SHA1 checksum.
```
```go-html-template
{{ sha1 "Hello world, gophers!" }}
<!-- returns the string "c8b5b0e33d408246e30f53e32b8f7627a7a649d4" -->
```
`sha256` hashes the given input and returns its SHA256 checksum.
```
```go-html-template
{{ sha256 "Hello world, gophers!" }}
<!-- returns the string "6ec43b78da9669f50e4e422575c54bf87536954ccd58280219c393f2ce352b46" -->
```

View File

@ -19,7 +19,7 @@ aliases: []
In contrast with `strings.CountRunes` function, which strips HTML and whitespace before counting runes, `strings.RuneCount` simply counts all the runes in a string. It relies on the Go [`utf8.RuneCountInString`] function.
```
```go-html-template
{{ "Hello, 世界" | strings.RuneCount }}
<!-- outputs a content length of 9 runes. -->
```

View File

@ -27,7 +27,7 @@ aliases: []
Can be combined in pipes. In the following snippet, the link text is cleaned up using `humanize` to remove dashes and `title` to convert the value of `$name` to Initial Caps.
```
```go-html-template
{{ range $name, $items := .Site.Taxonomies.categories }}
<li><a href="{{ printf "%s/%s" "categories" ($name | urlize | lower) | absURL }}">{{ $name | humanize | title }} ({{ len $items }})</a></li>
{{ end }}

View File

@ -52,7 +52,7 @@ As a convenience, Hugo allows you to access XML data in the same way that you ac
To get the contents of `<title>` in the document below, you use `{{ .message.title }}`:
```
```xml
<root>
<message>
<title>Hugo rocks!</title>
@ -63,7 +63,7 @@ To get the contents of `<title>` in the document below, you use `{{ .message.tit
The following example lists the items of an RSS feed:
```
```go-html-template
{{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }}
{{ range .channel.item }}
<strong>{{ .title | plainify | htmlUnescape }}</strong><br />

View File

@ -25,13 +25,13 @@ deprecated: false
`trim` *requires* the second argument, which tells the function specifically what to remove from the first argument. There is no default value for the second argument, so **the following usage will not work**:
```
```go-html-template
{{ trim .Inner }}
```
Instead, the following example tells `trim` to remove extra new lines from the content contained in the [shortcode `.Inner` variable][shortcodevars]:
```
```go-html-template
{{ trim .Inner "\n" }}
```

View File

@ -20,7 +20,7 @@ aliases: []
Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both. The elements supported are strings, integers, and floats (only float64).
```
```go-html-template
{{ union (slice 1 2 3) (slice 3 4 5) }}
<!-- returns [1 2 3 4 5] -->
@ -38,7 +38,7 @@ Given two arrays (or slices) A and B, this function will return a new array that
This is also very useful to use as `OR` filters when combined with where:
```
```go-html-template
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
{{ $pages = $pages | union (where .Site.RegularPages "Params.pinned" true) }}
{{ $pages = $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}