2023-10-24 00:36:08 -04:00
|
|
|
use crate::error::CustomError;
|
|
|
|
|
2023-10-27 14:43:06 -04:00
|
|
|
use super::registry::Registry;
|
2023-10-27 18:59:40 -04:00
|
|
|
use super::IDocumentElement;
|
2023-10-27 13:05:34 -04:00
|
|
|
use super::IObject;
|
2023-10-24 00:51:28 -04:00
|
|
|
|
2023-10-24 00:36:08 -04:00
|
|
|
#[derive(Debug)]
|
2023-10-27 13:05:34 -04:00
|
|
|
pub(crate) struct IHeading {
|
2023-10-27 12:47:12 -04:00
|
|
|
pub(crate) level: organic::types::HeadlineLevel,
|
2023-10-27 13:05:34 -04:00
|
|
|
pub(crate) title: Vec<IObject>,
|
2023-10-27 18:59:40 -04:00
|
|
|
pub(crate) children: Vec<IDocumentElement>,
|
2023-10-24 00:51:28 -04:00
|
|
|
}
|
2023-10-24 00:36:08 -04:00
|
|
|
|
2023-10-27 13:05:34 -04:00
|
|
|
impl IHeading {
|
2023-10-29 14:14:10 -04:00
|
|
|
pub(crate) async fn new<'b, 'parse>(
|
|
|
|
registry: &'b mut Registry<'parse>,
|
|
|
|
original: &'b organic::types::Heading<'parse>,
|
2023-10-27 14:43:06 -04:00
|
|
|
) -> Result<IHeading, CustomError> {
|
2023-10-27 15:55:19 -04:00
|
|
|
let title = {
|
|
|
|
let mut ret = Vec::new();
|
2023-10-29 12:15:07 -04:00
|
|
|
for obj in original.title.iter() {
|
2023-10-27 15:55:19 -04:00
|
|
|
ret.push(IObject::new(registry, obj).await?);
|
|
|
|
}
|
|
|
|
ret
|
|
|
|
};
|
2023-10-27 18:59:40 -04:00
|
|
|
let children = {
|
|
|
|
let mut ret = Vec::new();
|
2023-10-29 12:15:07 -04:00
|
|
|
for obj in original.children.iter() {
|
2023-10-27 18:59:40 -04:00
|
|
|
ret.push(IDocumentElement::new(registry, obj).await?);
|
|
|
|
}
|
|
|
|
ret
|
|
|
|
};
|
2023-10-27 13:05:34 -04:00
|
|
|
Ok(IHeading {
|
2023-10-27 12:14:07 -04:00
|
|
|
title,
|
2023-10-29 12:15:07 -04:00
|
|
|
level: original.level,
|
2023-10-27 18:59:40 -04:00
|
|
|
children,
|
2023-10-27 12:14:07 -04:00
|
|
|
})
|
2023-10-24 00:36:08 -04:00
|
|
|
}
|
|
|
|
}
|