From 27ff13e6755a4b0785c8a9b6e59645d80be083e8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 21 Dec 2023 17:27:19 -0500 Subject: [PATCH] Also special-case plain list items containing only paragraphs and sublists. This seems to be the behavior of the upstream org html exporter. --- src/context/plain_list_simple_item.rs | 2 +- src/intermediate/plain_list_item.rs | 27 +++++++++++++++------- src/intermediate/plain_list_simple_item.rs | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/context/plain_list_simple_item.rs b/src/context/plain_list_simple_item.rs index 1b03208..d1cae85 100644 --- a/src/context/plain_list_simple_item.rs +++ b/src/context/plain_list_simple_item.rs @@ -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")] diff --git a/src/intermediate/plain_list_item.rs b/src/intermediate/plain_list_item.rs index 64c7ae1..9cec4be 100644 --- a/src/intermediate/plain_list_item.rs +++ b/src/intermediate/plain_list_item.rs @@ -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 }; diff --git a/src/intermediate/plain_list_simple_item.rs b/src/intermediate/plain_list_simple_item.rs index d247c47..79a7665 100644 --- a/src/intermediate/plain_list_simple_item.rs +++ b/src/intermediate/plain_list_simple_item.rs @@ -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,