Skip to main content

yakultpdf (mark2pdf)

基于 Pandoc 和 Typst 的 Markdown 转 PDF 专业工具链

一个强大的文档转换工具,旨在将 Markdown 文件转换为排版精美的 PDF 文档。它支持类似 Hugo/Jekyll 的工作区管理、Frontmatter 配置以及高度可定制的 Typst 模板系统。

注意: 本项目在 PyPI 上包名为 yakultpdf,导入模块时使用 mark2pdf,命令行工具名为 yakultpdf。

系统依赖

在安装之前,请确保已安装以下系统依赖:

  • Pandoc - 通用文档转换工具
  • Typst - 现代排版系统

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.md frontmatter 配置:
disables:
  - title_injection
  • 若只想关闭 index 的题图注入(保留 index 标题和子文件注入):
disables:
  - index_image

文档导航

所有详细文档均位于 ./docs 目录:


核心特性

  • 工作区管理: 自动管理输入输出路径、模板与资源。
  • 智能图片处理: 自动下载远程图片、微信公众号图片修复、本地路径重写。
  • 混合排版: 支持标准 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")

Metadata

Release files for yakultpdf 0.8.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yakultpdf 0.8.20
File Size Uploaded
yakultpdf-0.8.20.tar.gz 3.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for yakultpdf 0.8.20
File Interpreter ABI Platform
yakultpdf-0.8.20-py3-none-any.whl Python 3 none any Details

Total release size: 3.6 MB

Release files / yakultpdf-0.8.20.tar.gz

Download URL yakultpdf-0.8.20.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
2a5e583702e6ba3138f8ad8d26f2e849b306432d469ded903f717cf758673e21
BLAKE2b-256 checksum
How to use checksums
f6362e161cd329925880b8300d5d6315bef60d5630a61b9adb9f8dc2f39a0cb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.9

Release files / yakultpdf-0.8.20-py3-none-any.whl

Download URL yakultpdf-0.8.20-py3-none-any.whl
Size 340.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfe8142ca422dbb0648b2f7b07199bb80a158c293c8cbeb8d8a8412e3789a8d7
BLAKE2b-256 checksum
How to use checksums
eef4669063577e0d19366d9a595c995fef8de29bf75b07c33d45a22ff37847ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.9

Release history Release notifications | RSS feed

0.8.23

2 release files

This release

0.8.20 This release

2 release files

0.8.9

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.3

2 release files

0.7.36

2 release files

0.7.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page