Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mark shortcode #480

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions layouts/shortcodes/mark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
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.
-->

{{- $error := false -}}
{{ $color := .Get "color" -}}
{{ $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 -}}

{{- $class := .Get "class" -}}

{{- if $color }}{{ $class = printf "%s text-bg-%s" $class $color }}{{ end -}}

{{- if not $error -}}
<mark{{ with $class }} class="{{ . }}"{{ end }}>{{ trim .Inner " \r\n" | .Page.RenderString -}}</mark>
{{- end -}}