0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-19 16:54:24 +01:00

Docs: js-docs unindent automatically the code inside shortcode (#38349)

This commit is contained in:
Julien Déramond 2023-03-28 16:01:47 +02:00 committed by GitHub
parent 92f9dda263
commit 34c2725fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,27 @@
<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 -}}