Skip to content

Commit f8a56da

Browse files
Docs: scss-docs unindent automatically the code inside shortcode
1 parent 2008c65 commit f8a56da

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

site/layouts/shortcodes/scss-docs.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@
5050
</button>
5151
</div>
5252
</div>
53-
{{- highlight $match "scss" "" -}}
53+
{{- $unindent := 0 -}}
54+
{{- $found := false -}}
55+
{{- $first_line:= index (split $match "\n") 0 -}}
56+
{{- range $char := split $first_line "" -}}
57+
{{- if and (eq $char " ") (not $found) -}}
58+
{{- $unindent = add $unindent 1 -}}
59+
{{- else -}}
60+
{{- $found = true -}}
61+
{{- end -}}
62+
{{- end -}}
63+
{{- $output := "" -}}
64+
{{- if (gt $unindent 0) -}}
65+
{{- $prefix := (strings.Repeat $unindent " ") -}}
66+
{{- range $line := split $match "\n" -}}
67+
{{- $line = strings.TrimPrefix $prefix $line -}}
68+
{{ $output = printf "%s%s\n" $output $line }}
69+
{{- end -}}
70+
{{- $output = chomp $output -}}
71+
{{- else -}}
72+
{{- $output = $match -}}
73+
{{- end -}}
74+
{{- highlight $output "scss" "" -}}
5475
</div>
5576
{{- end -}}

0 commit comments

Comments
 (0)