{{/* Copyright © 2022 - 2025 The Hinode Team / Mark Dumay. All rights reserved. Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file. Visit gethinode.com/license for more details. This source code adapts the original embedded shortcode as maintained by the The Bootstrap Authors. It introduces the following modifications: - Added validation of shortcode arguments - Modified the layout The original source code is available on: https://github.com/twbs/bootstrap/blob/main/site/layouts/shortcodes/scss-docs.html Copyright (c) 2011-2023 The Bootstrap Authors. Licensed under The MIT License (MIT). */}} {{ $error := false -}} {{/* Initialize arguments */}} {{- $args := partial "utilities/InitArgs.html" (dict "structure" "docs" "args" .Params "named" .IsNamedParams "group" "shortcode") -}} {{- if or $args.err $args.warnmsg -}} {{- partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict "partial" "shortcodes/docs.html" "msg" "Invalid arguments" "details" ($args.errmsg | append $args.warnmsg) "file" page.File "position" .Position )}} {{ $error = $args.err }} {{- end -}} {{/* Initialize local arguments */}} {{- $id := $args.id | default (printf "docs-collapse-%d" .Ordinal) -}} {{- $basePath := .Site.Params.docs.basePath -}} {{- $file := $args.file -}} {{- if hasPrefix $file "./" -}} {{- $file = path.Clean $file -}} {{- else -}} {{- $file = path.Join $basePath (path.Clean $file) -}} {{- end -}} {{- $extension := strings.TrimLeft "." (path.Ext $file) }} {{- $captureStart := "" -}} {{- $captureEnd := "" -}} {{- $supportedExtensions := slice "js" "scss" "toml" -}} {{- if in $supportedExtensions $extension -}} {{- if eq $extension "toml" }} {{- $captureStart = printf "# toml-docs-start %s" $args.name -}} {{- $captureEnd = printf "# toml-docs-end %s" $args.name -}} {{- else -}} {{- $captureStart = printf "// %s-docs-start %s" $extension $args.name -}} {{- $captureEnd = printf "// %s-docs-end %s" $extension $args.name -}} {{- end -}} {{- else -}} {{- errorf "File format not supported (line %s): %s" .Position $file -}} {{- end -}} {{/* Main code */}} {{- if not $error -}} {{- /* Force-check if the file exists */ -}} {{ $tmp := os.Stat $file }} {{- $regex := printf `%s((?:.|\n)*)%s` $captureStart $captureEnd -}} {{- $match := findRE $regex (readFile $file) -}} {{- $match = index $match 0 -}} {{- if not $match -}} {{- errorf "%s: %q: Got no matches for name=%q in file=%q!" .Position .Name $args.name $file -}} {{- end -}} {{- $match = replace $match $captureStart "" -}} {{- $match = replace $match $captureEnd "" -}}
{{- highlight (trim $match "\r\n") $extension "" -}}
{{- end -}}