创建 Presto 模板 Create Presto Templates
将你的排版规范变成可复用的命令行工具。支持 Go、Rust、TypeScript 三种语言,5 分钟发布到模板商店。 Turn your typesetting rules into reusable CLI tools. Supports Go, Rust, and TypeScript — publish to the store in 5 minutes.
工作原理 How It Works
Presto 模板是一个独立的可执行文件,通过 stdin/stdout 将 Markdown 转换为 Typst 排版源码。 A Presto template is a standalone binary that converts Markdown to Typst source code via stdin/stdout.
CLI 协议 CLI Protocol
| 调用方式 Usage | 行为 Behavior |
|---|---|
cat doc.md | ./binary | stdin 读取 Markdown,stdout 输出 Typst 源码 Read Markdown from stdin, output Typst to stdout |
./binary --manifest | 输出 manifest.json 内容 Output manifest.json contents |
./binary --example | 输出示例 Markdown 文档 Output example Markdown document |
./binary --version | 输出版本号 Output version number |
快速开始 Quick Start
选择你熟悉的语言,从 Starter 仓库创建你的模板项目。 Choose your preferred language and create a template project from a Starter repo.
交叉编译最简单,GOOS/GOARCH 即可 Simplest cross-compilation with GOOS/GOARCH
二进制最小、性能最高 Smallest binary, best performance
开发体验最好,Bun 编译 Best DX, compiled with Bun
创建仓库 Create Repository
在 GitHub 上点击 "Use this template" 创建你的模板仓库: Click "Use this template" on GitHub to create your template repo:
presto-template-starter-go
presto-template-starter-rust
presto-template-starter-typescript放入参考文件 Add Reference Files
将你的排版参考文件(PDF、DOCX、图片等)放入 reference/ 目录。AI 编程工具可以直接分析这些文件来生成转换代码。 Place your typesetting reference files (PDF, DOCX, images, etc.) in the reference/ directory. AI coding tools can analyze these files to generate conversion code.
开发与预览 Develop & Preview
make preview # 编译并安装到本地 PrestoBuild and install to local Presto在 Presto 中实时预览你的模板效果,对照参考文件调整排版。 Preview your template live in Presto and adjust typesetting against reference files.
发布 Publish
git tag v1.0.0 && git push origin main --tags打 tag 推送后,CI 自动编译 6 个平台的二进制并创建 GitHub Release。Registry 每 6 小时自动收录新模板到商店。 Push a tag and CI automatically builds binaries for 6 platforms and creates a GitHub Release. The registry indexes new templates every 6 hours.
manifest.json
模板的元数据文件,编译时嵌入到二进制中。 Template metadata file, embedded into the binary at compile time.
{
"name": "my-template",
"displayName": "我的模板",
"description": "一句话描述模板用途",
"version": "1.0.0",
"author": "your-github-username",
"license": "MIT",
"category": "通用",
"keywords": ["报告", "商务"],
"minPrestoVersion": "0.1.0",
"requiredFonts": [],
"frontmatterSchema": {
"title": { "type": "string", "default": "请输入标题" },
"date": { "type": "string", "format": "YYYY-MM-DD" }
}
}name
唯一标识符,kebab-case Unique identifier, kebab-case
displayName
显示名称(中文或英文) Display name shown in the store
category
分类标签,自由文本,≤20 字符 Category tag, free text, ≤20 chars
keywords
搜索关键词,2-6 个 Search keywords, 2-6 items
requiredFonts
所需字体列表(含下载链接) Required fonts (with download URLs)
frontmatterSchema
YAML frontmatter 字段定义 YAML frontmatter field definitions
安全模型 Security Model
模板二进制直接在用户机器上运行,Presto 通过三层防护确保安全。 Template binaries run directly on user machines. Presto ensures safety with three-layer defense.
静态分析 Static Analysis
源码层面检测禁止的 import——不允许网络库、进程执行、动态加载等。 Source-level detection of forbidden imports — no networking, process exec, or dynamic loading.
# Go
go list -f '{{join .Imports "\\n"}}' ./... | grep -E 'net|os/exec|plugin'
# Rust
cargo tree --prefix none | grep -iE 'reqwest|hyper|tokio|std::net'
# TypeScript
grep -rE 'node:http|node:net|fetch\(' src/运行时网络沙箱 Runtime Network Sandbox
操作系统级网络隔离,即使绕过静态分析也无法联网。 OS-level network isolation — even if static analysis is bypassed, networking is blocked.
# macOS
sandbox-exec -p '(version 1)(allow default)(deny network*)' ./binary
# Linux
unshare --net ./binary输出验证 Output Validation
检测 stdout 输出:禁止 HTML 标签,首行必须是 Typst 指令(# 开头)。 Validates stdout output: no HTML tags allowed, first line must be a Typst directive (starts with #).
关键约束 Key Constraints
- 禁止访问网络 — 所有资源在编译时嵌入 No network access — all resources embedded at compile time
- 禁止写文件 — 只允许 stdin/stdout I/O No file writes — only stdin/stdout I/O allowed
- 执行超时 30 秒,二进制大小限制 100MB 30-second timeout, 100MB binary size limit
- 执行环境最小化:
PATH=/usr/local/bin:/usr/bin:/binMinimal execution environment:PATH=/usr/local/bin:/usr/bin:/bin
测试与发布 Testing & Publishing
编译当前平台二进制 Build binary for current platform
编译并安装到本地 Presto 预览 Build and install to local Presto
安全测试 + 功能测试(CI 使用) Security tests + functional tests (for CI)
仅运行安全测试 Run security tests only
发布流程 Publishing
git add -A && git commit -m "feat: initial template"
git tag v1.0.0
git push origin main --tagsCI 会自动编译以下 6 个平台的二进制,生成 SHA256SUMS 校验文件,并创建 GitHub Release: CI automatically builds binaries for 6 platforms, generates SHA256SUMS checksums, and creates a GitHub Release:
信任标识 Trust Levels
模板在商店中会显示信任标识,由 Registry 自动判定: Templates display trust badges in the store, determined automatically by the Registry:
如何获得 Verified 标识 How to Get Verified
- 在
template-registry仓库提交 PR,附上模板源码仓库地址 Submit a PR to thetemplate-registryrepo with your template source repository URL - Presto CI 自动拉取源码,在沙箱中编译各平台二进制 Presto CI automatically pulls the source and compiles binaries for all platforms in a sandbox
- CI 通过后自动签名并发布到 Registry After CI passes, binaries are automatically signed and published to the Registry
- 模板获得 Verified 标识 Template receives the Verified badge
项目结构 Project Structure
my-template/
reference/ ← 参考文件(PDF、DOCX 等)← Reference files (PDF, DOCX, etc.)
main.go ← 核心转换逻辑← Core conversion logic
manifest.json ← 模板元数据← Template metadata
example.md ← 示例输入文档← Example input document
Makefile ← build / preview / test / clean
.github/workflows/
release.yml ← 6 平台自动构建← 6-platform auto build
README.md ← 模板说明文档← Template documentationStarter 仓库已配置好 CI、Makefile 和 AI 工具的配置文件(CLAUDE.md、AGENTS.md、.cursor/rules),让你专注于排版逻辑。 Starter repos come pre-configured with CI, Makefile, and AI tool configs (CLAUDE.md, AGENTS.md, .cursor/rules), so you can focus on typesetting logic.
AI 辅助开发 AI-Assisted Development
Starter 仓库内置了多 AI 工具的配置文件,指向统一的开发规范。你可以用任何 AI 编程工具来开发模板。 Starter repos include configs for multiple AI coding tools, all pointing to unified conventions. Use any AI tool you prefer.
开发流程:放入参考文件 → AI 分析排版特征 → 确认参数 → 生成代码 → make preview → 迭代调整。 Workflow: add reference files → AI analyzes typesetting → confirm parameters → generate code → make preview → iterate.
开始创建你的模板 Start Building Your Template
从 Starter 仓库开始,5 分钟内发布你的第一个模板。 Start from a Starter repo and publish your first template in 5 minutes.