');
let num_children = branch.children.len();
for i in 0..num_children {
let child_id = self.treehouse().tree.branch(branch_id).children[i];
self.branch(s, child_id);
}
s.push_str("
");
}
fn preprocess_markup(&self, branch_id: SemaBranchId) -> String {
let branch = self.treehouse().tree.branch(branch_id);
let raw_block_content =
&self.treehouse().source(self.file_id).input()[branch.content.clone()];
let mut markup = String::with_capacity(raw_block_content.len());
for line in raw_block_content.lines() {
// Bit of a jank way to remove at most branch.indent_level spaces from the front.
let mut space_count = 0;
for i in 0..branch.indent_level {
if line.as_bytes().get(i).copied() == Some(b' ') {
space_count += 1;
} else {
break;
}
}
markup.push_str(&line[space_count..]);
markup.push('\n');
}
if branch.attributes.template {
markup = mini_template::render(self.config(), self.treehouse(), self.dirs, &markup);
}
markup
}
pub fn branch(&self, s: &mut String, branch_id: SemaBranchId) {
let branch = self.treehouse().tree.branch(branch_id);
if !cfg!(debug_assertions) && branch.attributes.stage == Stage::Draft {
return;
}
let has_children = match !branch.children.is_empty()
|| matches!(branch.attributes.content, Content::ResolvedLink(_))
{
true => HasChildren::Yes,
false => HasChildren::No,
};
let linked_tree = match branch.attributes.content {
Content::Inline | Content::Link(_) => None,
Content::ResolvedLink(file_id) => self.treehouse().tree_path(file_id),
};
self.open_branch(s, &branch.html_id);
{
// data-cast
self.attr_cast_begin(s);
self.attr_cast_push(
s,
match linked_tree {
Some(_) => "b-linked",
None => "b",
},
);
if !branch.attributes.cast.is_empty() {
self.attr_cast_push(s, &branch.attributes.cast);
}
self.attr_cast_end(s);
// th-link
if let Some(tree_path) = linked_tree {
self.attr_link(s, tree_path);
}
// class
self.attr_class_begin(s, has_children);
if !branch.attributes.classes.branch.is_empty() {
self.attr_class_push(s, &branch.attributes.classes.branch);
}
if branch.attributes.stage == Stage::Draft {
self.attr_class_push(s, "draft");
}
self.attr_class_end(s);
// th-do-not-persist
if branch.attributes.do_not_persist {
self.attr_do_not_persist(s);
}
}
self.end_attrs(s);
let open = self.begin_container(s, has_children, branch.kind);
{
self.bullet_point(s);
self.branch_content(s, &self.preprocess_markup(branch_id), linked_tree);
let date_time = branch.attributes.timestamp();
let link_button = match linked_tree {
Some(_) => LinkButton::Tree,
None => LinkButton::Branch,
};
let link = match linked_tree {
Some(tree_path) => format!("{}/{}", self.config().site, tree_path),
None => format!("{}/b?{}", self.config().site, &branch.named_id),
};
self.button_bar(s, date_time, link_button, &link);
if self.begin_children(s, &open) == HasChildren::Yes {
self.branch_children(s, branch_id);
}
}
self.close_branch(s, open);
}
pub fn root(&self, s: &mut String) {
let roots = self
.treehouse()
.roots
.get(&self.file_id)
.expect("tree should have been added to the treehouse");
s.push_str("
");
for &child in &roots.branches {
self.branch(s, child);
}
let path = self.treehouse().path(self.file_id);
let children_path = if path == const { VPath::new_const("index.tree") } {
VPath::ROOT
} else {
path
};
let tree_path = children_path.with_extension("");
let child_pages = self.get_child_pages(&tree_path);
if !child_pages.is_empty() {
s.push_str(r#"