natter/src/context/heading.rs
Tom Alexander ae933b491e
Use macros for the intermediate to render step.
This is largely to make changing the type signature of these functions easier by significantly reducing the amount of places that duplicates the signature.
2023-10-31 19:48:05 -04:00

63 lines
1.4 KiB
Rust

use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IHeading;
use super::macros::render;
use super::RenderDocumentElement;
use super::RenderObject;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "heading")]
pub(crate) struct RenderHeading {
level: organic::types::HeadlineLevel,
title: Vec<RenderObject>,
children: Vec<RenderDocumentElement>,
}
render!(
RenderHeading,
IHeading,
original,
config,
output_directory,
output_file,
{
let title = {
let mut ret = Vec::new();
for obj in original.title.iter() {
ret.push(RenderObject::new(
config,
output_directory,
output_file,
obj,
)?);
}
ret
};
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(RenderDocumentElement::new(
config,
output_directory,
output_file,
obj,
)?);
}
ret
};
Ok(RenderHeading {
level: original.level + 1, // Adding 1 because the page title is going to be h1.
title,
children,
})
}
);