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,5 +1,6 @@
use serde::Serialize;
use super::plain_list_simple_item::RenderPlainListSimpleItem;
use super::render_context::RenderContext;
use crate::error::CustomError;
use crate::intermediate::IElement;
@@ -35,6 +36,7 @@ use super::verse_block::RenderVerseBlock;
pub(crate) enum RenderElement {
Paragraph(RenderParagraph),
PlainList(RenderPlainList),
PlainListSimpleItem(RenderPlainListSimpleItem),
CenterBlock(RenderCenterBlock),
QuoteBlock(RenderQuoteBlock),
SpecialBlock(RenderSpecialBlock),
@@ -69,6 +71,9 @@ render!(RenderElement, IElement, original, render_context, {
render_context.clone(),
inner,
)?)),
IElement::PlainListSimpleItem(inner) => Ok(RenderElement::PlainListSimpleItem(
RenderPlainListSimpleItem::new(render_context.clone(), inner)?,
)),
IElement::CenterBlock(inner) => Ok(RenderElement::CenterBlock(RenderCenterBlock::new(
render_context.clone(),
inner,

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;

View File

@@ -0,0 +1,38 @@
use serde::Serialize;
use super::render_context::RenderContext;
use crate::error::CustomError;
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.
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "plain_list_simple_item")]
pub(crate) struct RenderPlainListSimpleItem {
children: Vec<RenderObject>,
post_blank: organic::types::PostBlank,
}
render!(
RenderPlainListSimpleItem,
IPlainListSimpleItem,
original,
render_context,
{
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(RenderObject::new(render_context.clone(), obj)?);
}
ret
};
Ok(RenderPlainListSimpleItem {
children,
post_blank: original.post_blank,
})
}
);