2023-10-29 17:29:16 -04:00
|
|
|
use super::macros::intermediate;
|
2023-12-21 17:18:51 -05:00
|
|
|
use super::IPlainListSimpleItem;
|
2023-10-29 22:31:29 -04:00
|
|
|
|
2023-10-27 20:18:19 -04:00
|
|
|
use super::IElement;
|
|
|
|
use super::IObject;
|
2023-10-29 17:29:16 -04:00
|
|
|
use crate::error::CustomError;
|
2023-10-27 20:12:56 -04:00
|
|
|
|
2023-10-29 15:36:15 -04:00
|
|
|
#[derive(Debug, Clone)]
|
2023-10-27 20:18:19 -04:00
|
|
|
pub(crate) struct IPlainListItem {
|
|
|
|
pub(crate) tag: Vec<IObject>,
|
|
|
|
pub(crate) children: Vec<IElement>,
|
|
|
|
}
|
2023-10-27 20:12:56 -04:00
|
|
|
|
2023-12-19 17:09:11 -05:00
|
|
|
intermediate!(
|
|
|
|
IPlainListItem,
|
|
|
|
&'orig organic::types::PlainListItem<'parse>,
|
|
|
|
original,
|
2023-12-21 13:53:56 -05:00
|
|
|
intermediate_context,
|
2023-12-19 17:09:11 -05:00
|
|
|
{
|
|
|
|
let tag = {
|
|
|
|
let mut ret = Vec::new();
|
|
|
|
for obj in original.tag.iter() {
|
2023-12-21 13:53:56 -05:00
|
|
|
ret.push(IObject::new(intermediate_context.clone(), obj).await?);
|
2023-12-19 17:09:11 -05:00
|
|
|
}
|
|
|
|
ret
|
|
|
|
};
|
2023-10-27 20:18:19 -04:00
|
|
|
|
2023-12-19 17:09:11 -05:00
|
|
|
let children = {
|
|
|
|
let mut ret = Vec::new();
|
2023-12-21 17:18:51 -05:00
|
|
|
|
2023-12-21 17:27:19 -05:00
|
|
|
// Special case for list items with only paragraphs and sublists as their children. In those cases, the paragraph tags are omitted.
|
|
|
|
let is_simple_list_item = original.children.iter().all(|child| match child {
|
|
|
|
organic::types::Element::Paragraph(_) | organic::types::Element::PlainList(_) => {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
});
|
|
|
|
if is_simple_list_item {
|
|
|
|
for elem in original.children.iter() {
|
|
|
|
if let organic::types::Element::Paragraph(paragraph) = elem {
|
|
|
|
ret.push(IElement::PlainListSimpleItem(
|
|
|
|
IPlainListSimpleItem::new(intermediate_context.clone(), paragraph)
|
|
|
|
.await?,
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
|
|
|
|
}
|
|
|
|
}
|
2023-12-21 17:18:51 -05:00
|
|
|
} else {
|
|
|
|
for elem in original.children.iter() {
|
|
|
|
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
|
|
|
|
}
|
2023-12-19 17:09:11 -05:00
|
|
|
}
|
2023-12-21 17:27:19 -05:00
|
|
|
|
2023-12-19 17:09:11 -05:00
|
|
|
ret
|
|
|
|
};
|
2023-10-27 20:18:19 -04:00
|
|
|
|
2023-12-19 17:09:11 -05:00
|
|
|
Ok(IPlainListItem { tag, children })
|
|
|
|
}
|
|
|
|
);
|