Refactor example shortcode

This commit is contained in:
mark
2023-12-27 16:44:57 +01:00
parent 7a4c364b49
commit 836cd21df2
2 changed files with 48 additions and 9 deletions

View File

@@ -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.

View File

@@ -1,16 +1,27 @@
<!--
Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
This source code adapts the original embedded shortcode as maintained by the The Bootstrap Authors. It introduces
the following modifications:
- Added validation of shortcode arguments
- Modified the layout
The original source code is available on:
Source: https://github.com/twbs/bootstrap/blob/main/site/layouts/shortcodes/example.html
Display a code example and render a preview of the same input. The shortcode accepts the languages supported by
Hugo's highlight function. The shortcode supports the following named arguments:
"id" Optional identifier of the element's container.
"lang" Language used to display the code, default value is "markdown".
"show_markup" If the markup should be output in the HTML, defaults to "true".
"show_preview" If the preview should be output in the HTML, defaults to "true".
"class" Optional class attributes of the element's container.
Copyright (c) 2011-2023 The Bootstrap Authors. Licensed under The MIT License (MIT).
-->
{{ $error := false -}}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "example" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
<!-- Initialize arguments -->
{{- $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 -}}
<!-- Main code -->
<div class="rounded border mb-3">
{{- if eq $show_preview true -}}
<div {{ with $id }}id="{{ . }}"{{ end }} class="rounded-top p-3 {{ with $class }} {{ . }}{{ end }}">