From e7e4de3a0fdb154ee446999040b6fc31085ac533 Mon Sep 17 00:00:00 2001 From: Dipesh Rawat Date: Wed, 8 Mar 2023 13:37:12 +0000 Subject: [PATCH] Added info for shortcode in style guide (#39764) * Add info for codenew shortcode in style guide Signed-off-by: Dipesh Rawat * Update content/en/docs/contribute/style/style-guide.md Co-authored-by: Tim Bannister * Addressed feedback comments Signed-off-by: Dipesh Rawat * Update content/en/docs/contribute/style/hugo-shortcodes/index.md Co-authored-by: Brad Topol * Update content/en/docs/contribute/style/hugo-shortcodes/index.md Co-authored-by: Brad Topol --------- Signed-off-by: Dipesh Rawat Co-authored-by: Tim Bannister Co-authored-by: Brad Topol --- .../contribute/style/hugo-shortcodes/index.md | 27 +++++++++++++++++++ .../en/docs/contribute/style/style-guide.md | 1 + 2 files changed, 28 insertions(+) diff --git a/content/en/docs/contribute/style/hugo-shortcodes/index.md b/content/en/docs/contribute/style/hugo-shortcodes/index.md index 2d751f73f3..a6ba992ee7 100644 --- a/content/en/docs/contribute/style/hugo-shortcodes/index.md +++ b/content/en/docs/contribute/style/hugo-shortcodes/index.md @@ -271,6 +271,33 @@ Renders to: {{< tab name="JSON File" include="podtemplate.json" />}} {{< /tabs >}} +### Source code files + +You can use the `{{}}` 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. + +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. + +For example: + +```none +{{}} +``` + +The output is: + +{{< codenew language="yaml" file="application/deployment-scale.yaml" >}} + +When adding a new sample file, such as a YAML file, create the file in one of the `/examples/` subdirectories where `` is the language for the page. In the markdown of your page, use the `codenew` shortcode: + +```none +{{/example-yaml>" */>}} +``` +where `` 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`. + +```none +{{}} +``` + ## Third party content marker Running Kubernetes requires third-party software. For example: you diff --git a/content/en/docs/contribute/style/style-guide.md b/content/en/docs/contribute/style/style-guide.md index dce6eb291f..c7f020a5fc 100644 --- a/content/en/docs/contribute/style/style-guide.md +++ b/content/en/docs/contribute/style/style-guide.md @@ -631,4 +631,5 @@ These steps ... | These simple steps ... * Learn about [writing a new topic](/docs/contribute/style/write-new-topic/). * Learn about [using page templates](/docs/contribute/style/page-content-types/). +* Learn about [custom hugo shortcodes](/docs/contribute/style/hugo-shortcodes/). * Learn about [creating a pull request](/docs/contribute/new-content/open-a-pr/).