Reworked lines tabs

This commit is contained in:
p11 2025-05-30 00:20:50 +02:00
parent 3e6ba8ac02
commit ce23dcf455

View File

@ -645,6 +645,7 @@ fn handle_relative_connection(
}
enum SectionInfo {
Lines(Vec<String>),
Game(IndexMap<Box<str>, Box<str>>),
Description,
Comment(Vec<Comment>),
@ -653,7 +654,6 @@ fn handle_relative_connection(
#[derive(Default)]
struct Section {
title: Box<str>,
lines: Vec<String>,
info: Option<SectionInfo>,
}
@ -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<str> = "".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,10 +799,12 @@ fn handle_relative_connection(
}
let _ = write!(stream, "</div>");
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#"<div class="tab-content" id="content-{index}">"#);
if !lines.is_empty() {
if let Some(info) = info {
match info {
SectionInfo::Lines(lines) => {
convert_extended(
lines,
&mut stream,
@ -811,8 +814,6 @@ fn handle_relative_connection(
.with_use_textboxes(true),
);
}
if let Some(info) = info {
match info {
SectionInfo::Game(config_map) => {
if render_novel(
config_map,