mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-17 15:03:20 +00:00
Refactor mark shortcode
This commit is contained in:
27
data/structures/mark.yml
Normal file
27
data/structures/mark.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
comment: Highlights text by applying a background color.
|
||||
arguments:
|
||||
class:
|
||||
type: string
|
||||
optional: true
|
||||
comment: Class attribute of the highlight element.
|
||||
color:
|
||||
type: select
|
||||
optional: true
|
||||
comment: >-
|
||||
Theme color of the highlight. By default, the highlight uses the color of
|
||||
the HTML mark function.
|
||||
options:
|
||||
values:
|
||||
- primary
|
||||
- secondary
|
||||
- success
|
||||
- danger
|
||||
- warning
|
||||
- info
|
||||
- light
|
||||
- dark
|
||||
- white
|
||||
- black
|
||||
body:
|
||||
optional: false
|
||||
comment: Text to be marked.
|
@@ -1,23 +1,24 @@
|
||||
|
||||
<!--
|
||||
Highlights text by applying a background color. The shortcode supports the following arguments:
|
||||
"color": Optional theme color of the highlight, either "primary", "secondary", "success", "danger",
|
||||
"warning", "info", "light", "dark", "white" or "black". By default, the highlight uses the color of
|
||||
the HTML mark function.
|
||||
"class": Optional class attribute of the highlight element.
|
||||
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.
|
||||
-->
|
||||
|
||||
{{- $error := false -}}
|
||||
{{ $color := .Get "color" | default "" -}}
|
||||
{{ $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" -}}
|
||||
{{ if and $color (not (in $supportedColors $color)) -}}
|
||||
{{ errorf "Invalid value for param 'color': %s" .Position -}}
|
||||
{{ $error = true -}}
|
||||
{{ end -}}
|
||||
{{ $error := false -}}
|
||||
|
||||
<!-- Validate arguments -->
|
||||
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "mark" "args" .Params) }}
|
||||
{{ errorf "Invalid arguments: %s" .Position -}}
|
||||
{{ $error = true }}
|
||||
{{ end }}
|
||||
|
||||
<!-- Initialize arguments -->
|
||||
{{ $color := .Get "color" | default "" -}}
|
||||
{{- $class := .Get "class" | default "" -}}
|
||||
|
||||
{{- if $color }}{{ $class = printf "%s text-bg-%s" $class $color }}{{ end -}}
|
||||
|
||||
<!-- Main code -->
|
||||
{{- if not $error -}}
|
||||
{{- if $color }}{{ $class = printf "%s text-bg-%s" $class $color }}{{ end -}}
|
||||
<mark{{ with $class }} class="{{ . }}"{{ end }}>{{ trim .Inner " \r\n" | .Page.RenderString -}}</mark>
|
||||
{{- end -}}
|
Reference in New Issue
Block a user