Reworked lines tabs
This commit is contained in:
parent
3e6ba8ac02
commit
ce23dcf455
51
src/main.rs
51
src/main.rs
@ -645,6 +645,7 @@ fn handle_relative_connection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum SectionInfo {
|
enum SectionInfo {
|
||||||
|
Lines(Vec<String>),
|
||||||
Game(IndexMap<Box<str>, Box<str>>),
|
Game(IndexMap<Box<str>, Box<str>>),
|
||||||
Description,
|
Description,
|
||||||
Comment(Vec<Comment>),
|
Comment(Vec<Comment>),
|
||||||
@ -653,7 +654,6 @@ fn handle_relative_connection(
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Section {
|
struct Section {
|
||||||
title: Box<str>,
|
title: Box<str>,
|
||||||
lines: Vec<String>,
|
|
||||||
info: Option<SectionInfo>,
|
info: Option<SectionInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,7 +671,6 @@ fn handle_relative_connection(
|
|||||||
if let Some(config_map) = config_map {
|
if let Some(config_map) = config_map {
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: "Game".into(),
|
title: "Game".into(),
|
||||||
lines: Vec::new(),
|
|
||||||
info: Some(SectionInfo::Game(config_map)),
|
info: Some(SectionInfo::Game(config_map)),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -679,42 +678,44 @@ fn handle_relative_connection(
|
|||||||
unreachable!();
|
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() {
|
for line in BufReader::new(pk_file).lines() {
|
||||||
let Ok(line) = line else {
|
let Ok(line) = line else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let Some(title) = line.strip_prefix("# ") {
|
if let Some(title) = line.strip_prefix("# ") {
|
||||||
if !current_section.title.is_empty() {
|
if !current_title.is_empty() {
|
||||||
sections.push(current_section);
|
sections.push(Section {
|
||||||
|
title: current_title,
|
||||||
|
info: Some(SectionInfo::Lines(current_lines)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
current_section = Section {
|
current_title = title.into();
|
||||||
title: title.into(),
|
current_lines = vec![line];
|
||||||
lines: vec![line],
|
|
||||||
info: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
continue;
|
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() {
|
if file_paths.pki.is_some() {
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: "Description".into(),
|
title: "Description".into(),
|
||||||
lines: Vec::new(),
|
|
||||||
info: Some(SectionInfo::Description),
|
info: Some(SectionInfo::Description),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: "Comments".into(),
|
title: "Comments".into(),
|
||||||
lines: Vec::new(),
|
|
||||||
info: Some(SectionInfo::Comment(comments)),
|
info: Some(SectionInfo::Comment(comments)),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -798,21 +799,21 @@ fn handle_relative_connection(
|
|||||||
}
|
}
|
||||||
let _ = write!(stream, "</div>");
|
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 index = i + 1;
|
||||||
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
|
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
|
||||||
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 {
|
if let Some(info) = info {
|
||||||
match 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) => {
|
SectionInfo::Game(config_map) => {
|
||||||
if render_novel(
|
if render_novel(
|
||||||
config_map,
|
config_map,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user