From 159d8fb72a8a0bb920c9138060746e15496fd238 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Oct 2023 20:02:04 -0400 Subject: [PATCH] Add render stage for text markup. --- src/context/bold.rs | 32 +++++++++++++++++++++++++++++--- src/context/code.rs | 20 +++++++++++++++++--- src/context/italic.rs | 32 +++++++++++++++++++++++++++++--- src/context/strike_through.rs | 32 +++++++++++++++++++++++++++++--- src/context/underline.rs | 32 +++++++++++++++++++++++++++++--- src/context/verbatim.rs | 20 +++++++++++++++++--- 6 files changed, 150 insertions(+), 18 deletions(-) diff --git a/src/context/bold.rs b/src/context/bold.rs index 4fdb56e..87c6fb0 100644 --- a/src/context/bold.rs +++ b/src/context/bold.rs @@ -6,11 +6,37 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IBold; -use super::macros::rnoop; +use super::macros::render; +use super::RenderObject; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "bold")] -pub(crate) struct RenderBold {} +pub(crate) struct RenderBold { + children: Vec, +} -rnoop!(RenderBold, IBold); +render!( + RenderBold, + IBold, + original, + config, + output_directory, + output_file, + { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(RenderObject::new( + config, + output_directory, + output_file, + obj, + )?); + } + ret + }; + + Ok(RenderBold { children }) + } +); diff --git a/src/context/code.rs b/src/context/code.rs index bdad7e2..e03032d 100644 --- a/src/context/code.rs +++ b/src/context/code.rs @@ -6,11 +6,25 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ICode; -use super::macros::rnoop; +use super::macros::render; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "code")] -pub(crate) struct RenderCode {} +pub(crate) struct RenderCode { + contents: String, +} -rnoop!(RenderCode, ICode); +render!( + RenderCode, + ICode, + original, + config, + output_directory, + output_file, + { + Ok(RenderCode { + contents: original.contents.clone(), + }) + } +); diff --git a/src/context/italic.rs b/src/context/italic.rs index b29320e..d5240b4 100644 --- a/src/context/italic.rs +++ b/src/context/italic.rs @@ -6,11 +6,37 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IItalic; -use super::macros::rnoop; +use super::macros::render; +use super::RenderObject; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "italic")] -pub(crate) struct RenderItalic {} +pub(crate) struct RenderItalic { + children: Vec, +} -rnoop!(RenderItalic, IItalic); +render!( + RenderItalic, + IItalic, + original, + config, + output_directory, + output_file, + { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(RenderObject::new( + config, + output_directory, + output_file, + obj, + )?); + } + ret + }; + + Ok(RenderItalic { children }) + } +); diff --git a/src/context/strike_through.rs b/src/context/strike_through.rs index be6f960..c84fa37 100644 --- a/src/context/strike_through.rs +++ b/src/context/strike_through.rs @@ -6,11 +6,37 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IStrikeThrough; -use super::macros::rnoop; +use super::macros::render; +use super::RenderObject; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "strike_through")] -pub(crate) struct RenderStrikeThrough {} +pub(crate) struct RenderStrikeThrough { + children: Vec, +} -rnoop!(RenderStrikeThrough, IStrikeThrough); +render!( + RenderStrikeThrough, + IStrikeThrough, + original, + config, + output_directory, + output_file, + { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(RenderObject::new( + config, + output_directory, + output_file, + obj, + )?); + } + ret + }; + + Ok(RenderStrikeThrough { children }) + } +); diff --git a/src/context/underline.rs b/src/context/underline.rs index cfc1aa6..41cb21c 100644 --- a/src/context/underline.rs +++ b/src/context/underline.rs @@ -6,11 +6,37 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IUnderline; -use super::macros::rnoop; +use super::macros::render; +use super::RenderObject; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "underline")] -pub(crate) struct RenderUnderline {} +pub(crate) struct RenderUnderline { + children: Vec, +} -rnoop!(RenderUnderline, IUnderline); +render!( + RenderUnderline, + IUnderline, + original, + config, + output_directory, + output_file, + { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(RenderObject::new( + config, + output_directory, + output_file, + obj, + )?); + } + ret + }; + + Ok(RenderUnderline { children }) + } +); diff --git a/src/context/verbatim.rs b/src/context/verbatim.rs index 2456d0c..941317f 100644 --- a/src/context/verbatim.rs +++ b/src/context/verbatim.rs @@ -6,11 +6,25 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IVerbatim; -use super::macros::rnoop; +use super::macros::render; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "verbatim")] -pub(crate) struct RenderVerbatim {} +pub(crate) struct RenderVerbatim { + contents: String, +} -rnoop!(RenderVerbatim, IVerbatim); +render!( + RenderVerbatim, + IVerbatim, + original, + config, + output_directory, + output_file, + { + Ok(RenderVerbatim { + contents: original.contents.clone(), + }) + } +);