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,6 +1,7 @@
use super::comment::IComment;
use super::keyword::IKeyword;
use super::macros::iselector;
use super::IPlainListSimpleItem;
use super::IBabelCall;
use super::ICenterBlock;
@@ -32,6 +33,7 @@ use futures::future::{BoxFuture, FutureExt};
pub(crate) enum IElement {
Paragraph(IParagraph),
PlainList(IPlainList),
PlainListSimpleItem(IPlainListSimpleItem),
CenterBlock(ICenterBlock),
QuoteBlock(IQuoteBlock),
SpecialBlock(ISpecialBlock),

View File

@@ -41,6 +41,7 @@ mod paragraph;
mod plain_link;
mod plain_list;
mod plain_list_item;
mod plain_list_simple_item;
mod plain_text;
mod planning;
mod property_drawer;
@@ -108,6 +109,7 @@ pub(crate) use paragraph::IParagraph;
pub(crate) use plain_link::IPlainLink;
pub(crate) use plain_list::IPlainList;
pub(crate) use plain_list_item::IPlainListItem;
pub(crate) use plain_list_simple_item::IPlainListSimpleItem;
pub(crate) use plain_text::IPlainText;
pub(crate) use planning::IPlanning;
pub(crate) use property_drawer::IPropertyDrawer;

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
};

View File

@@ -0,0 +1,32 @@
use super::macros::intermediate;
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.
#[derive(Debug, Clone)]
pub(crate) struct IPlainListSimpleItem {
pub(crate) children: Vec<IObject>,
pub(crate) post_blank: organic::types::PostBlank,
}
intermediate!(
IPlainListSimpleItem,
&'orig organic::types::Paragraph<'parse>,
original,
intermediate_context,
{
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IObject::new(intermediate_context.clone(), obj).await?);
}
ret
};
Ok(IPlainListSimpleItem {
children,
post_blank: original.get_post_blank(),
})
}
);