huashu-md-to-pdf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Markdown to PDF Skill

Markdown to PDF Skill

将 Markdown 文档转换为专业的苹果设计风格 PDF 白皮书。
Convert Markdown documents into professional PDF whitepapers with Apple design style.

核心功能

Core Features

  1. 专业排版:书籍级排版质量,自动处理分页、孤行寡行
  2. 苹果设计:SF 字体系统、现代简洁风格、专业配色
  3. 完整目录:自动提取章节结构,双列布局,可点击跳转
  4. Markdown 完美支持:代码块、表格、引用、列表等全部正确渲染
  1. Professional Typesetting: Book-level typesetting quality, automatically handles page breaks, widows and orphans
  2. Apple Design: SF font system, modern and minimalist style, professional color scheme
  3. Complete Table of Contents: Automatically extracts chapter structure, two-column layout, clickable navigation
  4. Full Markdown Support: Correctly renders code blocks, tables, blockquotes, lists, etc.

使用方法

Usage Instructions

基础用法

Basic Usage

bash
undefined
bash
undefined

转换单个文件

Convert a single file

python scripts/convert.py input.md
python scripts/convert.py input.md

指定输出文件名

Specify output file name

python scripts/convert.py input.md -o "我的白皮书.pdf"
python scripts/convert.py input.md -o "我的白皮书.pdf"

自定义标题和作者

Customize title and author

python scripts/convert.py input.md --title "技术白皮书" --author "花叔"
undefined
python scripts/convert.py input.md --title "技术白皮书" --author "花叔"
undefined

Markdown 文档要求

Markdown Document Requirements

你的 Markdown 文档应该遵循以下结构:
markdown
undefined
Your Markdown document should follow this structure:
markdown
undefined

文档标题

Document Title

1. 第一章

1. Chapter 1

1.1 第一节

1.1 Section 1

1.2 第二节

1.2 Section 2

2. 第二章

2. Chapter 2

2.1 第一节

2.1 Section 1


**关键规则**:
- 主章节:`## 1. 标题`(数字 + 点 + 空格 + 标题)
- 子章节:`### 1.1 标题`(数字.数字 + 空格 + 标题)
- 这样才能正确提取目录

**Key Rules**:
- Main chapters: `## 1. Title` (number + dot + space + title)
- Sub-chapters: `### 1.1 Title` (number.number + space + title)
- This ensures correct table of contents extraction

设计特点

Design Features

封面设计

Cover Design

  • 淡灰色渐变背景
  • 大标题:64pt,简洁现代
  • 副标题和元信息
  • Light gray gradient background
  • Large title: 64pt, clean and modern
  • Subtitle and meta information

目录设计

Table of Contents Design

  • 双列布局,单页展示
  • 主章节粗体,子章节缩进
  • 可点击跳转到对应章节
  • Two-column layout, single-page display
  • Main chapters in bold, sub-chapters indented
  • Clickable to jump to corresponding chapters

正文排版

Body Typesetting

  • SF 字体系列(苹果设计语言)
  • 行高 1.7,舒适阅读
  • 章节自动分页
  • 孤行寡行控制
  • SF font family (Apple design language)
  • Line height 1.7, comfortable reading
  • Automatic page breaks for chapters
  • Widow and orphan control

代码块

Code Blocks

  • 浅灰背景 + 细边框
  • 圆角 8px
  • SF Mono 等宽字体
  • 自动避免分页
  • Light gray background + thin border
  • 8px rounded corners
  • SF Mono monospaced font
  • Automatically avoids page breaks

表格

Tables

  • 清晰网格线
  • 浅灰表头
  • 自动保留表头(长表格分页时)
  • Clear grid lines
  • Light gray header
  • Automatically retains header (for long tables with page breaks)

配置选项

Configuration Options

如果需要自定义样式,可以修改
scripts/convert.py
中的 CSS 变量:
python
undefined
To customize styles, modify the CSS variables in
scripts/convert.py
:
python
undefined

主色调

Primary color

PRIMARY_COLOR = '#06c' # 苹果蓝 TEXT_COLOR = '#1d1d1f' # 主文本黑色 GRAY_COLOR = '#86868b' # 浅灰色
PRIMARY_COLOR = '#06c' # Apple blue TEXT_COLOR = '#1d1d1f' # Main text black GRAY_COLOR = '#86868b' # Light gray

字体大小

Font sizes

