diff --git a/data/structures/example.yml b/data/structures/example.yml new file mode 100644 index 00000000..69253dfe --- /dev/null +++ b/data/structures/example.yml @@ -0,0 +1,27 @@ +comment: >- + Display a code example and render a preview of the same input. The shortcode + accepts the languages supported by Hugo's highlight function. +arguments: + lang: + type: string + optional: true + default: markdown + comment: Language used to display the code. + show_markup: + type: bool + optional: true + default: true + comment: Indicates if the markup should be output in the HTML. + show_preview: + type: bool + optional: true + default: true + comment: Indicates if the preview should be output in the HTML. + class: + type: string + optional: true + comment: Class attributes of the element's container. +body: + type: string + optional: false + comment: The example input. diff --git a/layouts/shortcodes/example.html b/layouts/shortcodes/example.html index ff9c92a9..6441c06e 100644 --- a/layouts/shortcodes/example.html +++ b/layouts/shortcodes/example.html @@ -1,16 +1,27 @@ +{{ $error := false -}} + + +{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "example" "args" .Params) }} + {{ errorf "Invalid arguments: %s" .Position -}} + {{ $error = true }} +{{ end }} + + {{- $id := .Get "id" | default "" -}} {{- $class := .Get "class" | default "" -}} {{- $lang := .Get "lang" | default "markdown" -}} @@ -19,6 +30,7 @@ {{- $content := .InnerDeindent -}} {{- if eq $lang "hugo" }}{{ $lang = "markdown" }}{{ end -}} +