Make converstion to intermediate state async.

We are going to need to do things like call external tools for syntax highlighting so we are going to need async in there eventually.
This commit is contained in:
Tom Alexander 2023-10-27 15:55:19 -04:00
parent 4a6948cde7
commit f9377d7609
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
9 changed files with 48 additions and 35 deletions

View File

@ -61,11 +61,14 @@ impl BlogPost {
let mut ret = Vec::new(); let mut ret = Vec::new();
for (real_path, _contents, parsed_document) in parsed_org_files.iter() { for (real_path, _contents, parsed_document) in parsed_org_files.iter() {
let relative_to_post_dir_path = real_path.strip_prefix(post_dir)?; let relative_to_post_dir_path = real_path.strip_prefix(post_dir)?;
ret.push(BlogPostPage::new( ret.push(
relative_to_post_dir_path, BlogPostPage::new(
&mut registry, relative_to_post_dir_path,
parsed_document, &mut registry,
)?); parsed_document,
)
.await?,
);
} }
ret ret
}; };

View File

@ -9,13 +9,13 @@ pub(crate) enum IElement {
} }
impl IElement { impl IElement {
pub(crate) fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
elem: &organic::types::Element<'parse>, elem: &organic::types::Element<'parse>,
) -> Result<IElement, CustomError> { ) -> Result<IElement, CustomError> {
match elem { match elem {
organic::types::Element::Paragraph(inner) => { organic::types::Element::Paragraph(inner) => {
Ok(IElement::Paragraph(IParagraph::new(registry, inner)?)) Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?))
} }
organic::types::Element::PlainList(_) => todo!(), organic::types::Element::PlainList(_) => todo!(),
organic::types::Element::CenterBlock(_) => todo!(), organic::types::Element::CenterBlock(_) => todo!(),

View File

@ -10,15 +10,17 @@ pub(crate) struct IHeading {
} }
impl IHeading { impl IHeading {
pub(crate) fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
heading: &organic::types::Heading<'parse>, heading: &organic::types::Heading<'parse>,
) -> Result<IHeading, CustomError> { ) -> Result<IHeading, CustomError> {
let title = heading let title = {
.title let mut ret = Vec::new();
.iter() for obj in heading.title.iter() {
.map(|obj| IObject::new(registry, obj)) ret.push(IObject::new(registry, obj).await?);
.collect::<Result<Vec<_>, _>>()?; }
ret
};
Ok(IHeading { Ok(IHeading {
title, title,
level: heading.level, level: heading.level,

View File

@ -11,7 +11,7 @@ pub(crate) enum IObject {
} }
impl IObject { impl IObject {
pub(crate) fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
obj: &organic::types::Object<'parse>, obj: &organic::types::Object<'parse>,
) -> Result<IObject, CustomError> { ) -> Result<IObject, CustomError> {
@ -23,7 +23,7 @@ impl IObject {
organic::types::Object::Code(_) => todo!(), organic::types::Object::Code(_) => todo!(),
organic::types::Object::Verbatim(_) => todo!(), organic::types::Object::Verbatim(_) => todo!(),
organic::types::Object::PlainText(inner) => { organic::types::Object::PlainText(inner) => {
Ok(IObject::PlainText(IPlainText::new(registry, inner)?)) Ok(IObject::PlainText(IPlainText::new(registry, inner).await?))
} }
organic::types::Object::RegularLink(_) => todo!(), organic::types::Object::RegularLink(_) => todo!(),
organic::types::Object::RadioLink(_) => todo!(), organic::types::Object::RadioLink(_) => todo!(),
@ -41,7 +41,7 @@ impl IObject {
organic::types::Object::InlineSourceBlock(_) => todo!(), organic::types::Object::InlineSourceBlock(_) => todo!(),
organic::types::Object::LineBreak(_) => todo!(), organic::types::Object::LineBreak(_) => todo!(),
organic::types::Object::Target(inner) => { organic::types::Object::Target(inner) => {
Ok(IObject::Target(ITarget::new(registry, inner)?)) Ok(IObject::Target(ITarget::new(registry, inner).await?))
} }
organic::types::Object::StatisticsCookie(_) => todo!(), organic::types::Object::StatisticsCookie(_) => todo!(),
organic::types::Object::Subscript(_) => todo!(), organic::types::Object::Subscript(_) => todo!(),

View File

@ -18,7 +18,7 @@ pub(crate) struct BlogPostPage {
} }
impl BlogPostPage { impl BlogPostPage {
pub(crate) fn new<'parse, P: Into<PathBuf>>( pub(crate) async fn new<'parse, P: Into<PathBuf>>(
path: P, path: P,
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
document: &organic::types::Document<'parse>, document: &organic::types::Document<'parse>,
@ -26,10 +26,14 @@ impl BlogPostPage {
let path = path.into(); let path = path.into();
let mut children = Vec::new(); let mut children = Vec::new();
if let Some(section) = document.zeroth_section.as_ref() { if let Some(section) = document.zeroth_section.as_ref() {
children.push(IDocumentElement::Section(ISection::new(registry, section)?)); children.push(IDocumentElement::Section(
ISection::new(registry, section).await?,
));
} }
for heading in document.children.iter() { for heading in document.children.iter() {
children.push(IDocumentElement::Heading(IHeading::new(registry, heading)?)); children.push(IDocumentElement::Heading(
IHeading::new(registry, heading).await?,
));
} }
Ok(BlogPostPage { Ok(BlogPostPage {

View File

@ -9,15 +9,17 @@ pub(crate) struct IParagraph {
} }
impl IParagraph { impl IParagraph {
pub(crate) fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
paragraph: &organic::types::Paragraph<'parse>, paragraph: &organic::types::Paragraph<'parse>,
) -> Result<IParagraph, CustomError> { ) -> Result<IParagraph, CustomError> {
let children = paragraph let children = {
.children let mut ret = Vec::new();
.iter() for obj in paragraph.children.iter() {
.map(|obj| IObject::new(registry, obj)) ret.push(IObject::new(registry, obj).await?);
.collect::<Result<Vec<_>, _>>()?; }
ret
};
Ok(IParagraph { children }) Ok(IParagraph { children })
} }

View File

@ -9,9 +9,9 @@ pub(crate) struct IPlainText {
} }
impl IPlainText { impl IPlainText {
pub(crate) fn new( pub(crate) async fn new<'parse>(
registry: &mut Registry<'_>, registry: &mut Registry<'parse>,
plain_text: &organic::types::PlainText<'_>, plain_text: &organic::types::PlainText<'parse>,
) -> Result<IPlainText, CustomError> { ) -> Result<IPlainText, CustomError> {
Ok(IPlainText { Ok(IPlainText {
source: coalesce_whitespace(plain_text.source).into_owned(), source: coalesce_whitespace(plain_text.source).into_owned(),

View File

@ -9,15 +9,17 @@ pub(crate) struct ISection {
} }
impl ISection { impl ISection {
pub(crate) fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
section: &organic::types::Section<'parse>, section: &organic::types::Section<'parse>,
) -> Result<ISection, CustomError> { ) -> Result<ISection, CustomError> {
let children = section let children = {
.children let mut ret = Vec::new();
.iter() for elem in section.children.iter() {
.map(|obj| IElement::new(registry, obj)) ret.push(IElement::new(registry, elem).await?);
.collect::<Result<Vec<_>, _>>()?; }
ret
};
Ok(ISection { children }) Ok(ISection { children })
} }

View File

@ -10,7 +10,7 @@ pub(crate) struct ITarget {
} }
impl ITarget { impl ITarget {
pub(crate) fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
target: &organic::types::Target<'parse>, target: &organic::types::Target<'parse>,
) -> Result<ITarget, CustomError> { ) -> Result<ITarget, CustomError> {