diff options
| author | Louis-Maxime Piton <[email protected]> | 2023-03-24 15:11:22 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-24 16:11:22 +0200 |
| commit | f8a56da8b04d8d29a8a8f65d50549206c429a621 (patch) | |
| tree | 49c4d3bdf6c99ed538defbf277948d60a287ab39 | |
| parent | 2008c65c54c36fabf6c59e99591fc231708f6fa2 (diff) | |
| download | bootstrap-f8a56da8b04d8d29a8a8f65d50549206c429a621.tar.xz bootstrap-f8a56da8b04d8d29a8a8f65d50549206c429a621.zip | |
Docs: `scss-docs` unindent automatically the code inside shortcode
| -rw-r--r-- | site/layouts/shortcodes/scss-docs.html | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/site/layouts/shortcodes/scss-docs.html b/site/layouts/shortcodes/scss-docs.html index 2bfdf8de5..d28b29c92 100644 --- a/site/layouts/shortcodes/scss-docs.html +++ b/site/layouts/shortcodes/scss-docs.html @@ -50,6 +50,27 @@ </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 -}} |
