-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from gethinode/develop
Add mark shortcode
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -}} |