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:
parent
a8969f141d
commit
2914e42ba1
@ -1,6 +1,7 @@
|
|||||||
{@select key=.type}
|
{@select key=.type}
|
||||||
{@eq value="paragraph"}{>paragraph/}{/eq}
|
{@eq value="paragraph"}{>paragraph/}{/eq}
|
||||||
{@eq value="plain_list"}{>plain_list/}{/eq}
|
{@eq value="plain_list"}{>plain_list/}{/eq}
|
||||||
|
{@eq value="plain_list_simple_item"}{>plain_list_simple_item/}{/eq}
|
||||||
{@eq value="center_block"}{>center_block/}{/eq}
|
{@eq value="center_block"}{>center_block/}{/eq}
|
||||||
{@eq value="quote_block"}{>quote_block/}{/eq}
|
{@eq value="quote_block"}{>quote_block/}{/eq}
|
||||||
{@eq value="special_block"}{>special_block/}{/eq}
|
{@eq value="special_block"}{>special_block/}{/eq}
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
{#.children}
|
||||||
|
{>object/}
|
||||||
|
{/.children}
|
@ -1,5 +1,6 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::plain_list_simple_item::RenderPlainListSimpleItem;
|
||||||
use super::render_context::RenderContext;
|
use super::render_context::RenderContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::intermediate::IElement;
|
use crate::intermediate::IElement;
|
||||||
@ -35,6 +36,7 @@ use super::verse_block::RenderVerseBlock;
|
|||||||
pub(crate) enum RenderElement {
|
pub(crate) enum RenderElement {
|
||||||
Paragraph(RenderParagraph),
|
Paragraph(RenderParagraph),
|
||||||
PlainList(RenderPlainList),
|
PlainList(RenderPlainList),
|
||||||
|
PlainListSimpleItem(RenderPlainListSimpleItem),
|
||||||
CenterBlock(RenderCenterBlock),
|
CenterBlock(RenderCenterBlock),
|
||||||
QuoteBlock(RenderQuoteBlock),
|
QuoteBlock(RenderQuoteBlock),
|
||||||
SpecialBlock(RenderSpecialBlock),
|
SpecialBlock(RenderSpecialBlock),
|
||||||
@ -69,6 +71,9 @@ render!(RenderElement, IElement, original, render_context, {
|
|||||||
render_context.clone(),
|
render_context.clone(),
|
||||||
inner,
|
inner,
|
||||||
)?)),
|
)?)),
|
||||||
|
IElement::PlainListSimpleItem(inner) => Ok(RenderElement::PlainListSimpleItem(
|
||||||
|
RenderPlainListSimpleItem::new(render_context.clone(), inner)?,
|
||||||
|
)),
|
||||||
IElement::CenterBlock(inner) => Ok(RenderElement::CenterBlock(RenderCenterBlock::new(
|
IElement::CenterBlock(inner) => Ok(RenderElement::CenterBlock(RenderCenterBlock::new(
|
||||||
render_context.clone(),
|
render_context.clone(),
|
||||||
inner,
|
inner,
|
||||||
|
@ -41,6 +41,7 @@ mod paragraph;
|
|||||||
mod plain_link;
|
mod plain_link;
|
||||||
mod plain_list;
|
mod plain_list;
|
||||||
mod plain_list_item;
|
mod plain_list_item;
|
||||||
|
mod plain_list_simple_item;
|
||||||
mod plain_text;
|
mod plain_text;
|
||||||
mod planning;
|
mod planning;
|
||||||
mod property_drawer;
|
mod property_drawer;
|
||||||
|
38
src/context/plain_list_simple_item.rs
Normal file
38
src/context/plain_list_simple_item.rs
Normal 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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
@ -1,6 +1,7 @@
|
|||||||
use super::comment::IComment;
|
use super::comment::IComment;
|
||||||
use super::keyword::IKeyword;
|
use super::keyword::IKeyword;
|
||||||
use super::macros::iselector;
|
use super::macros::iselector;
|
||||||
|
use super::IPlainListSimpleItem;
|
||||||
|
|
||||||
use super::IBabelCall;
|
use super::IBabelCall;
|
||||||
use super::ICenterBlock;
|
use super::ICenterBlock;
|
||||||
@ -32,6 +33,7 @@ use futures::future::{BoxFuture, FutureExt};
|
|||||||
pub(crate) enum IElement {
|
pub(crate) enum IElement {
|
||||||
Paragraph(IParagraph),
|
Paragraph(IParagraph),
|
||||||
PlainList(IPlainList),
|
PlainList(IPlainList),
|
||||||
|
PlainListSimpleItem(IPlainListSimpleItem),
|
||||||
CenterBlock(ICenterBlock),
|
CenterBlock(ICenterBlock),
|
||||||
QuoteBlock(IQuoteBlock),
|
QuoteBlock(IQuoteBlock),
|
||||||
SpecialBlock(ISpecialBlock),
|
SpecialBlock(ISpecialBlock),
|
||||||
|
@ -41,6 +41,7 @@ mod paragraph;
|
|||||||
mod plain_link;
|
mod plain_link;
|
||||||
mod plain_list;
|
mod plain_list;
|
||||||
mod plain_list_item;
|
mod plain_list_item;
|
||||||
|
mod plain_list_simple_item;
|
||||||
mod plain_text;
|
mod plain_text;
|
||||||
mod planning;
|
mod planning;
|
||||||
mod property_drawer;
|
mod property_drawer;
|
||||||
@ -108,6 +109,7 @@ pub(crate) use paragraph::IParagraph;
|
|||||||
pub(crate) use plain_link::IPlainLink;
|
pub(crate) use plain_link::IPlainLink;
|
||||||
pub(crate) use plain_list::IPlainList;
|
pub(crate) use plain_list::IPlainList;
|
||||||
pub(crate) use plain_list_item::IPlainListItem;
|
pub(crate) use plain_list_item::IPlainListItem;
|
||||||
|
pub(crate) use plain_list_simple_item::IPlainListSimpleItem;
|
||||||
pub(crate) use plain_text::IPlainText;
|
pub(crate) use plain_text::IPlainText;
|
||||||
pub(crate) use planning::IPlanning;
|
pub(crate) use planning::IPlanning;
|
||||||
pub(crate) use property_drawer::IPropertyDrawer;
|
pub(crate) use property_drawer::IPropertyDrawer;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::macros::intermediate;
|
use super::macros::intermediate;
|
||||||
|
use super::IPlainListSimpleItem;
|
||||||
|
|
||||||
use super::IElement;
|
use super::IElement;
|
||||||
use super::IObject;
|
use super::IObject;
|
||||||
@ -26,8 +27,19 @@ intermediate!(
|
|||||||
|
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
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
|
ret
|
||||||
};
|
};
|
||||||
|
32
src/intermediate/plain_list_simple_item.rs
Normal file
32
src/intermediate/plain_list_simple_item.rs
Normal 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(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
@ -1,3 +1,4 @@
|
|||||||
|
#![feature(let_chains)]
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user