Markdown to PDF converter using Pandoc and Typst
Project description
yakultpdf (mark2pdf)
基于 Pandoc 和 Typst 的 Markdown 转 PDF 专业工具链
yakultpdf 是一个强大的文档转换工具,旨在将 Markdown 文件转换为排版精美的 PDF 文档。它支持类似 Hugo/Jekyll 的工作区管理、Frontmatter 配置以及高度可定制的 Typst 模板系统。
⚠️ 注意: 本项目在 PyPI 上包名为
yakultpdf,导入模块时使用mark2pdf,命令行工具名为yakultpdf。
系统依赖
在安装之前,请确保已安装以下系统依赖:
macOS 安装
brew install pandoc typst
Linux 安装
# Ubuntu/Debian
sudo apt-get install pandoc typst
# 或使用 cargo 安装 typst
cargo install typst-cli
🚀 快速开始
1. 安装
pip install yakultpdf
2. 初始化工作区 (推荐)
我们强烈建议使用工作区模式来管理你的文档项目:
mkdir my-docs && cd my-docs
yakultpdf init .
这将创建标准目录结构 (in/, out/, mark2pdf.config.toml 等)。
3. 开始转换
将 Markdown 文件放入 in/ 目录,然后运行:
yakultpdf convert
生成的 PDF 将出现在 out/ 目录中。
4. 封面开关
默认不生成封面。
可以用三种方式开启:
# CLI 显式开启
yakultpdf convert test.md --with-cover
# mark2pdf.config.toml
[options]
withcover = true
# frontmatter.yaml 或文件头
theme:
withcover: true
优先级是:CLI > 单文件 YAML 头 > frontmatter.yaml > config > 默认关闭。
只要显式传了 --with-cover 或 --no-cover,CLI 就会覆盖文件头、frontmatter.yaml、disables: [cover] 和 config。
只有没传 CLI 时,disables: [cover] 才会按禁用处理。
5. 目录模式 title/image 自动注入
当使用 yakultpdf convert --dir <目录> 时:
- 会读取
index.md与各子文件 frontmatter 的title/image。 image会自动注入为topimage块:
::: {#topimage}
images/cover.jpg
:::
title会自动注入为 H1 标题(# 标题)。- 该行为仅在目录模式生效,默认开启。
- 如需关闭,在
index.mdfrontmatter 配置:
disables:
- title_injection
- 若只想关闭
index的题图注入(保留 index 标题和子文件注入):
disables:
- index_image
📚 文档导航
所有详细文档均位于 ./docs 目录:
- 入门必读: 💪 工作区使用指南 - 最佳实践、环境配置与工作流。
- 命令手册: 🛠 CLI 使用说明 - 所有命令参数详解。
- 配置参考: ⚙️ 配置指南 -
config.toml、封面开关与 Frontmatter 参数全解。 - 模板语法: 🎨 模板语法指南 - 如何使用高级排版特性(NB模板)。
- 架构说明: 🏗 项目说明文档 - 开发者视角的设计文档。
- 常见问题: ❓ FAQ - 疑难解答。
✨ 核心特性
- 工作区管理: 自动管理输入输出路径、模板与资源。
- 智能图片处理: 自动下载远程图片、微信公众号图片修复、本地路径重写。
- 混合排版: 支持标准 Markdown 与 Typst 语法混合使用。
- 多模式转换: 支持单文件转换、目录合并转换、批量转换。
- 中文优化: 内置简繁转换、常用中文字体下载与管理。
- 稿纸模式: 特有的
gaozhi转换器,生成书写练习稿纸。
🐍 Python API
也可以在 Python 代码中直接使用(注意导入模块名为 mark2pdf):
from mark2pdf import convert_file, convert_directory
# 单文件转换
convert_file("input.md", output_file="output.pdf")
# 目录转换(合并目录下所有 Markdown)
convert_directory("docs", output_file="merged_report.pdf")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yakultpdf-0.8.8.tar.gz.
File metadata
- Download URL: yakultpdf-0.8.8.tar.gz
- Upload date:
- Size: 3.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c26eb7100381f06bc93e726a7a615cb0d3251a1bdeae68256367851423b6ede8
|
|
| MD5 |
6286ce640c539d8199ad1983c161b98b
|
|
| BLAKE2b-256 |
6898eb59159f4fabad9e662a84c6b7d7ee04ec270eefe5a6a36871f7fd992128
|
File details
Details for the file yakultpdf-0.8.8-py3-none-any.whl.
File metadata
- Download URL: yakultpdf-0.8.8-py3-none-any.whl
- Upload date:
- Size: 312.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75bfaf1d16d4d5c4507708345f492d29df0a53cd57fce8a25eab988a92914ed0
|
|
| MD5 |
38be9fa0d9d7e595039fab6e72b9eb53
|
|
| BLAKE2b-256 |
5c8a887609ad6e15c886ff3327631592c1cc2214be233f7b74d21e1ec0a63414
|