Add render phase to tables.

This commit is contained in:
Tom Alexander 2023-10-31 20:29:37 -04:00
parent 386af57ce6
commit b654ca4859
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 117 additions and 3 deletions

View File

@ -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;

View File

@ -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<RenderTableRow>,
}
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 })
}
);

42
src/context/table_cell.rs Normal file
View File

@ -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<RenderObject>,
}
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 })
}
);

42
src/context/table_row.rs Normal file
View File

@ -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<RenderTableCell>,
}
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 })
}
);

View File

@ -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;