Add paragraph.
This commit is contained in:
parent
5b34942b64
commit
4a6948cde7
@ -6,9 +6,13 @@ use crate::config::Config;
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::intermediate::IElement;
|
use crate::intermediate::IElement;
|
||||||
|
|
||||||
|
use super::paragraph::RenderParagraph;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub(crate) enum RenderElement {}
|
pub(crate) enum RenderElement {
|
||||||
|
Paragraph(RenderParagraph),
|
||||||
|
}
|
||||||
|
|
||||||
impl RenderElement {
|
impl RenderElement {
|
||||||
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
|
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
|
||||||
@ -17,6 +21,13 @@ impl RenderElement {
|
|||||||
output_file: F,
|
output_file: F,
|
||||||
element: &IElement,
|
element: &IElement,
|
||||||
) -> Result<RenderElement, CustomError> {
|
) -> Result<RenderElement, CustomError> {
|
||||||
todo!()
|
match element {
|
||||||
|
IElement::Paragraph(inner) => Ok(RenderElement::Paragraph(RenderParagraph::new(
|
||||||
|
config,
|
||||||
|
output_directory,
|
||||||
|
output_file,
|
||||||
|
inner,
|
||||||
|
)?)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ mod element;
|
|||||||
mod global_settings;
|
mod global_settings;
|
||||||
mod heading;
|
mod heading;
|
||||||
mod object;
|
mod object;
|
||||||
|
mod paragraph;
|
||||||
mod plain_text;
|
mod plain_text;
|
||||||
mod section;
|
mod section;
|
||||||
mod target;
|
mod target;
|
||||||
|
32
src/context/paragraph.rs
Normal file
32
src/context/paragraph.rs
Normal 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 })
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
use super::registry::Registry;
|
use super::registry::Registry;
|
||||||
|
use super::IParagraph;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum IElement {}
|
pub(crate) enum IElement {
|
||||||
|
Paragraph(IParagraph),
|
||||||
|
}
|
||||||
|
|
||||||
impl IElement {
|
impl IElement {
|
||||||
pub(crate) fn new<'parse>(
|
pub(crate) fn new<'parse>(
|
||||||
@ -11,7 +14,9 @@ impl IElement {
|
|||||||
elem: &organic::types::Element<'parse>,
|
elem: &organic::types::Element<'parse>,
|
||||||
) -> Result<IElement, CustomError> {
|
) -> Result<IElement, CustomError> {
|
||||||
match elem {
|
match elem {
|
||||||
organic::types::Element::Paragraph(_) => todo!(),
|
organic::types::Element::Paragraph(inner) => {
|
||||||
|
Ok(IElement::Paragraph(IParagraph::new(registry, inner)?))
|
||||||
|
}
|
||||||
organic::types::Element::PlainList(_) => todo!(),
|
organic::types::Element::PlainList(_) => todo!(),
|
||||||
organic::types::Element::CenterBlock(_) => todo!(),
|
organic::types::Element::CenterBlock(_) => todo!(),
|
||||||
organic::types::Element::QuoteBlock(_) => todo!(),
|
organic::types::Element::QuoteBlock(_) => todo!(),
|
||||||
|
@ -5,6 +5,7 @@ mod element;
|
|||||||
mod heading;
|
mod heading;
|
||||||
mod object;
|
mod object;
|
||||||
mod page;
|
mod page;
|
||||||
|
mod paragraph;
|
||||||
mod plain_text;
|
mod plain_text;
|
||||||
mod registry;
|
mod registry;
|
||||||
mod section;
|
mod section;
|
||||||
@ -17,6 +18,7 @@ pub(crate) use element::IElement;
|
|||||||
pub(crate) use heading::IHeading;
|
pub(crate) use heading::IHeading;
|
||||||
pub(crate) use object::IObject;
|
pub(crate) use object::IObject;
|
||||||
pub(crate) use page::BlogPostPage;
|
pub(crate) use page::BlogPostPage;
|
||||||
|
pub(crate) use paragraph::IParagraph;
|
||||||
pub(crate) use plain_text::IPlainText;
|
pub(crate) use plain_text::IPlainText;
|
||||||
pub(crate) use section::ISection;
|
pub(crate) use section::ISection;
|
||||||
pub(crate) use target::ITarget;
|
pub(crate) use target::ITarget;
|
||||||
|
@ -22,8 +22,8 @@ impl IObject {
|
|||||||
organic::types::Object::StrikeThrough(_) => todo!(),
|
organic::types::Object::StrikeThrough(_) => todo!(),
|
||||||
organic::types::Object::Code(_) => todo!(),
|
organic::types::Object::Code(_) => todo!(),
|
||||||
organic::types::Object::Verbatim(_) => todo!(),
|
organic::types::Object::Verbatim(_) => todo!(),
|
||||||
organic::types::Object::PlainText(plain_text) => {
|
organic::types::Object::PlainText(inner) => {
|
||||||
Ok(IObject::PlainText(IPlainText::new(registry, plain_text)?))
|
Ok(IObject::PlainText(IPlainText::new(registry, inner)?))
|
||||||
}
|
}
|
||||||
organic::types::Object::RegularLink(_) => todo!(),
|
organic::types::Object::RegularLink(_) => todo!(),
|
||||||
organic::types::Object::RadioLink(_) => todo!(),
|
organic::types::Object::RadioLink(_) => todo!(),
|
||||||
@ -40,8 +40,8 @@ impl IObject {
|
|||||||
organic::types::Object::InlineBabelCall(_) => todo!(),
|
organic::types::Object::InlineBabelCall(_) => todo!(),
|
||||||
organic::types::Object::InlineSourceBlock(_) => todo!(),
|
organic::types::Object::InlineSourceBlock(_) => todo!(),
|
||||||
organic::types::Object::LineBreak(_) => todo!(),
|
organic::types::Object::LineBreak(_) => todo!(),
|
||||||
organic::types::Object::Target(target) => {
|
organic::types::Object::Target(inner) => {
|
||||||
Ok(IObject::Target(ITarget::new(registry, target)?))
|
Ok(IObject::Target(ITarget::new(registry, inner)?))
|
||||||
}
|
}
|
||||||
organic::types::Object::StatisticsCookie(_) => todo!(),
|
organic::types::Object::StatisticsCookie(_) => todo!(),
|
||||||
organic::types::Object::Subscript(_) => todo!(),
|
organic::types::Object::Subscript(_) => todo!(),
|
||||||
|
24
src/intermediate/paragraph.rs
Normal file
24
src/intermediate/paragraph.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use crate::error::CustomError;
|
||||||
|
|
||||||
|
use super::registry::Registry;
|
||||||
|
use super::IObject;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct IParagraph {
|
||||||
|
pub(crate) children: Vec<IObject>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IParagraph {
|
||||||
|
pub(crate) fn new<'parse>(
|
||||||
|
registry: &mut Registry<'parse>,
|
||||||
|
paragraph: &organic::types::Paragraph<'parse>,
|
||||||
|
) -> Result<IParagraph, CustomError> {
|
||||||
|
let children = paragraph
|
||||||
|
.children
|
||||||
|
.iter()
|
||||||
|
.map(|obj| IObject::new(registry, obj))
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(IParagraph { children })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user