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::macros::render;
use super::RenderObject; 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)] #[derive(Debug, Serialize)]
#[serde(tag = "type")] #[serde(tag = "type")]
#[serde(rename = "plain_list_simple_item")] #[serde(rename = "plain_list_simple_item")]

View File

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

View File

@ -3,7 +3,7 @@ use super::IObject;
use crate::error::CustomError; use crate::error::CustomError;
use organic::types::StandardProperties; 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)] #[derive(Debug, Clone)]
pub(crate) struct IPlainListSimpleItem { pub(crate) struct IPlainListSimpleItem {
pub(crate) children: Vec<IObject>, pub(crate) children: Vec<IObject>,