From b654ca48596558e589d0041192c23cfdef238887 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Oct 2023 20:29:37 -0400 Subject: [PATCH] Add render phase to tables. --- src/context/mod.rs | 2 ++ src/context/table.rs | 32 ++++++++++++++++++++++++++--- src/context/table_cell.rs | 42 +++++++++++++++++++++++++++++++++++++++ src/context/table_row.rs | 42 +++++++++++++++++++++++++++++++++++++++ src/intermediate/mod.rs | 2 ++ 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 src/context/table_cell.rs create mode 100644 src/context/table_row.rs diff --git a/src/context/mod.rs b/src/context/mod.rs index f6203d8..2c412b3 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -54,6 +54,8 @@ mod strike_through; mod subscript; mod superscript; mod table; +mod table_cell; +mod table_row; mod target; mod timestamp; mod underline; diff --git a/src/context/table.rs b/src/context/table.rs index 6b21b74..f460650 100644 --- a/src/context/table.rs +++ b/src/context/table.rs @@ -6,11 +6,37 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ITable; -use super::macros::rnoop; +use super::macros::render; +use super::table_row::RenderTableRow; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "table")] -pub(crate) struct RenderTable {} +pub(crate) struct RenderTable { + children: Vec, +} -rnoop!(RenderTable, ITable); +render!( + RenderTable, + ITable, + original, + config, + output_directory, + output_file, + { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(RenderTableRow::new( + config, + output_directory, + output_file, + obj, + )?); + } + ret + }; + + Ok(RenderTable { children }) + } +); diff --git a/src/context/table_cell.rs b/src/context/table_cell.rs new file mode 100644 index 0000000..c2cef3c --- /dev/null +++ b/src/context/table_cell.rs @@ -0,0 +1,42 @@ +use std::path::Path; + +use serde::Serialize; + +use crate::config::Config; +use crate::error::CustomError; +use crate::intermediate::ITableCell; + +use super::macros::render; +use super::RenderObject; + +#[derive(Debug, Serialize)] +#[serde(tag = "type")] +#[serde(rename = "table_cell")] +pub(crate) struct RenderTableCell { + children: Vec, +} + +render!( + RenderTableCell, + ITableCell, + 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(RenderTableCell { children }) + } +); diff --git a/src/context/table_row.rs b/src/context/table_row.rs new file mode 100644 index 0000000..c4da3a8 --- /dev/null +++ b/src/context/table_row.rs @@ -0,0 +1,42 @@ +use std::path::Path; + +use serde::Serialize; + +use crate::config::Config; +use crate::error::CustomError; +use crate::intermediate::ITableRow; + +use super::macros::render; +use super::table_cell::RenderTableCell; + +#[derive(Debug, Serialize)] +#[serde(tag = "type")] +#[serde(rename = "table_row")] +pub(crate) struct RenderTableRow { + children: Vec, +} + +render!( + RenderTableRow, + ITableRow, + original, + config, + output_directory, + output_file, + { + let children = { + let mut ret = Vec::new(); + for obj in original.children.iter() { + ret.push(RenderTableCell::new( + config, + output_directory, + output_file, + obj, + )?); + } + ret + }; + + Ok(RenderTableRow { children }) + } +); diff --git a/src/intermediate/mod.rs b/src/intermediate/mod.rs index 7274f8a..fd969ef 100644 --- a/src/intermediate/mod.rs +++ b/src/intermediate/mod.rs @@ -121,6 +121,8 @@ pub(crate) use strike_through::IStrikeThrough; pub(crate) use subscript::ISubscript; pub(crate) use superscript::ISuperscript; pub(crate) use table::ITable; +pub(crate) use table_cell::ITableCell; +pub(crate) use table_row::ITableRow; pub(crate) use target::ITarget; pub(crate) use timestamp::ITimestamp; pub(crate) use underline::IUnderline;