Add children to heading.

This commit is contained in:
Tom Alexander
2023-10-27 18:59:40 -04:00
parent bd982fb62d
commit c279bad13a
62 changed files with 406 additions and 203 deletions

View File

@@ -6,6 +6,7 @@ use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IHeading;
use super::RenderDocumentElement;
use super::RenderObject;
#[derive(Debug, Serialize)]
@@ -14,23 +15,46 @@ use super::RenderObject;
pub(crate) struct RenderHeading {
level: organic::types::HeadlineLevel,
title: Vec<RenderObject>,
children: Vec<RenderDocumentElement>,
}
impl RenderHeading {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
pub(crate) fn new(
config: &Config,
output_directory: D,
output_file: F,
output_directory: &Path,
output_file: &Path,
heading: &IHeading,
) -> Result<RenderHeading, CustomError> {
let title = heading
.title
.iter()
.map(|obj| RenderObject::new(config, &output_directory, &output_file, obj))
.collect::<Result<Vec<_>, _>>()?;
let title = {
let mut ret = Vec::new();
for obj in heading.title.iter() {
ret.push(RenderObject::new(
config,
&output_directory,
&output_file,
obj,
)?);
}
ret
};
let children = {
let mut ret = Vec::new();
for obj in heading.children.iter() {
ret.push(RenderDocumentElement::new(
config,
&output_directory,
&output_file,
obj,
)?);
}
ret
};
Ok(RenderHeading {
level: heading.level,
level: heading.level + 1, // Adding 1 because the page title is going to be h1.
title,
children,
})
}
}