This commit is contained in:
りき萌 2024-02-12 19:56:06 +01:00
parent 81018eeafe
commit f2e9a5f66e
11 changed files with 126 additions and 16 deletions

View file

@ -203,6 +203,7 @@ impl Generator {
pub title: String,
pub thumbnail: Option<Thumbnail>,
pub scripts: Vec<String>,
pub styles: Vec<String>,
pub breadcrumbs: String,
pub tree_path: Option<String>,
pub tree: String,
@ -240,6 +241,7 @@ impl Generator {
alt: thumbnail.alt.clone(),
}),
scripts: roots.attributes.scripts.clone(),
styles: roots.attributes.styles.clone(),
breadcrumbs,
tree_path: treehouse
.tree_path(parsed_tree.file_id)

View file

@ -158,7 +158,16 @@ pub fn branch_to_html(
if has_children {
s.push_str("</summary>");
{
s.push_str("<ul>");
s.push_str("<ul");
if !branch.attributes.classes.branch_children.is_empty() {
write!(
s,
" class=\"{}\"",
EscapeAttribute(&branch.attributes.classes.branch_children)
)
.unwrap();
}
s.push('>');
let num_children = branch.children.len();
for i in 0..num_children {
let child_id = treehouse.tree.branch(branch_id).children[i];

View file

@ -21,6 +21,11 @@ pub struct RootAttributes {
/// These are relative to the /static/js directory.
#[serde(default)]
pub scripts: Vec<String>,
/// Additional styles to load into to the page.
/// These are relative to the /static/css directory.
#[serde(default)]
pub styles: Vec<String>,
}
/// A picture reference.
@ -51,6 +56,10 @@ pub struct Attributes {
/// Do not persist the branch in localStorage.
#[serde(default)]
pub do_not_persist: bool,
/// Strings of extra CSS class names to include in the generated HTML.
#[serde(default)]
pub classes: Classes,
}
/// Controls for block content presentation.
@ -76,3 +85,10 @@ pub enum Content {
/// children, an `attribute`-type error is raised.
Link(String),
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize)]
pub struct Classes {
/// Classes to append to the branch's <ul> element containing its children.
#[serde(default)]
pub branch_children: String,
}