Skip to content

Commit 1da55a7

Browse files
committed
Fix CI and docs
1 parent 6b0425e commit 1da55a7

File tree

11 files changed

+80
-40
lines changed

11 files changed

+80
-40
lines changed

cmd/doctor_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"os"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011
"testing"
1112

@@ -767,9 +768,16 @@ func TestCheckPluginsWithValidPlugin(t *testing.T) {
767768
t.Fatalf("failed to create plugins directory: %v", err)
768769
}
769770

771+
pluginName := "test"
772+
pluginContent := []byte("#!/bin/sh\necho test")
773+
if runtime.GOOS == "windows" {
774+
pluginName = "test.bat"
775+
pluginContent = []byte("@echo off\r\necho test\r\n")
776+
}
777+
770778
// Create an executable file
771-
pluginPath := filepath.Join(pluginDir, "test")
772-
if err := os.WriteFile(pluginPath, []byte("#!/bin/sh\necho test"), 0755); err != nil {
779+
pluginPath := filepath.Join(pluginDir, pluginName)
780+
if err := os.WriteFile(pluginPath, pluginContent, 0755); err != nil {
773781
t.Fatalf("failed to create plugin: %v", err)
774782
}
775783

@@ -781,7 +789,7 @@ chapters:
781789
file: "ch1.md"
782790
plugins:
783791
- name: test-plugin
784-
path: ./plugins/test
792+
path: ./plugins/` + pluginName + `
785793
`
786794
if err := os.WriteFile(filepath.Join(tmpDir, "book.yaml"), []byte(bookYAML), 0644); err != nil {
787795
t.Fatalf("failed to create book.yaml: %v", err)

cmd/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ func TestInstallNewVersionFlow(t *testing.T) {
684684
t.Fatalf("failed to stat binary: %v", err)
685685
}
686686
mode := info.Mode()
687-
if mode&0100 == 0 {
687+
if runtime.GOOS != "windows" && mode&0100 == 0 {
688688
t.Errorf("binary is not executable by owner")
689689
}
690690
})

docs/manual/en/best-practices/ci-cd.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Setup Go
3636
uses: actions/setup-go@v4
3737
with:
38-
go-version: '1.21'
38+
go-version: '1.25'
3939
cache: 'go'
4040

4141
- name: Install mdPress
@@ -98,7 +98,7 @@ jobs:
9898

9999
- uses: actions/setup-go@v4
100100
with:
101-
go-version: '1.21'
101+
go-version: '1.25'
102102
cache: 'go'
103103

104104
- name: Install mdPress
@@ -146,7 +146,7 @@ jobs:
146146

147147
- uses: actions/setup-go@v4
148148
with:
149-
go-version: '1.21'
149+
go-version: '1.25'
150150
cache: 'go'
151151

152152
- run: go install github.com/yeasy/mdpress@latest
@@ -262,8 +262,8 @@ build-protected:
262262
**Linux (Ubuntu/Debian):**
263263
```bash
264264
# Install Go
265-
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
266-
tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
265+
wget https://go.dev/dl/go1.25.0.linux-amd64.tar.gz
266+
tar -C /usr/local -xzf go1.25.0.linux-amd64.tar.gz
267267
export PATH=$PATH:/usr/local/go/bin
268268
269269
# Install mdPress
@@ -281,7 +281,7 @@ go install github.com/yeasy/mdpress@latest
281281

282282
**Docker:**
283283
```dockerfile
284-
FROM golang:1.21-alpine
284+
FROM golang:1.25-alpine
285285
286286
# Install Chrome for PDF rendering
287287
RUN apk add --no-cache chromium
@@ -354,7 +354,7 @@ brew install font-noto-sans-cjk
354354
```yaml
355355
- uses: actions/setup-go@v4
356356
with:
357-
go-version: '1.21'
357+
go-version: '1.25'
358358
cache: 'go' # Automatically caches Go modules
359359
360360
- name: Download modules
@@ -651,7 +651,7 @@ jobs:
651651
- uses: actions/checkout@v4
652652
- uses: actions/setup-go@v4
653653
with:
654-
go-version: '1.21'
654+
go-version: '1.25'
655655
- run: go install github.com/yeasy/mdpress@latest
656656
- run: mdpress validate
657657
@@ -663,7 +663,7 @@ jobs:
663663
- uses: actions/checkout@v4
664664
- uses: actions/setup-go@v4
665665
with:
666-
go-version: '1.21'
666+
go-version: '1.25'
667667
- run: go install github.com/yeasy/mdpress@latest
668668
- run: mdpress build --format html
669669
- uses: actions/upload-artifact@v3
@@ -682,7 +682,7 @@ jobs:
682682
- uses: actions/checkout@v4
683683
- uses: actions/setup-go@v4
684684
with:
685-
go-version: '1.21'
685+
go-version: '1.25'
686686
- run: go install github.com/yeasy/mdpress@latest
687687
- uses: actions/cache@v3
688688
with:
@@ -702,7 +702,7 @@ jobs:
702702
- uses: actions/checkout@v4
703703
- uses: actions/setup-go@v4
704704
with:
705-
go-version: '1.21'
705+
go-version: '1.25'
706706
- run: go install github.com/yeasy/mdpress@latest
707707
- run: mdpress build --format site
708708
- uses: actions/upload-pages-artifact@v2

docs/manual/en/plugins/lifecycle-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ Fires once when the development server starts, before watching for file changes.
558558
"context": {
559559
"phase": "serve",
560560
"server_host": "localhost",
561-
"server_port": 8000,
561+
"server_port": 9000,
562562
"watch_paths": ["chapters/", "docs/"]
563563
}
564564
}

