2025-05-01 12:50:40 +08:00
|
|
|
{% macro code_block(code, language="html", class="my-4") %}
|
2025-06-20 08:29:29 +08:00
|
|
|
<div class="relative {{ class }}">
|
2025-11-02 11:56:40 +08:00
|
|
|
<pre class="grid text-sm max-h-[650px] overflow-y-auto rounded-xl scrollbar"><code class="language-{{ language }} !bg-muted/40 !p-3.5">{{- code | escape -}}</code></pre>
|
2025-06-20 08:29:29 +08:00
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
onclick="
|
|
|
|
|
const button = this;
|
|
|
|
|
const code = this.parentElement.querySelector('pre code');
|
|
|
|
|
if (!code) return;
|
|
|
|
|
navigator.clipboard.writeText(code.textContent || '').then(() => {
|
|
|
|
|
button.classList.add('copied');
|
|
|
|
|
setTimeout(() => { button.classList.remove('copied') }, 2000);
|
2025-04-25 16:42:10 +08:00
|
|
|
}).catch(err => {
|
|
|
|
|
console.error('Failed to copy text: ', err);
|
|
|
|
|
});
|
2025-06-20 08:29:29 +08:00
|
|
|
"
|
|
|
|
|
class="btn-icon-ghost size-8 absolute right-2.5 top-2 text-muted-foreground hover:text-foreground group"
|
2025-04-25 16:42:10 +08:00
|
|
|
>
|
2025-11-03 13:51:40 +08:00
|
|
|
{% lucide "copy", {"class": "group-[.copied]:hidden" } %}
|
2025-06-20 08:29:29 +08:00
|
|
|
{% lucide "check", {"class": "hidden group-[.copied]:block" } %}
|
2025-04-25 16:42:10 +08:00
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-05-01 12:50:40 +08:00
|
|
|
{% endmacro %}
|