mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-19 07:53:10 +00:00
Refactor example shortcode
This commit is contained in:
27
data/structures/example.yml
Normal file
27
data/structures/example.yml
Normal 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.
|
@@ -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
|
Source: https://github.com/twbs/bootstrap/blob/main/site/layouts/shortcodes/example.html
|
||||||
|
Copyright (c) 2011-2023 The Bootstrap Authors. Licensed under The MIT License (MIT).
|
||||||
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.
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
{{ $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 "" -}}
|
{{- $id := .Get "id" | default "" -}}
|
||||||
{{- $class := .Get "class" | default "" -}}
|
{{- $class := .Get "class" | default "" -}}
|
||||||
{{- $lang := .Get "lang" | default "markdown" -}}
|
{{- $lang := .Get "lang" | default "markdown" -}}
|
||||||
@@ -19,6 +30,7 @@
|
|||||||
{{- $content := .InnerDeindent -}}
|
{{- $content := .InnerDeindent -}}
|
||||||
{{- if eq $lang "hugo" }}{{ $lang = "markdown" }}{{ end -}}
|
{{- if eq $lang "hugo" }}{{ $lang = "markdown" }}{{ end -}}
|
||||||
|
|
||||||
|
<!-- Main code -->
|
||||||
<div class="rounded border mb-3">
|
<div class="rounded border mb-3">
|
||||||
{{- if eq $show_preview true -}}
|
{{- if eq $show_preview true -}}
|
||||||
<div {{ with $id }}id="{{ . }}"{{ end }} class="rounded-top p-3 {{ with $class }} {{ . }}{{ end }}">
|
<div {{ with $id }}id="{{ . }}"{{ end }} class="rounded-top p-3 {{ with $class }} {{ . }}{{ end }}">
|
||||||
|
Reference in New Issue
Block a user