diff --git a/src/main.rs b/src/main.rs index 02801ca..7ace602 100644 --- a/src/main.rs +++ b/src/main.rs @@ -645,6 +645,7 @@ fn handle_relative_connection( } enum SectionInfo { + Lines(Vec), Game(IndexMap, Box>), Description, Comment(Vec), @@ -653,7 +654,6 @@ fn handle_relative_connection( #[derive(Default)] struct Section { title: Box, - lines: Vec, info: Option, } @@ -671,7 +671,6 @@ fn handle_relative_connection( if let Some(config_map) = config_map { sections.push(Section { title: "Game".into(), - lines: Vec::new(), info: Some(SectionInfo::Game(config_map)), }); } else { @@ -679,42 +678,44 @@ fn handle_relative_connection( unreachable!(); }; - let mut current_section = Section::default(); + let mut current_title: Box = "".into(); + let mut current_lines = Vec::new(); for line in BufReader::new(pk_file).lines() { let Ok(line) = line else { continue; }; if let Some(title) = line.strip_prefix("# ") { - if !current_section.title.is_empty() { - sections.push(current_section); + if !current_title.is_empty() { + sections.push(Section { + title: current_title, + info: Some(SectionInfo::Lines(current_lines)), + }) } - current_section = Section { - title: title.into(), - lines: vec![line], - info: None, - }; + current_title = title.into(); + current_lines = vec![line]; continue; } - current_section.lines.push(line); + current_lines.push(line); } - sections.push(current_section); + sections.push(Section { + title: current_title, + info: Some(SectionInfo::Lines(current_lines)), + }) } if file_paths.pki.is_some() { sections.push(Section { title: "Description".into(), - lines: Vec::new(), info: Some(SectionInfo::Description), }); } sections.push(Section { title: "Comments".into(), - lines: Vec::new(), info: Some(SectionInfo::Comment(comments)), }); @@ -798,21 +799,21 @@ fn handle_relative_connection( } let _ = write!(stream, ""); - for (i, Section { lines, info, .. }) in sections.into_iter().enumerate() { + for (i, Section { info, .. }) in sections.into_iter().enumerate() { let index = i + 1; let _ = write!(stream, r#"
"#); - if !lines.is_empty() { - convert_extended( - lines, - &mut stream, - Settings::default() - .with_handler(entry_handler(path, relative_path, censored)) - .with_start_level(start_level) - .with_use_textboxes(true), - ); - } if let Some(info) = info { match info { + SectionInfo::Lines(lines) => { + convert_extended( + lines, + &mut stream, + Settings::default() + .with_handler(entry_handler(path, relative_path, censored)) + .with_start_level(start_level) + .with_use_textboxes(true), + ); + } SectionInfo::Game(config_map) => { if render_novel( config_map,