COVER_TITLE_SIZE = '64pt' H2_SIZE = '22pt' H3_SIZE = '17pt' BODY_SIZE = '11pt'
undefined
COVER_TITLE_SIZE = '64pt' H2_SIZE = '22pt' H3_SIZE = '17pt' BODY_SIZE = '11pt'
undefined

常见问题

Frequently Asked Questions

Q: 目录为什么是空的?

Q: Why is the table of contents empty?

A: 确保你的 Markdown 使用了正确的章节格式:
  • ## 1. 标题
    而不是
    ## 标题
  • ### 1.1 标题
    而不是
    ### 标题
A: Ensure your Markdown uses the correct chapter format:
  • ## 1. Title
    instead of
    ## Title
  • ### 1.1 Title
    instead of
    ### Title

Q: 代码块显示不正确?

Q: Code blocks are not displayed correctly?

A: 确保使用三个反引号包裹:
markdown
```python
def hello():
    print("Hello")
```
A: Ensure they are wrapped with three backticks:
markdown
```python
def hello():
    print("Hello")
```

Q: 表格格式乱了?

Q: Table formatting is messed up?

A: 使用标准的 Markdown 表格语法:
markdown
| 列1 | 列2 |
|-----|-----|
| 值1 | 值2 |
A: Use standard Markdown table syntax:
markdown
| Column 1 | Column 2 |
|-----|-----|
| Value 1 | Value 2 |

Q: 如何修改字体?

Q: How to modify fonts?

A: 编辑
scripts/convert.py
中的 CSS,修改
font-family
属性。
A: Edit the CSS in
scripts/convert.py
and modify the
font-family
property.

Q: 生成的 PDF 太大?

Q: The generated PDF is too large?

A: 检查是否有大量图片,考虑压缩图片或使用外链。
A: Check for large images, consider compressing images or using external links.

依赖安装

Dependency Installation

首次使用需要安装 Python 依赖:
bash
pip3 install markdown2 weasyprint
如果遇到 WeasyPrint 安装问题(macOS):
bash
brew install pango
pip3 install weasyprint
Install Python dependencies for first-time use:
bash
pip3 install markdown2 weasyprint
If you encounter WeasyPrint installation issues (macOS):
bash
brew install pango
pip3 install weasyprint

示例

Examples

生成技术文档

Generate Technical Document

bash
python scripts/convert.py tech-guide.md -o "技术指南.pdf"
bash
python scripts/convert.py tech-guide.md -o "技术指南.pdf"

生成白皮书

Generate Whitepaper

bash
python scripts/convert.py whitepaper.md --title "产品白皮书" --author "团队"
bash
python scripts/convert.py whitepaper.md --title "产品白皮书" --author "团队"

脚本说明

Script Description

  • scripts/convert.py
    - 主转换脚本
  • scripts/styles.css
    - CSS 样式定义(已嵌入脚本)
  • templates/cover.html
    - 封面模板(已嵌入脚本)
  • scripts/convert.py
    - Main conversion script
  • scripts/styles.css
    - CSS style definitions (embedded in the script)
  • templates/cover.html
    - Cover template (embedded in the script)

技术实现

Technical Implementation

本 Skill 使用:
  • markdown2:Markdown 解析(支持扩展语法)
  • WeasyPrint:HTML to PDF 转换(支持 CSS3)
  • 苹果设计系统:SF 字体、专业配色、现代排版
This Skill uses:
  • markdown2: Markdown parsing (supports extended syntax)
  • WeasyPrint: HTML to PDF conversion (supports CSS3)
  • Apple Design System: SF fonts, professional color scheme, modern typesetting

更新日志

Changelog

v1.0 (2025-12-24)

v1.0 (2025-12-24)

  • 初始版本
  • 支持完整 Markdown 语法
  • 苹果设计风格
  • 自动目录生成
  • 书籍级排版质量

花叔出品 | AI Native Coder · 独立开发者 公众号「花叔」| 30万+粉丝 | AI工具与效率提升 代表作:小猫补光灯(AppStore付费榜Top1)·《一本书玩转DeepSeek》
  • Initial release
  • Supports full Markdown syntax
  • Apple design style
  • Automatic table of contents generation
  • Book-level typesetting quality

Produced by Uncle Hua | AI Native Coder · Independent Developer Official Account "Uncle Hua" | 300,000+ followers | AI Tools & Efficiency Improvement Masterpieces: Kitty Fill Light (Top 1 in AppStore Paid Charts) · Mastering DeepSeek in One Book