]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Docs: `js-docs` unindent automatically the code inside shortcode (#38349)
authorJulien Déramond <juderamond@gmail.com>
Tue, 28 Mar 2023 14:01:47 +0000 (16:01 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Mar 2023 14:01:47 +0000 (17:01 +0300)
site/layouts/shortcodes/js-docs.html

index 1a479db6789db39fb2d183b89f0aa3ff8b02a8c2..fad4f034fc058fef315624d2be302b4ddf42b663 100644 (file)
         <svg class="bi" aria-hidden="true"><use xlink:href="#clipboard"></use></svg>
       </button>
     </div>
-    {{- highlight $match "js" "" -}}
+    {{- $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 "js" "" -}}
   </div>
 {{- end -}}