docs/layouts/_default/_markup/render-codeblock.html

71 lines
2.5 KiB
HTML

<div data-pagefind-ignore class="scroll-mt-2" x-data x-ref="root">
{{ with .Attributes.title }}
<div
class="mb-0 rounded-sm bg-gray-100 p-2 text-sm text-gray-900 dark:bg-gray-900 dark:text-gray-200"
>
{{ . }}
</div>
{{ end }}
<div class="group relative">
<!-- copy button -->
<button
x-data="{ code: '{{ encoding.Base64Encode .Inner }}', copying: false }"
class="absolute top-3 right-3 z-10 text-gray-200 dark:text-gray-500"
title="copy"
@click="window.navigator.clipboard.writeText(atob(code).replaceAll(/^[\$>]\s+/gm, ''));
copying = true;
setTimeout(() => copying = false, 2000);"
>
<span :class="{ 'group-hover:block' : !copying }" class="icon-svg hidden"
>{{ partialCached "icon" "content_copy" "content_copy" }}</span
>
<span :class="{ 'group-hover:block' : copying }" class="icon-svg hidden"
>{{ partialCached "icon" "check_circle" "check_circle" }}</span
>
</button>
{{ $lang := .Type | default "text" }}
{{ $result := transform.Highlight .Inner
$lang .Options
}}
<div class="syntax-light dark:syntax-dark not-prose">
{{ with .Attributes.collapse }}
<div
x-data="{ collapse: true }"
class="relative overflow-clip"
x-init="$watch('collapse', value => $refs.root.scrollIntoView({ behavior: 'smooth'}))"
>
<div
x-show="collapse"
class="absolute z-10 flex h-32 w-full flex-col-reverse items-center overflow-clip pb-4"
>
<button
@click="collapse = false"
class="bg-blue flex items-center rounded-full px-2 text-sm text-white dark:bg-blue-500"
>
<span>Show more</span>
<span class="icon-svg"
>{{ partialCached "icon" "arrow_drop_down" "arrow_drop_down" }}</span
>
</button>
</div>
<div :class="{ 'h-32': collapse }">
{{ $result }}
<button
@click="collapse = true"
x-show="!collapse"
class="bg-blue mx-auto mt-4 flex items-center rounded-full px-2 text-sm text-white dark:bg-blue-500"
>
<span>Hide</span>
<span class="icon-svg"
>{{ partialCached "icon" "arrow_drop_up" "arrow_drop_up" }}</span
>
</button>
</div>
</div>
{{ else }}
{{ $result }}
{{ end }}
</div>
</div>
</div>