From 24e96e2724a31c4831ab0bca65bafb732ee1ff12 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 27 Dec 2023 09:20:29 +0100 Subject: [PATCH] Refactor mark shortcode --- data/structures/mark.yml | 27 +++++++++++++++++++++++++++ layouts/shortcodes/mark.html | 29 +++++++++++++++-------------- 2 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 data/structures/mark.yml diff --git a/data/structures/mark.yml b/data/structures/mark.yml new file mode 100644 index 00000000..4106bd37 --- /dev/null +++ b/data/structures/mark.yml @@ -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. diff --git a/layouts/shortcodes/mark.html b/layouts/shortcodes/mark.html index cc4d6138..ef7041f1 100644 --- a/layouts/shortcodes/mark.html +++ b/layouts/shortcodes/mark.html @@ -1,23 +1,24 @@ + -{{- $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 -}} + +{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "mark" "args" .Params) }} + {{ errorf "Invalid arguments: %s" .Position -}} + {{ $error = true }} +{{ end }} + + +{{ $color := .Get "color" | default "" -}} {{- $class := .Get "class" | default "" -}} -{{- if $color }}{{ $class = printf "%s text-bg-%s" $class $color }}{{ end -}} - + {{- if not $error -}} + {{- if $color }}{{ $class = printf "%s text-bg-%s" $class $color }}{{ end -}} {{ trim .Inner " \r\n" | .Page.RenderString -}} {{- end -}} \ No newline at end of file