Skip to content

Commit e7e4de3

Browse files
dipesh-rawatTim Bannisterbradtopol
authored
Added info for <codenew> shortcode in style guide (#39764)
* Add info for codenew shortcode in style guide Signed-off-by: Dipesh Rawat <[email protected]> * Update content/en/docs/contribute/style/style-guide.md Co-authored-by: Tim Bannister <[email protected]> * Addressed feedback comments Signed-off-by: Dipesh Rawat <[email protected]> * Update content/en/docs/contribute/style/hugo-shortcodes/index.md Co-authored-by: Brad Topol <[email protected]> * Update content/en/docs/contribute/style/hugo-shortcodes/index.md Co-authored-by: Brad Topol <[email protected]> --------- Signed-off-by: Dipesh Rawat <[email protected]> Co-authored-by: Tim Bannister <[email protected]> Co-authored-by: Brad Topol <[email protected]>
1 parent 5087c55 commit e7e4de3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

content/en/docs/contribute/style/hugo-shortcodes/index.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,33 @@ Renders to:
271271
{{< tab name="JSON File" include="podtemplate.json" />}}
272272
{{< /tabs >}}
273273

274+
### Source code files
275+
276+
You can use the `{{</* codenew */>}}` shortcode to embed the contents of file in a code block to allow users to download or copy its content to their clipboard. This shortcode is used when the contents of the sample file is generic and reusable, and you want the users to try it out themselves.
277+
278+
This shortcode takes in two named parameters: `language` and `file`. The mandatory parameter `file` is used to specify the path to the file being displayed. The optional parameter `language` is used to specify the programming language of the file. If the `language` parameter is not provided, the shortcode will attempt to guess the language based on the file extension.
279+
280+
For example:
281+
282+
```none
283+
{{</* codenew language="yaml" file="application/deployment-scale.yaml" */>}}
284+
```
285+
286+
The output is:
287+
288+
{{< codenew language="yaml" file="application/deployment-scale.yaml" >}}
289+
290+
When adding a new sample file, such as a YAML file, create the file in one of the `<LANG>/examples/` subdirectories where `<LANG>` is the language for the page. In the markdown of your page, use the `codenew` shortcode:
291+
292+
```none
293+
{{</* codenew file="<RELATIVE-PATH>/example-yaml>" */>}}
294+
```
295+
where `<RELATIVE-PATH>` is the path to the sample file to include, relative to the `examples` directory. The following shortcode references a YAML file located at `/content/en/examples/configmap/configmaps.yaml`.
296+
297+
```none
298+
{{</* codenew file="configmap/configmaps.yaml" */>}}
299+
```
300+
274301
## Third party content marker
275302

276303
Running Kubernetes requires third-party software. For example: you

content/en/docs/contribute/style/style-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,4 +631,5 @@ These steps ... | These simple steps ...
631631

632632
* Learn about [writing a new topic](/docs/contribute/style/write-new-topic/).
633633
* Learn about [using page templates](/docs/contribute/style/page-content-types/).
634+
* Learn about [custom hugo shortcodes](/docs/contribute/style/hugo-shortcodes/).
634635
* Learn about [creating a pull request](/docs/contribute/new-content/open-a-pr/).

0 commit comments

Comments
 (0)