]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Docs: `scss-docs` unindent automatically the code inside shortcode
authorLouis-Maxime Piton <louismaxime.piton@orange.com>
Fri, 24 Mar 2023 14:11:22 +0000 (15:11 +0100)
committerGitHub <noreply@github.com>
Fri, 24 Mar 2023 14:11:22 +0000 (16:11 +0200)
site/layouts/shortcodes/scss-docs.html

index 2bfdf8de5ec63819c13a02c1d03afa92cf54ecbc..d28b29c926db8b1ab33b03954a10566858853185 100644 (file)
         </button>
       </div>
     </div>
-    {{- highlight $match "scss" "" -}}
+    {{- $unindent := 0 -}}
+    {{- $found := false -}}
+    {{- $first_line:= index (split $match "\n") 0 -}}
+    {{- range $char := split $first_line "" -}}
+      {{- if and (eq $char " ") (not $found) -}}
+        {{- $unindent = add $unindent 1 -}}
+      {{- else -}}
+        {{- $found = true -}}
+      {{- end -}}
+    {{- end -}}
+    {{- $output := "" -}}
+    {{- if (gt $unindent 0) -}}
+      {{- $prefix := (strings.Repeat $unindent " ") -}}
+      {{- range $line := split $match "\n" -}}
+        {{- $line = strings.TrimPrefix $prefix $line -}}
+        {{ $output = printf "%s%s\n" $output $line }}
+      {{- end -}}
+      {{- $output = chomp $output -}}
+    {{- else -}}
+      {{- $output = $match -}}
+    {{- end -}}
+    {{- highlight $output "scss" "" -}}
   </div>
 {{- end -}}