改进标题渲染:按层级差异化显示(字号/加粗/间距/对齐)

This commit is contained in:
Developer
2026-05-17 22:06:53 +08:00
parent afa8ea6ce7
commit 6bd96cd913
3 changed files with 101 additions and 30 deletions

View File

@@ -65,10 +65,11 @@ pub fn strip_html(input: &str) -> String {
// Emit text before the tag
if tag_start > pos {
let text = decode_entities(&input[pos..tag_start]);
if heading_level.is_some() {
out.push_str("\x01");
if let Some(level) = heading_level {
out.push('\x01');
out.push(char::from_digit(level, 10).unwrap_or('1'));
out.push_str(&text);
out.push_str("\x02");
out.push('\x02');
} else {
out.push_str(&text);
}
@@ -182,7 +183,7 @@ pub struct TocEntry {
#[derive(Debug, Clone)]
pub struct ContentBlock {
pub text: String,
pub is_heading: bool,
pub heading_level: u8, // 0 = body, 1-6 = h1-h6
}
#[derive(Debug, Clone)]