diff options
| author | Christopher Morrissey <[email protected]> | 2019-09-06 18:35:43 +0300 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-11-04 15:32:29 +0200 |
| commit | 04acb679ab4282b50e2c6214c3ce7db634f9c2e1 (patch) | |
| tree | 4e2f6e6cc8cfdec6c279a68d2e0bf16c351bfac1 | |
| parent | a28adc76663b00b72abee1ae326b53cc9c9d6b9c (diff) | |
| download | bootstrap-04acb679ab4282b50e2c6214c3ce7db634f9c2e1.tar.xz bootstrap-04acb679ab4282b50e2c6214c3ce7db634f9c2e1.zip | |
Example shortcode: use a regex and simplify logic.
| -rw-r--r-- | site/layouts/shortcodes/example.html | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/site/layouts/shortcodes/example.html b/site/layouts/shortcodes/example.html index a13cccca4..22b3906ee 100644 --- a/site/layouts/shortcodes/example.html +++ b/site/layouts/shortcodes/example.html @@ -19,36 +19,7 @@ {{- end -}} {{- if eq $show_markup true -}} - {{- $.Scratch.Set "highlight_content" $input -}} - - {{- if (strings.Contains $input `<svg class="bd-placeholder-img`) -}} - {{- $.Scratch.Set "highlight_content" "" -}} - - {{- $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 "✂️" -}} - - {{- range $content_chunk := $modified_content -}} - {{- $image_class := "" -}} - - {{- if (strings.Contains $content_chunk `<svg class="bd-placeholder-img `) -}} - {{- $image_class = replace $content_chunk "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 -}} - - {{- 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" "" -}} + {{- $content := replaceRE `<svg.*class=.bd\-placeholder\-img(?:\-lg)?(?:\s*?bd\-placeholder\-img\-lg)?\s?(.*?)".*?<\/svg>\n` `<img src="..." class="$1" alt="..." >` $input -}} + {{- $content = replaceRE `(class="\s*?")` `` $content -}} + {{- highlight (trim $content `\n`) `html` `` -}} {{- end -}} |
