Also special-case plain list items containing only paragraphs and sublists.

This seems to be the behavior of the upstream org html exporter.
This commit is contained in:
Tom Alexander 2023-12-21 17:27:19 -05:00
parent 2914e42ba1
commit 27ff13e675
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 21 additions and 10 deletions

View File

@ -7,7 +7,7 @@ use crate::intermediate::IPlainListSimpleItem;
use super::macros::render;
use super::RenderObject;
/// Special case for list items with only 1 child which is a paragraph. In those cases, the paragraph tags are omitted. This is equivalent to a Paragraph but in a different struct to have a different type tag.
/// Special case for list items with only paragraphs and sublists as their children. In those cases, the paragraph tags are omitted. This is equivalent to a Paragraph but in a different struct to have a different type tag.
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "plain_list_simple_item")]

View File

@ -28,19 +28,30 @@ intermediate!(
let children = {
let mut ret = Vec::new();
// Special case for list items with only 1 child which is a paragraph. In those cases, the paragraph tags are omitted.
if original.children.len() == 1
&& let Some(organic::types::Element::Paragraph(paragraph)) =
original.children.iter().next()
{
ret.push(IElement::PlainListSimpleItem(
IPlainListSimpleItem::new(intermediate_context.clone(), paragraph).await?,
));
// 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?);
}
}
} else {
for elem in original.children.iter() {
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
}
}
ret
};

View File

@ -3,7 +3,7 @@ use super::IObject;
use crate::error::CustomError;
use organic::types::StandardProperties;
/// Special case for list items with only 1 child which is a paragraph. In those cases, the paragraph tags are omitted. This is equivalent to a Paragraph but in a different struct to have a different type tag.
/// Special case for list items with only paragraphs and sublists as their children. In those cases, the paragraph tags are omitted. This is equivalent to a Paragraph but in a different struct to have a different type tag.
#[derive(Debug, Clone)]
pub(crate) struct IPlainListSimpleItem {
pub(crate) children: Vec<IObject>,