Add paragraph.

This commit is contained in:
Tom Alexander
2023-10-27 15:46:16 -04:00
parent 5b34942b64
commit 4a6948cde7
7 changed files with 83 additions and 8 deletions

View File

@@ -6,9 +6,13 @@ use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IElement;
use super::paragraph::RenderParagraph;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderElement {}
pub(crate) enum RenderElement {
Paragraph(RenderParagraph),
}
impl RenderElement {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
@@ -17,6 +21,13 @@ impl RenderElement {
output_file: F,
element: &IElement,
) -> Result<RenderElement, CustomError> {
todo!()
match element {
IElement::Paragraph(inner) => Ok(RenderElement::Paragraph(RenderParagraph::new(
config,
output_directory,
output_file,
inner,
)?)),
}
}
}

View File

@@ -4,6 +4,7 @@ mod element;
mod global_settings;
mod heading;
mod object;
mod paragraph;
mod plain_text;
mod section;
mod target;

32
src/context/paragraph.rs Normal file
View File

@@ -0,0 +1,32 @@
use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IParagraph;
use super::RenderObject;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "heading")]
pub(crate) struct RenderParagraph {
children: Vec<RenderObject>,
}
impl RenderParagraph {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
paragraph: &IParagraph,
) -> Result<RenderParagraph, CustomError> {
let children = paragraph
.children
.iter()
.map(|obj| RenderObject::new(config, &output_directory, &output_file, obj))
.collect::<Result<Vec<_>, _>>()?;
Ok(RenderParagraph { children })
}
}