Skip to content

Commit 87ed1d6

Browse files
committed
Improve code quality and translations
1 parent 7815b9c commit 87ed1d6

File tree

23 files changed

+278
-296
lines changed

23 files changed

+278
-296
lines changed

cmd/chapter_pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (p *ChapterPipeline) ProcessWithOptions(ctx context.Context, options Chapte
412412
Content: htmlContent,
413413
ChapterIndex: i,
414414
ChapterFile: chDef.File,
415-
Metadata: make(map[string]interface{}),
415+
Metadata: make(map[string]any),
416416
}
417417
if err := p.PluginManager.RunHook(hookCtx); err != nil {
418418
p.Logger.Warn("AfterParse plugin hook failed", slog.String("file", chDef.File), slog.String("error", err.Error()))

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
var (
1515
// Version is overridden at build time via -ldflags.
16-
Version = "0.6.1"
16+
Version = "0.6.2"
1717
// BuildTime is overridden at build time via -ldflags.
1818
BuildTime = "unknown"
1919
// rootCmd is the root command for the mdpress application.

examples/chapter01/README.md

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,65 @@
1-
# 第一章 快速开始 / Chapter 1: Quick Start
1+
# Chapter 1: Quick Start
22

3-
本章将帮助你快速上手 mdpress,从安装到生成第一本 PDF 图书。
3+
This chapter helps you get started with mdpress, from installation to generating your first PDF book.
44

5-
*This chapter helps you get started with mdpress, from installation to generating your first PDF book.*
5+
## 1.1 Installation
66

7-
## 1.1 安装 / Installation
7+
### Install with Go
88

9-
### 使用 Go 安装 / Install with Go
10-
11-
确保你已安装 Go 1.21 或更高版本,然后运行:
12-
13-
*Ensure you have Go 1.21 or later installed, then run:*
9+
Ensure you have Go 1.25 or later installed, then run:
1410

1511
```bash
1612
go install github.com/yeasy/mdpress@latest
1713
```
1814

19-
### 从源码编译 / Build from Source
15+
### Build from Source
2016

2117
```bash
2218
git clone https://github.com/yeasy/mdpress.git
2319
cd mdpress
2420
make build
2521
```
2622

27-
### 前置依赖 / Prerequisites
28-
29-
mdpress 使用 Chromium 进行 PDF 渲染,请确保系统中已安装:
23+
### Prerequisites
3024

31-
*mdpress uses Chromium for PDF rendering. Ensure the following is installed:*
25+
mdpress uses Chromium for PDF rendering. Ensure the following is installed:
3226

33-
- **macOS**: `brew install chromium` 或安装 Google Chrome / or install Google Chrome
27+
- **macOS**: `brew install chromium` or install Google Chrome
3428
- **Ubuntu/Debian**: `apt install chromium-browser`
35-
- **Windows**: 安装 Google Chrome / Install Google Chrome
29+
- **Windows**: Install Google Chrome
3630

37-
## 1.2 初始化项目 / Initialize a Project
31+
## 1.2 Initialize a Project
3832

39-
在你的图书目录下运行 / Run in your book directory:
33+
Run in your book directory:
4034

4135
```bash
4236
mdpress init
4337
```
4438

45-
这将创建以下文件结构 / This creates the following file structure:
39+
This creates the following file structure:
4640

4741
```
4842
my-book/
49-
├── book.yaml # 配置文件 / Config file
50-
├── preface.md # 前言 / Preface
43+
├── book.yaml # Config file
44+
├── preface.md # Preface
5145
└── chapter01/
52-
└── README.md # 第一章 / Chapter 1
46+
└── README.md # Chapter 1
5347
```
5448

55-
## 1.3 编写内容 / Write Content
49+
## 1.3 Write Content
5650

57-
使用你喜欢的编辑器编辑 Markdown 文件。mdpress 完整支持 GitHub Flavored MarkdownGFM),包括:
51+
Edit Markdown files with your favorite editor. mdpress fully supports GitHub Flavored Markdown (GFM), including:
5852

59-
*Edit Markdown files with your favorite editor. mdpress fully supports GFM, including:*
53+
### Tables
6054

61-
### 表格 / Tables
55+
| Feature | Supported | Description |
56+
|---------|-----------|-------------|
57+
| Tables || GFM table syntax |
58+
| Task lists || `- [x]` syntax |
59+
| Footnotes || `[^1]` syntax |
60+
| Code highlighting || Multi-language support |
6261

63-
| 功能 / Feature | 支持 / Supported | 说明 / Description |
64-
|------|---------|------|
65-
| 表格 / Tables || GFM 表格语法 / GFM table syntax |
66-
| 任务列表 / Task lists || `- [x]` 语法 / `- [x]` syntax |
67-
| 脚注 / Footnotes || `[^1]` 语法 / `[^1]` syntax |
68-
| 代码高亮 / Code highlighting || 多语言支持 / Multi-language support |
69-
70-
### 代码高亮 / Code Highlighting
62+
### Code Highlighting
7163

7264
```go
7365
package main
@@ -81,37 +73,33 @@ func main() {
8173

8274
```python
8375
def hello():
84-
"""mdpress 支持多种编程语言的语法高亮 / mdpress supports syntax highlighting for many languages"""
76+
"""mdpress supports syntax highlighting for many languages"""
8577
print("Hello, mdpress!")
8678
```
8779

88-
### 任务列表 / Task Lists
80+
### Task Lists
8981

90-
- [x] 安装 mdpress / Install mdpress
91-
- [x] 创建项目结构 / Create project structure
92-
- [ ] 编写内容 / Write content
93-
- [ ] 生成 PDF / Generate PDF
82+
- [x] Install mdpress
83+
- [x] Create project structure
84+
- [ ] Write content
85+
- [ ] Generate PDF
9486

95-
## 1.4 生成 PDF / Generate PDF
87+
## 1.4 Generate PDF
9688

97-
一切就绪后,运行构建命令 / When everything is ready, run:
89+
When everything is ready, run:
9890

9991
```bash
10092
mdpress build
10193
```
10294

103-
或指定配置文件 / Or specify a config file:
95+
Or specify a config file:
10496

10597
```bash
10698
mdpress build --config path/to/book.yaml
10799
```
108100

109-
生成的 PDF 文件将保存到配置文件中 `output.filename` 指定的路径。
110-
111-
*The generated PDF will be saved to the path specified in `output.filename` in the config file.*
112-
113-
## 1.5 小结 / Summary
101+
The generated PDF will be saved to the path specified in `output.filename` in the config file.
114102

115-
恭喜!你已经成功生成了第一本 PDF 图书。接下来,请阅读第二章了解更多进阶功能。
103+
## 1.5 Summary
116104

117-
*Congratulations! You have successfully generated your first PDF book. Read Chapter 2 for more advanced features.*
105+
Congratulations! You have successfully generated your first PDF book. Read Chapter 2 for more advanced features.

examples/chapter02/README.md

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
# 第二章 进阶用法 / Chapter 2: Advanced Usage
1+
# Chapter 2: Advanced Usage
22

3-
本章介绍 mdpress 的高级功能,帮助你打造专业级的 PDF 图书。
3+
This chapter covers advanced mdpress features for creating professional-grade PDF books.
44

5-
*This chapter covers advanced mdpress features for creating professional-grade PDF books.*
5+
## 2.1 Custom Themes
66

7-
## 2.1 自定义主题 / Custom Themes
7+
mdpress comes with three built-in themes:
88

9-
mdpress 内置三套主题 / mdpress comes with three built-in themes:
9+
- **technical**: Technical docs style, ideal for programming books
10+
- **elegant**: Elegant literary style, ideal for literary works
11+
- **minimal**: Minimalist style, ideal for notes and memos
1012

11-
- **technical**:技术文档风格,适合编程书籍 / Technical docs style, ideal for programming books
12-
- **elegant**:优雅文学风格,适合文学作品 / Elegant literary style, ideal for literary works
13-
- **minimal**:极简风格,适合笔记和备忘录 / Minimalist style, ideal for notes and memos
14-
15-
`book.yaml` 中切换主题 / Switch themes in `book.yaml`:
13+
Switch themes in `book.yaml`:
1614

1715
```yaml
1816
style:
1917
theme: "elegant"
2018
```
2119
22-
### 创建自定义主题 / Creating Custom Themes
20+
### Creating Custom Themes
2321
24-
你也可以创建自己的主题文件(YAML 格式)/ You can create your own theme file (YAML format):
22+
You can create your own theme file (YAML format):
2523
2624
```yaml
2725
name: my-theme
@@ -34,32 +32,32 @@ colors:
3432
link: "#2980b9"
3533
```
3634
37-
## 2.2 交叉引用 / Cross References
35+
## 2.2 Cross References
3836
39-
mdpress 支持图表和章节的交叉引用。/ mdpress supports cross-referencing of figures, tables, and sections.
37+
mdpress supports cross-referencing of figures, tables, and sections.
4038
41-
### 图片引用 / Figure References
39+
### Figure References
4240
4341
```markdown
44-
![图片标题 / Figure caption](image.png){#fig:architecture}
42+
![Figure caption](image.png){#fig-architecture}
4543

46-
如 {{ref:fig:architecture}} 所示... / As shown in {{ref:fig:architecture}}...
44+
As shown in {{ref:fig-architecture}}...
4745
```
4846

49-
### 表格引用 / Table References
47+
### Table References
5048

5149
```markdown
52-
| 列1 / Col1 | 列2 / Col2 |
53-
|-----|-----|
54-
| a | b |
55-
{#tab:comparison}
50+
| Col1 | Col2 |
51+
|------|------|
52+
| a | b |
53+
{#tab-comparison}
5654

57-
详见 {{ref:tab:comparison}}。/ See {{ref:tab:comparison}}.
55+
See {{ref:tab-comparison}}.
5856
```
5957

60-
## 2.3 多文件组织 / Multi-file Organization
58+
## 2.3 Multi-file Organization
6159

62-
对于大型图书项目,建议按章节组织文件 / For large book projects, organize files by chapter:
60+
For large book projects, organize files by chapter:
6361

6462
```
6563
my-book/
@@ -79,38 +77,34 @@ my-book/
7977
└── references.md
8078
```
8179

82-
## 2.4 页眉页脚 / Headers & Footers
80+
## 2.4 Headers & Footers
8381

84-
自定义页眉页脚支持模板变量 / Custom headers and footers support template variables:
82+
Custom headers and footers support template variables:
8583

86-
| 变量 / Variable | 说明 / Description |
87-
|------|------|
88-
| `{{.Book.Title}}` | 书名 / Book title |
89-
| `{{.Book.Author}}` | 作者 / Author |
90-
| `{{.Chapter.Title}}` | 当前章节标题 / Current chapter title |
91-
| `{{.PageNum}}` | 当前页码 / Current page number |
84+
| Variable | Description |
85+
|----------|-------------|
86+
| `{{.Book.Title}}` | Book title |
87+
| `{{.Book.Author}}` | Author |
88+
| `{{.Chapter.Title}}` | Current chapter title |
89+
| `{{.PageNum}}` | Current page number |
9290

93-
配置示例 / Configuration example:
91+
Configuration example:
9492

9593
```yaml
9694
style:
9795
header:
9896
left: "{{.Book.Title}}"
9997
right: "{{.Chapter.Title}}"
10098
footer:
101-
center: "第 {{.PageNum}} 页 / Page {{.PageNum}}"
99+
center: "Page {{.PageNum}}"
102100
```
103101
104-
## 2.5 脚注 / Footnotes[^1]
105-
106-
mdpress 完整支持 Markdown 脚注语法,脚注会自动编号并在页面底部或章节末尾显示。
107-
108-
*mdpress fully supports Markdown footnote syntax. Footnotes are automatically numbered and displayed at the bottom of the page or end of the chapter.*
102+
## 2.5 Footnotes[^1]
109103
110-
[^1]: 这是一个脚注示例。/ This is a footnote example.
104+
mdpress fully supports Markdown footnote syntax. Footnotes are automatically numbered and displayed at the bottom of the page or end of the chapter.
111105
112-
## 2.6 小结 / Summary
106+
[^1]: This is a footnote example.
113107
114-
通过本章的学习,你已经掌握了 mdpress 的大部分高级功能。更多详细信息请参阅项目文档。
108+
## 2.6 Summary
115109
116-
*After this chapter, you have mastered most of the advanced features of mdpress. For more details, refer to the project documentation.*
110+
After this chapter, you have mastered most of the advanced features of mdpress. For more details, refer to the project documentation.

examples/plugins/word-count/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import (
2929

3030
// Request mirrors plugin.ExternalPluginRequest.
3131
type Request struct {
32-
Phase string `json:"phase"`
33-
Content string `json:"content"`
34-
ChapterIndex int `json:"chapter_index"`
35-
ChapterFile string `json:"chapter_file"`
36-
Config map[string]interface{} `json:"config"`
37-
Metadata map[string]interface{} `json:"metadata"`
32+
Phase string `json:"phase"`
33+
Content string `json:"content"`
34+
ChapterIndex int `json:"chapter_index"`
35+
ChapterFile string `json:"chapter_file"`
36+
Config map[string]any `json:"config"`
37+
Metadata map[string]any `json:"metadata"`
3838
}
3939

4040
// Response mirrors plugin.ExternalPluginResponse.

internal/config/bookjson.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
// bookJSON is the raw structure of a GitBook book.json file.
1515
// Only fields relevant to mdPress are decoded; unknown fields are silently ignored.
1616
type bookJSON struct {
17-
Title string `json:"title"`
18-
Author jsonStringOrSlice `json:"author"`
19-
Description string `json:"description"`
20-
Language string `json:"language"`
21-
GitBook string `json:"gitbook"`
22-
Plugins []string `json:"plugins"`
23-
PluginsCfg map[string]map[string]interface{} `json:"pluginsConfig"`
24-
Structure bookJSONStructure `json:"structure"`
17+
Title string `json:"title"`
18+
Author jsonStringOrSlice `json:"author"`
19+
Description string `json:"description"`
20+
Language string `json:"language"`
21+
GitBook string `json:"gitbook"`
22+
Plugins []string `json:"plugins"`
23+
PluginsCfg map[string]map[string]any `json:"pluginsConfig"`
24+
Structure bookJSONStructure `json:"structure"`
2525
}
2626

2727
// bookJSONStructure holds optional overrides for well-known GitBook file paths.
@@ -208,7 +208,7 @@ func normalizeLanguage(lang string) string {
208208

209209
// convertBookJSONPlugins maps GitBook plugin entries to PluginConfig values.
210210
// Entries prefixed with "-" are disabled in GitBook and are skipped here.
211-
func convertBookJSONPlugins(names []string, cfgs map[string]map[string]interface{}) []PluginConfig {
211+
func convertBookJSONPlugins(names []string, cfgs map[string]map[string]any) []PluginConfig {
212212
if len(names) == 0 {
213213
return nil
214214
}
@@ -221,7 +221,7 @@ func convertBookJSONPlugins(names []string, cfgs map[string]map[string]interface
221221
p := PluginConfig{Name: name}
222222
if cfgs != nil {
223223
if extra, ok := cfgs[name]; ok {
224-
p.Config = make(map[string]interface{}, len(extra))
224+
p.Config = make(map[string]any, len(extra))
225225
for k, v := range extra {
226226
p.Config[k] = v
227227
}

internal/config/discover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func ExtractReadmeMetadata(ctx context.Context, path string) ReadmeMetadata {
367367
content := allText.String()
368368

369369
// Determine book title: try to find a meaningful title that is NOT just
370-
// a generic heading like "前言" or "Preface".
370+
// a generic heading like "Preface" or "Introduction".
371371
meta.Title = inferBookTitle(h1Title, content, filepath.Dir(path))
372372

373373
// Detect language from content.

internal/config/summary.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// summary.go parses chapter structure from SUMMARY.md.
22
// SUMMARY.md uses Markdown link lists to define chapter order in a GitBook-compatible format.
33
//
4-
// 格式示例:
4+
// Format example:
55
//
66
// # Summary
77
//
8-
// * [前言](preface.md)
9-
// * [第一章](chapter01/README.md)
10-
// * [1.1 小节](chapter01/section01.md)
11-
// * [第二章](chapter02/README.md)
8+
// * [Preface](preface.md)
9+
// * [Chapter 1](chapter01/README.md)
10+
// * [Section 1.1](chapter01/section01.md)
11+
// * [Chapter 2](chapter02/README.md)
1212
package config
1313

1414
import (

0 commit comments

Comments
 (0)