diff --git a/src/style.rs b/src/style.rs index 37eb791..ee57581 100644 --- a/src/style.rs +++ b/src/style.rs @@ -40,7 +40,7 @@ impl StyleProfile { name: "宽松".into(), alignment: TextAlignment::Left, line_spacing: 1.0, - paragraph_spacing: 1.0, + paragraph_spacing: 2.0, first_line_indent: 2.0, font_size: 26.0, }, @@ -67,12 +67,13 @@ impl StyleProfile { } fn apply_para_spacing(text: &str, spacing: f32) -> String { - if spacing <= 0.0 { - return text.to_string(); + let blank_lines = spacing.round().max(0.0) as usize; + if blank_lines == 0 { + return text.to_string(); // 保留 strip_html 输出的 \n\n,即 1 行空白 } - // spacing 表示额外空白行数:基础换行 \n\n 已有1行空白,再加 spacing 行 - let newlines = 2 + spacing.round().max(0.0) as usize; - let sep = "\n".repeat(newlines); + // spacing 直接表示段落间空白行数(1行=1空行,2行=2空行) + let total_nl = blank_lines + 1; + let sep = "\n".repeat(total_nl); text.replace("\n\n", &sep) }