For plain list items with a single child that is a paragraph, do not wrap in paragraph html tags.

This is mimicking the behavior from org-mode's HTML exporter.
This commit is contained in:
Tom Alexander
2023-12-21 17:18:51 -05:00
parent a8969f141d
commit 2914e42ba1
10 changed files with 99 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
use super::macros::intermediate;
use super::IPlainListSimpleItem;
use super::IElement;
use super::IObject;
@@ -26,8 +27,19 @@ intermediate!(
let children = {
let mut ret = Vec::new();
for elem in original.children.iter() {
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
// 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?,
));
} else {
for elem in original.children.iter() {
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
}
}
ret
};