---
/**
* TypstBlock 组件
*
* 用于在 MDX 文章中渲染 Typst 数学公式和复杂排版。
*
* 使用方式:
*
* $ integral_0^infinity e^(-x^2) dif x = sqrt(pi) / 2 $
*
*
* 注意:此组件需要在构建时安装 Typst 编译器。
* 如果 Typst 未安装,会显示原始代码块作为降级方案。
*/
interface Props {
class?: string;
}
const { class: className = '' } = Astro.props;
// 获取子内容(Typst 代码)
const content = await Astro.slots.render('default');
const typstCode = content?.trim() || '';
---
{/*
Typst 渲染区域
在实际实现中,这里会调用 Typst 编译器将代码渲染为 SVG
目前作为占位符显示
*/}
{typstCode ? (
{/* SVG 输出区域 (构建时会被替换为实际的 Typst 渲染结果) */}
{typstCode}
Typst 公式
) : (
请提供 Typst 代码
)}