Compare commits

..

2 Commits

Author SHA1 Message Date
Tom Alexander
5bbb12327b
Add template for quote blocks. 2023-10-27 19:53:18 -04:00
Tom Alexander
f6c475c80c
Add templates for text markup. 2023-10-27 19:42:33 -04:00
14 changed files with 227 additions and 177 deletions

View File

@ -1 +1,3 @@
bold <b>{#.children}
{>object/}
{/.children}</b>

View File

@ -1 +1 @@
code <code>{.source}</code>

View File

@ -1 +1,3 @@
italic <i>{#.children}
{>object/}
{/.children}</i>

View File

@ -1 +1 @@
plain_text {.source}

View File

@ -1 +1,3 @@
quote_block <blockquote>{#.children}
{>element/}
{/.children}</blockquote>

View File

@ -1 +1,3 @@
strike_through <del>{#.children}
{>object/}
{/.children}</del>

View File

@ -1 +1,3 @@
underline <u>{#.children}
{>object/}
{/.children}</u>

View File

@ -1 +1 @@
verbatim <code>{.source}</code>

View File

@ -9,15 +9,19 @@ use crate::intermediate::IPlainText;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(tag = "type")] #[serde(tag = "type")]
#[serde(rename = "plain_text")] #[serde(rename = "plain_text")]
pub(crate) struct RenderPlainText {} pub(crate) struct RenderPlainText {
source: String,
}
impl RenderPlainText { impl RenderPlainText {
pub(crate) fn new( pub(crate) fn new(
config: &Config, config: &Config,
output_directory: &Path, output_directory: &Path,
output_file: &Path, output_file: &Path,
heading: &IPlainText, original: &IPlainText,
) -> Result<RenderPlainText, CustomError> { ) -> Result<RenderPlainText, CustomError> {
Ok(RenderPlainText {}) Ok(RenderPlainText {
source: original.source.clone(),
})
} }
} }

View File

@ -6,10 +6,14 @@ use crate::config::Config;
use crate::error::CustomError; use crate::error::CustomError;
use crate::intermediate::IQuoteBlock; use crate::intermediate::IQuoteBlock;
use super::RenderElement;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(tag = "type")] #[serde(tag = "type")]
#[serde(rename = "quote_block")] #[serde(rename = "quote_block")]
pub(crate) struct RenderQuoteBlock {} pub(crate) struct RenderQuoteBlock {
children: Vec<RenderElement>,
}
impl RenderQuoteBlock { impl RenderQuoteBlock {
pub(crate) fn new( pub(crate) fn new(
@ -18,6 +22,19 @@ impl RenderQuoteBlock {
output_file: &Path, output_file: &Path,
original: &IQuoteBlock, original: &IQuoteBlock,
) -> Result<RenderQuoteBlock, CustomError> { ) -> Result<RenderQuoteBlock, CustomError> {
Ok(RenderQuoteBlock {}) let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(RenderElement::new(
config,
&output_directory,
&output_file,
obj,
)?);
}
ret
};
Ok(RenderQuoteBlock { children })
} }
} }

View File

@ -25,6 +25,7 @@ use super::ISpecialBlock;
use super::ISrcBlock; use super::ISrcBlock;
use super::ITable; use super::ITable;
use super::IVerseBlock; use super::IVerseBlock;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum IElement { pub(crate) enum IElement {
@ -55,10 +56,11 @@ pub(crate) enum IElement {
} }
impl IElement { impl IElement {
pub(crate) async fn new<'parse>( pub(crate) fn new<'parse, 'b>(
registry: &mut Registry<'parse>, registry: &'b mut Registry<'parse>,
elem: &organic::types::Element<'parse>, elem: &'b organic::types::Element<'parse>,
) -> Result<IElement, CustomError> { ) -> BoxFuture<'b, Result<IElement, CustomError>> {
async move {
match elem { match elem {
organic::types::Element::Paragraph(inner) => { organic::types::Element::Paragraph(inner) => {
Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?)) Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?))
@ -78,9 +80,9 @@ impl IElement {
organic::types::Element::DynamicBlock(inner) => Ok(IElement::DynamicBlock( organic::types::Element::DynamicBlock(inner) => Ok(IElement::DynamicBlock(
IDynamicBlock::new(registry, inner).await?, IDynamicBlock::new(registry, inner).await?,
)), )),
organic::types::Element::FootnoteDefinition(inner) => Ok(IElement::FootnoteDefinition( organic::types::Element::FootnoteDefinition(inner) => Ok(
IFootnoteDefinition::new(registry, inner).await?, IElement::FootnoteDefinition(IFootnoteDefinition::new(registry, inner).await?),
)), ),
organic::types::Element::Comment(inner) => { organic::types::Element::Comment(inner) => {
Ok(IElement::Comment(IComment::new(registry, inner).await?)) Ok(IElement::Comment(IComment::new(registry, inner).await?))
} }
@ -134,4 +136,6 @@ impl IElement {
)), )),
} }
} }
.boxed()
}
} }

View File

@ -28,6 +28,7 @@ use super::timestamp::ITimestamp;
use super::underline::IUnderline; use super::underline::IUnderline;
use super::verbatim::IVerbatim; use super::verbatim::IVerbatim;
use super::ITarget; use super::ITarget;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum IObject { pub(crate) enum IObject {
@ -61,10 +62,11 @@ pub(crate) enum IObject {
} }
impl IObject { impl IObject {
pub(crate) async fn new<'parse>( pub(crate) fn new<'parse, 'b>(
registry: &mut Registry<'parse>, registry: &'b mut Registry<'parse>,
obj: &organic::types::Object<'parse>, obj: &'b organic::types::Object<'parse>,
) -> Result<IObject, CustomError> { ) -> BoxFuture<'b, Result<IObject, CustomError>> {
async move {
match obj { match obj {
organic::types::Object::Bold(inner) => { organic::types::Object::Bold(inner) => {
Ok(IObject::Bold(IBold::new(registry, inner).await?)) Ok(IObject::Bold(IBold::new(registry, inner).await?))
@ -149,4 +151,6 @@ impl IObject {
} }
} }
} }
.boxed()
}
} }

View File

@ -5,7 +5,7 @@ use super::registry::Registry;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct IPlainText { pub(crate) struct IPlainText {
source: String, pub(crate) source: String,
} }
impl IPlainText { impl IPlainText {

View File

@ -1,15 +1,26 @@
use crate::error::CustomError; use crate::error::CustomError;
use super::registry::Registry; use super::registry::Registry;
use super::IElement;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct IQuoteBlock {} pub(crate) struct IQuoteBlock {
pub(crate) children: Vec<IElement>,
}
impl IQuoteBlock { impl IQuoteBlock {
pub(crate) async fn new<'parse>( pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>, registry: &mut Registry<'parse>,
original: &organic::types::QuoteBlock<'parse>, original: &organic::types::QuoteBlock<'parse>,
) -> Result<IQuoteBlock, CustomError> { ) -> Result<IQuoteBlock, CustomError> {
Ok(IQuoteBlock {}) let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(IElement::new(registry, obj).await?);
}
ret
};
Ok(IQuoteBlock { children })
} }
} }