docs/manual/zh/best-practices/ci-cd.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Setup Go
3636
uses: actions/setup-go@v4
3737
with:
38-
go-version: '1.21'
38+
go-version: '1.25'
3939
cache: 'go'
4040

4141
- name: Install mdPress
@@ -98,7 +98,7 @@ jobs:
9898

9999
- uses: actions/setup-go@v4
100100
with:
101-
go-version: '1.21'
101+
go-version: '1.25'
102102
cache: 'go'
103103

104104
- name: Install mdPress
@@ -146,7 +146,7 @@ jobs:
146146

147147
- uses: actions/setup-go@v4
148148
with:
149-
go-version: '1.21'
149+
go-version: '1.25'
150150
cache: 'go'
151151

152152
- run: go install github.com/yeasy/mdpress@latest
@@ -262,8 +262,8 @@ build-protected:
262262
**Linux (Ubuntu/Debian):**
263263
```bash
264264
# 安装 Go
265-
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
266-
tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
265+
wget https://go.dev/dl/go1.25.0.linux-amd64.tar.gz
266+
tar -C /usr/local -xzf go1.25.0.linux-amd64.tar.gz
267267
export PATH=$PATH:/usr/local/go/bin
268268
269269
# 安装 mdPress
@@ -281,7 +281,7 @@ go install github.com/yeasy/mdpress@latest
281281

282282
**Docker:**
283283
```dockerfile
284-
FROM golang:1.21-alpine
284+
FROM golang:1.25-alpine
285285
286286
# 安装 Chrome 用于 PDF 渲染
287287
RUN apk add --no-cache chromium
@@ -354,7 +354,7 @@ brew install font-noto-sans-cjk
354354
```yaml
355355
- uses: actions/setup-go@v4
356356
with:
357-
go-version: '1.21'
357+
go-version: '1.25'
358358
cache: 'go' # 自动缓存 Go 模块
359359
360360
- name: Download modules
@@ -651,7 +651,7 @@ jobs:
651651
- uses: actions/checkout@v4
652652
- uses: actions/setup-go@v4
653653
with:
654-
go-version: '1.21'
654+
go-version: '1.25'
655655
- run: go install github.com/yeasy/mdpress@latest
656656
- run: mdpress validate
657657
@@ -663,7 +663,7 @@ jobs:
663663
- uses: actions/checkout@v4
664664
- uses: actions/setup-go@v4
665665
with:
666-
go-version: '1.21'
666+
go-version: '1.25'
667667
- run: go install github.com/yeasy/mdpress@latest
668668
- run: mdpress build --format html
669669
- uses: actions/upload-artifact@v3
@@ -682,7 +682,7 @@ jobs:
682682
- uses: actions/checkout@v4
683683
- uses: actions/setup-go@v4
684684
with:
685-
go-version: '1.21'
685+
go-version: '1.25'
686686
- run: go install github.com/yeasy/mdpress@latest
687687
- uses: actions/cache@v3
688688
with:
@@ -702,7 +702,7 @@ jobs:
702702
- uses: actions/checkout@v4
703703
- uses: actions/setup-go@v4
704704
with:
705-
go-version: '1.21'
705+
go-version: '1.25'
706706
- run: go install github.com/yeasy/mdpress@latest
707707
- run: mdpress build --format site
708708
- uses: actions/upload-pages-artifact@v2

docs/manual/zh/getting-started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mdpress --version
4343
```bash
4444
git clone https://github.com/yeasy/mdpress.git
4545
cd mdpress
46-
go build -o mdpress ./cmd/mdpress
46+
go build -o mdpress .
4747
```
4848

4949
将二进制文件复制到 PATH 中的某个位置,或直接使用它:

docs/manual/zh/plugins/lifecycle-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ if request.get("hook") == "after_build":
558558
"context": {
559559
"phase": "serve",
560560
"server_host": "localhost",
561-
"server_port": 8000,
561+
"server_port": 9000,
562562
"watch_paths": ["chapters/", "docs/"]
563563
}
564564
}

internal/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ func (c *BookConfig) Validate() error {
282282
return fmt.Errorf("toc_max_depth must be between 1 and 6 (got %d)", c.Output.TOCMaxDepth)
283283
}
284284

285+
// Validate WatermarkOpacity range (0.0-1.0, or 0 for not set).
286+
if c.Output.WatermarkOpacity != 0 && (c.Output.WatermarkOpacity < 0.0 || c.Output.WatermarkOpacity > 1.0) {
287+
return fmt.Errorf("watermark_opacity must be between 0.0 and 1.0 (got %f)", c.Output.WatermarkOpacity)
288+
}
289+
290+
// Validate PDFTimeout range (5-3600 seconds, or 0 for default).
291+
if c.Output.PDFTimeout != 0 && (c.Output.PDFTimeout < 5 || c.Output.PDFTimeout > 3600) {
292+
return fmt.Errorf("pdf_timeout must be between 5 and 3600 seconds (got %d)", c.Output.PDFTimeout)
293+
}
294+
285295
return nil
286296
}
287297

internal/plugin/external_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ func TestResolveWindowsExecutableSuffix_NoExtension(t *testing.T) {
591591
if resolved == "" {
592592
t.Fatal("expected resolved path")
593593
}
594-
if resolved != exePath {
594+
if !strings.EqualFold(resolved, exePath) {
595595
t.Errorf("resolved = %q, want %q", resolved, exePath)
596596
}
597597
}
@@ -616,7 +616,7 @@ func TestResolveWindowsExecutableSuffix_SkipsDirectories(t *testing.T) {
616616
if resolved == "" {
617617
t.Fatal("expected resolved path")
618618
}
619-
if resolved != exePath {
619+
if !strings.EqualFold(resolved, exePath) {
620620
t.Errorf("resolved = %q, want %q", resolved, exePath)
621621
}
622622
}
@@ -658,7 +658,7 @@ func TestResolveWindowsExecutableSuffix_MultipleExtensions(t *testing.T) {
658658
validPaths := []string{batPath, exePath, cmdPath}
659659
found := false
660660
for _, valid := range validPaths {
661-
if resolved == valid {
661+
if strings.EqualFold(resolved, valid) {
662662
found = true
663663
break
664664
}
@@ -736,7 +736,7 @@ func TestResolveWindowsExecutableSuffix_TableDriven(t *testing.T) {
736736
if resolved == "" {
737737
t.Fatal("expected resolved path, got empty string")
738738
}
739-
if expectedExt != "" && !strings.HasSuffix(resolved, expectedExt) {
739+
if expectedExt != "" && !strings.HasSuffix(strings.ToLower(resolved), strings.ToLower(expectedExt)) {
740740
t.Errorf("resolved = %q, expected to end with %q", resolved, expectedExt)
741741
}
742742
} else if resolved != "" {

internal/typst/converter.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ func (c *MarkdownToTypstConverter) replaceLinks(text string) string {
214214
}
215215
closeBracket++ // Adjust for the +1 offset
216216

217+
// Bounds check: ensure i+closeBracket is within bounds
218+
if i+closeBracket >= len(text) {
219+
result.WriteString(text[i:])
220+
break
221+
}
222+
217223
linkText := text[i+1 : i+closeBracket]
218224

219225
// Check if followed by (url)
@@ -277,6 +283,12 @@ func (c *MarkdownToTypstConverter) convertItalic(text string) string {
277283
closeIdx := strings.Index(text[i+1:], "_")
278284
if closeIdx != -1 {
279285
closeIdx++ // Adjust for the +1 offset
286+
// Bounds check: ensure i+closeIdx is within bounds
287+
if i+closeIdx >= len(text) {
288+
result.WriteByte(text[i])
289+
i++
290+
continue
291+
}
280292
// Make sure it's not part of __
281293
if (i > 0 && text[i-1] == '_') || (i+closeIdx+1 < len(text) && text[i+closeIdx+1] == '_') {
282294
result.WriteByte(text[i])

0 commit comments

Comments
 (0)