Docs
Example
Overview
The example shortcode displays a code example and renders a preview of the same input. The shortcode accepts the languages supported by Hugo’s
highlight function
.
Hugo code example
Set the lang argument to hugo to render a Hugo code example. Be sure to escape the input with /* and */ delimiters to avoid rendering issues.
Preview
export MY_VAR=123{{< command >}}
export MY_VAR=123
{{< /command >}}Input
{{< example lang="hugo" >}}
{{</* command */>}}
export MY_VAR=123
{{</* /command */>}}
{{< /example >}}Hidden markup
Set show-markup to false to hide the code input and to display the preview only.
Preview
This is a lead paragraph. It stands out from regular paragraphs.
Input
{{< example show-markup=false >}}
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}
{{< /example >}}Hidden preview
Set show-preview to false to hide the output and to display the code input only.
Preview
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}Input
{{< example show-preview=false >}}
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}
{{< /example >}}Resizable preview
Set resize to true to add a grip to the lower-right corner of the preview. Drag it to narrow the preview and observe how the component reflows.
Important
The grip demonstrates fluid reflow — content wrapping, text truncation, tables gaining a scrollbar, images scaling. It does not trigger responsive breakpoints. Bootstrap 5’s responsive classes (
navbar-expand-*,col-md-*, and similar) are viewport media queries, so they respond to the size of the browser window, not the size of the preview. To preview breakpoint behavior, resize the browser window instead.
Preview
This is a lead paragraph. It stands out from regular paragraphs.
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}Input
{{< example resize="true" >}}
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}
{{< /example >}}Arguments
The shortcode supports the following arguments:
| Name | Type | Required | Default | Comment |
|---|---|---|---|---|
| class | string | Class attributes of the element. It supports Bootstrap attributes to modify the styling of the element. | ||
| Class attributes of the element. It supports Bootstrap attributes to modify the styling of the element. | ||||
| id | string | Unique identifier of the current element. | ||
| Unique identifier of the current element. | ||||
| lang | string | markdown |
Language to be used by the syntax highlighter. For files, the language is derived from the file extension when no language is specified. When rendering code examples with the example shortcode, use hugo to process Hugo (escaped) shortcodes and bookshop to render a Bookshop component using inline YAML data. |
|
Language to be used by the syntax highlighter. For files, the language is derived from the file extension when no language is specified. When rendering code examples with the example shortcode, use hugo to process Hugo (escaped) shortcodes and bookshop to render a Bookshop component using inline YAML data. |
||||
| resize | bool |
v3.2.0
Adds a grip to the lower-right corner of the preview, allowing the reader to resize the preview horizontally. Requires show-preview to be enabled. |
||
v3.2.0
Adds a grip to the lower-right corner of the preview, allowing the reader to resize the preview horizontally. Requires show-preview to be enabled. |
||||
| show-markup | bool | true |
v1.0.0 Indicates if the markup should be output in the HTML. | |
| v1.0.0 Indicates if the markup should be output in the HTML. | ||||
| show-preview | bool | true |
v1.0.0 Indicates if the preview should be output in the HTML. | |
| v1.0.0 Indicates if the preview should be output in the HTML. | ||||
| show_markup | bool |
v1.0.0
Use show-markup instead. Indicates if the markup should be output in the HTML. |
||
v1.0.0
Use show-markup instead. Indicates if the markup should be output in the HTML. |
||||
| show_preview | bool |
v1.0.0
Use show-preview instead. Indicates if the preview should be output in the HTML. |
||
v1.0.0
Use show-preview instead. Indicates if the preview should be output in the HTML. |
||||