aboutsummaryrefslogtreecommitdiff
path: root/site/layouts/shortcodes/example.html
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2019-01-08 18:33:28 +0200
committerXhmikosR <[email protected]>2019-03-13 19:22:59 +0200
commitd95d30029f8d63190eb242c9914cee16b6b90627 (patch)
tree06fbab510fa94ac092606eb04b37d061e64d8fbc /site/layouts/shortcodes/example.html
parent6aa475c82e69a02882e87da7067e522806d6579c (diff)
downloadbootstrap-d95d30029f8d63190eb242c9914cee16b6b90627.tar.xz
bootstrap-d95d30029f8d63190eb242c9914cee16b6b90627.zip
Switch to Hugo.
No more Ruby dependency and most important more than 10 times less build time (at least on Windows)!
Diffstat (limited to 'site/layouts/shortcodes/example.html')
-rw-r--r--site/layouts/shortcodes/example.html53
1 files changed, 53 insertions, 0 deletions
diff --git a/site/layouts/shortcodes/example.html b/site/layouts/shortcodes/example.html
new file mode 100644
index 000000000..67813b70f
--- /dev/null
+++ b/site/layouts/shortcodes/example.html
@@ -0,0 +1,53 @@
+{{- /*
+ Usage: `example [args]`
+
+ `args` are optional and can be one of the following:
+ id: the `div`'s id - default: ""
+ class: any extra class(es) to be added to the `div` - default ""
+ show_preview: if the preview should be output in the HTML - default: `true`
+ show_markup: if the markup should be output in the HTML - default: `true`
+*/ -}}
+
+{{- $show_preview := .Get "show_preview" | default true -}}
+{{- $show_markup := .Get "show_markup" | default true -}}
+{{- $input := .Inner -}}
+
+{{- if eq $show_preview true -}}
+<div{{ with .Get "id" }} id="{{ . }}"{{ end }} class="bd-example{{ with .Get "class" }} {{ . }}{{ end }}">
+ {{- $input -}}
+</div>
+{{- end -}}
+
+{{- if eq $show_markup true -}}
+ {{- $.Scratch.Set "highlight_content" $input -}}
+
+ {{- if (strings.Contains $input `<svg class="bd-placeholder-img`) -}}
+ {{- $.Scratch.Set "highlight_content" "" -}}
+ {{- $image_class := "" -}}
+
+ {{- $modified_content := replace $input `<svg class="bd-placeholder-img` `✂️<svg class="bd-placeholder-img` -}}
+ {{- $modified_content = replace $modified_content "</svg>\n" "</svg>✂️" -}}
+ {{- $modified_content = split $modified_content "✂️" -}}
+
+ {{- if (strings.Contains $input `<svg class="bd-placeholder-img `) -}}
+ {{- $image_class = replace $input "bd-placeholder-img " "bd-placeholder-img ✂️ " -}}
+ {{- $image_class = split (replace $image_class `" width="` `✂️" width="`) "✂️" -}}
+ {{- $image_class = replace (index $image_class 1) "bd-placeholder-img-lg" "" -}}
+ {{- $image_class = trim $image_class " " -}}
+ {{- end -}}
+
+ {{- range $i, $content_chunk := $modified_content -}}
+ {{- if (strings.Contains $content_chunk `<svg class="bd-placeholder-img`) -}}
+ {{- if $image_class -}}
+ {{- $.Scratch.Add "highlight_content" (printf `<img src="..." class="%s" alt="...">` $image_class) -}}
+ {{- else -}}
+ {{- $.Scratch.Add "highlight_content" `<img src="..." alt="...">` -}}
+ {{- end -}}
+ {{- else -}}
+ {{- $.Scratch.Add "highlight_content" $content_chunk -}}
+ {{- end -}}
+ {{- end -}}
+ {{- end -}}
+
+ {{- highlight (trim ($.Scratch.Get "highlight_content") "\n") "html" "" -}}
+{{- end -}}