From 0fae4176106ded746f88f8cc833f801947dbcb9a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Oct 2023 19:57:04 -0400 Subject: [PATCH] Add intermediate stage for text markup. --- default_environment/templates/html/code.dust | 2 +- .../templates/html/verbatim.dust | 2 +- src/intermediate/bold.rs | 20 +++++++++++++++++-- src/intermediate/code.rs | 14 +++++++++++-- src/intermediate/italic.rs | 20 +++++++++++++++++-- src/intermediate/strike_through.rs | 20 +++++++++++++++++-- src/intermediate/underline.rs | 19 ++++++++++++++++-- src/intermediate/verbatim.rs | 15 +++++++++++--- 8 files changed, 97 insertions(+), 15 deletions(-) diff --git a/default_environment/templates/html/code.dust b/default_environment/templates/html/code.dust index d8ccfe4..07d701a 100644 --- a/default_environment/templates/html/code.dust +++ b/default_environment/templates/html/code.dust @@ -1 +1 @@ -{.source} +{.contents} diff --git a/default_environment/templates/html/verbatim.dust b/default_environment/templates/html/verbatim.dust index d8ccfe4..07d701a 100644 --- a/default_environment/templates/html/verbatim.dust +++ b/default_environment/templates/html/verbatim.dust @@ -1 +1 @@ -{.source} +{.contents} diff --git a/src/intermediate/bold.rs b/src/intermediate/bold.rs index 6c4554b..dbca21d 100644 --- a/src/intermediate/bold.rs +++ b/src/intermediate/bold.rs @@ -1,5 +1,21 @@ -use super::macros::inoop; +use super::macros::intermediate; +use super::IObject; use crate::error::CustomError; -inoop!(IBold, Bold); +#[derive(Debug, Clone)] +pub(crate) struct IBold { + pub(crate) children: Vec, +} + +intermediate!(IBold, Bold, original, registry, { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(IObject::new(registry.clone(), obj).await?); + } + ret + }; + + Ok(IBold { children }) +}); diff --git a/src/intermediate/code.rs b/src/intermediate/code.rs index b077f18..b121666 100644 --- a/src/intermediate/code.rs +++ b/src/intermediate/code.rs @@ -1,5 +1,15 @@ -use super::macros::inoop; +use super::macros::intermediate; use crate::error::CustomError; -inoop!(ICode, Code); +#[derive(Debug, Clone)] +pub(crate) struct ICode { + pub(crate) contents: String, +} + +intermediate!(ICode, Code, original, _registry, { + Ok(ICode { + // TODO: Should this coalesce whitespace like PlainText? + contents: original.contents.to_owned(), + }) +}); diff --git a/src/intermediate/italic.rs b/src/intermediate/italic.rs index fed41bd..29d3fb3 100644 --- a/src/intermediate/italic.rs +++ b/src/intermediate/italic.rs @@ -1,5 +1,21 @@ -use super::macros::inoop; +use super::macros::intermediate; +use super::IObject; use crate::error::CustomError; -inoop!(IItalic, Italic); +#[derive(Debug, Clone)] +pub(crate) struct IItalic { + pub(crate) children: Vec, +} + +intermediate!(IItalic, Italic, original, registry, { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(IObject::new(registry.clone(), obj).await?); + } + ret + }; + + Ok(IItalic { children }) +}); diff --git a/src/intermediate/strike_through.rs b/src/intermediate/strike_through.rs index f924fa0..430670b 100644 --- a/src/intermediate/strike_through.rs +++ b/src/intermediate/strike_through.rs @@ -1,5 +1,21 @@ -use super::macros::inoop; +use super::macros::intermediate; +use super::IObject; use crate::error::CustomError; -inoop!(IStrikeThrough, StrikeThrough); +#[derive(Debug, Clone)] +pub(crate) struct IStrikeThrough { + pub(crate) children: Vec, +} + +intermediate!(IStrikeThrough, StrikeThrough, original, registry, { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(IObject::new(registry.clone(), obj).await?); + } + ret + }; + + Ok(IStrikeThrough { children }) +}); diff --git a/src/intermediate/underline.rs b/src/intermediate/underline.rs index 9e2f569..2f35db3 100644 --- a/src/intermediate/underline.rs +++ b/src/intermediate/underline.rs @@ -1,6 +1,21 @@ +use super::macros::intermediate; +use super::IObject; + use crate::error::CustomError; -use super::macros::inoop; +#[derive(Debug, Clone)] +pub(crate) struct IUnderline { + pub(crate) children: Vec, +} +intermediate!(IUnderline, Underline, original, registry, { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(IObject::new(registry.clone(), obj).await?); + } + ret + }; -inoop!(IUnderline, Underline); + Ok(IUnderline { children }) +}); diff --git a/src/intermediate/verbatim.rs b/src/intermediate/verbatim.rs index 8e1e05e..cceb972 100644 --- a/src/intermediate/verbatim.rs +++ b/src/intermediate/verbatim.rs @@ -1,6 +1,15 @@ +use super::macros::intermediate; + use crate::error::CustomError; -use super::macros::inoop; +#[derive(Debug, Clone)] +pub(crate) struct IVerbatim { + pub(crate) contents: String, +} - -inoop!(IVerbatim, Verbatim); +intermediate!(IVerbatim, Verbatim, original, _registry, { + Ok(IVerbatim { + // TODO: Should this coalesce whitespace like PlainText? + contents: original.contents.to_owned(), + }) +});