diff options
| author | Julien Déramond <[email protected]> | 2023-03-28 16:01:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-28 17:01:47 +0300 |
| commit | 34c2725fe1c59940d775054f374d7cb6836bf80f (patch) | |
| tree | 9bf846270bb1804d6245f9657fe2b8e1898de4c0 | |
| parent | 92f9dda263e4a80a8b9a60574af20f610b6c6fa8 (diff) | |
| download | bootstrap-34c2725fe1c59940d775054f374d7cb6836bf80f.tar.xz bootstrap-34c2725fe1c59940d775054f374d7cb6836bf80f.zip | |
Docs: `js-docs` unindent automatically the code inside shortcode (#38349)
| -rw-r--r-- | site/layouts/shortcodes/js-docs.html | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/site/layouts/shortcodes/js-docs.html b/site/layouts/shortcodes/js-docs.html index 1a479db67..fad4f034f 100644 --- a/site/layouts/shortcodes/js-docs.html +++ b/site/layouts/shortcodes/js-docs.html @@ -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 -}} |
