Skip to content

Commit

Permalink
Docs: scss-docs unindent automatically the code inside shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
louismaximepiton committed Mar 24, 2023
1 parent 2008c65 commit f8a56da
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion site/layouts/shortcodes/scss-docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

0 comments on commit f8a56da

Please sign in to comment.