
This module is mostly the intermediate representation of the AST, so the renaming is to make that more clear. The three forms are parsed => intermediate => render. Parsed comes from Organic and is a direct translation of the org-mode text. Intermediate converts the parsed data into owned values and does any calculations that are needed on the data (for example: assigning numbers to footnotes.) Render takes intermediate and translates it into the format expected by the dust templates. The processing in this step should be minimal since all the logic should be in the intermediate step.
37 lines
882 B
Rust
37 lines
882 B
Rust
use std::path::Path;
|
|
|
|
use serde::Serialize;
|
|
|
|
use crate::config::Config;
|
|
use crate::error::CustomError;
|
|
use crate::intermediate::IHeading;
|
|
|
|
use super::RenderObject;
|
|
|
|
#[derive(Debug, Serialize)]
|
|
#[serde(tag = "type")]
|
|
#[serde(rename = "heading")]
|
|
pub(crate) struct RenderHeading {
|
|
level: organic::types::HeadlineLevel,
|
|
title: Vec<RenderObject>,
|
|
}
|
|
|
|
impl RenderHeading {
|
|
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
|
|
config: &Config,
|
|
output_directory: D,
|
|
output_file: F,
|
|
heading: &IHeading,
|
|
) -> Result<RenderHeading, CustomError> {
|
|
let title = heading
|
|
.title
|
|
.iter()
|
|
.map(|obj| RenderObject::new(config, &output_directory, &output_file, obj))
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
Ok(RenderHeading {
|
|
level: heading.level,
|
|
title,
|
|
})
|
|
}
|
|
}
|