From 1870defa2b8c43e11bbf80a8241dd961e20a1f49 Mon Sep 17 00:00:00 2001 From: p11 Date: Thu, 29 May 2025 23:37:51 +0200 Subject: [PATCH] Added basic tab support --- src/main.rs | 132 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d0c16d5..3aa0ec3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -669,16 +669,132 @@ fn handle_relative_connection( unreachable!(); }; - let lines = BufReader::new(pk_file).lines(); + #[derive(Default)] + struct Section { + title: Box, + lines: Vec, + } - convert_extended( - lines.map(Result::unwrap_or_default), - &mut stream, - Settings::default() - .with_handler(entry_handler(path, relative_path, censored)) - .with_start_level(start_level) - .with_use_textboxes(true), + let mut sections = Vec::new(); + + let mut current_section = Section::default(); + + 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); + } + current_section = Section { + title: title.into(), + lines: vec![line], + }; + + continue; + } + + current_section.lines.push(line); + } + + sections.push(current_section); + + let count = sections.len(); + + let _ = write!(stream, ""); + + let _ = write!(stream, r#"
"#); + + let _ = write!( + stream, + r#""# + ); + for i in 2..=count { + let _ = write!( + stream, + r#""# + ); + } + + let _ = write!(stream, r#"
"#); + for (i, Section { title, .. }) in sections.iter().enumerate() { + let index = i + 1; + let _ = write!( + stream, + r#""# + ); + } + let _ = write!(stream, "
"); + + for (i, Section { lines, .. }) in sections.iter().enumerate() { + let index = i + 1; + let _ = write!(stream, r#"
"#); + convert_extended( + lines, + &mut stream, + Settings::default() + .with_handler(entry_handler(path, relative_path, censored)) + .with_start_level(start_level) + .with_use_textboxes(true), + ); + let _ = write!(stream, "
"); + } + + let _ = write!(stream, "
"); } section(&mut stream);