Compare commits
No commits in common. "cb5838345e4c803082048c3502f3d20fe04a33a8" and "88e10010d8974bdd849f5dd674d0c20fad0f16b8" have entirely different histories.
cb5838345e
...
88e10010d8
@ -14,10 +14,6 @@
|
|||||||
--src-block-language-background: #84828f;
|
--src-block-language-background: #84828f;
|
||||||
|
|
||||||
--quote-block-border-color: #84828f;
|
--quote-block-border-color: #84828f;
|
||||||
|
|
||||||
--table-border-color: #6a687a;
|
|
||||||
--table-odd-background-color: #0a0a0a;
|
|
||||||
--table-even-background-color: #141414;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@ -188,37 +184,4 @@ body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.org_table {
|
|
||||||
table-layout: fixed;
|
|
||||||
border-collapse: collapse;
|
|
||||||
border: 1px solid var(--table-border-color);
|
|
||||||
> tbody {
|
|
||||||
border-width: 1px 0;
|
|
||||||
border-style: solid;
|
|
||||||
border-color: var(--table-border-color);
|
|
||||||
> tr {
|
|
||||||
> td {
|
|
||||||
padding: 0.2rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
> tr:nth-child(odd) {
|
|
||||||
background-color: var(--table-odd-background-color);
|
|
||||||
}
|
|
||||||
> tr:nth-child(even) {
|
|
||||||
background-color: var(--table-even-background-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
> thead {
|
|
||||||
border-width: 1px 0;
|
|
||||||
border-style: solid;
|
|
||||||
border-color: var(--table-border-color);
|
|
||||||
> tr {
|
|
||||||
> th {
|
|
||||||
padding: 0.2rem;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1 @@
|
|||||||
<table class="org_table">{#.children}{@select key=.type}
|
<table>{#.children}{>table_row/}{/.children}</table>
|
||||||
{@eq value="head"}{>table_head/}{/eq}
|
|
||||||
{@eq value="body"}{>table_body/}{/eq}
|
|
||||||
{@none}{!TODO: make this panic!}ERROR: Unrecognized type {.type}.{/none}
|
|
||||||
{/select}{/.children}</table>
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<tbody>{#.children}{>table_row/}{/.children}</tbody>
|
|
@ -1 +0,0 @@
|
|||||||
<thead>{#.children}{>table_head_row/}{/.children}</thead>
|
|
@ -1 +0,0 @@
|
|||||||
<th scope="col">{#.children}{>object/}{/.children}</th>
|
|
@ -1 +0,0 @@
|
|||||||
<tr>{#.children}{>table_head_cell/}{/.children}</tr>
|
|
@ -59,7 +59,6 @@ mod subscript;
|
|||||||
mod superscript;
|
mod superscript;
|
||||||
mod table;
|
mod table;
|
||||||
mod table_cell;
|
mod table_cell;
|
||||||
mod table_group;
|
|
||||||
mod table_row;
|
mod table_row;
|
||||||
mod target;
|
mod target;
|
||||||
mod timestamp;
|
mod timestamp;
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::render_context::RenderContext;
|
use super::render_context::RenderContext;
|
||||||
use super::table_group::RenderTableGroup;
|
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::intermediate::ITable;
|
use crate::intermediate::ITable;
|
||||||
use crate::intermediate::ITableGroup;
|
|
||||||
|
|
||||||
use super::macros::render;
|
use super::macros::render;
|
||||||
use super::table_row::RenderTableRow;
|
use super::table_row::RenderTableRow;
|
||||||
@ -13,29 +11,15 @@ use super::table_row::RenderTableRow;
|
|||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
#[serde(rename = "table")]
|
#[serde(rename = "table")]
|
||||||
pub(crate) struct RenderTable {
|
pub(crate) struct RenderTable {
|
||||||
children: Vec<RenderTableGroup>,
|
children: Vec<RenderTableRow>,
|
||||||
post_blank: organic::types::PostBlank,
|
post_blank: organic::types::PostBlank,
|
||||||
}
|
}
|
||||||
|
|
||||||
render!(RenderTable, ITable, original, render_context, {
|
render!(RenderTable, ITable, original, render_context, {
|
||||||
let children = {
|
let children = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for group in original.children.iter() {
|
for obj in original.children.iter() {
|
||||||
let mut rows = Vec::new();
|
ret.push(RenderTableRow::new(render_context.clone(), obj)?);
|
||||||
match group {
|
|
||||||
ITableGroup::Head(irows) => {
|
|
||||||
for obj in irows {
|
|
||||||
rows.push(RenderTableRow::new(render_context.clone(), obj)?);
|
|
||||||
}
|
|
||||||
ret.push(RenderTableGroup::Head { children: rows });
|
|
||||||
}
|
|
||||||
ITableGroup::Body(irows) => {
|
|
||||||
for obj in irows {
|
|
||||||
rows.push(RenderTableRow::new(render_context.clone(), obj)?);
|
|
||||||
}
|
|
||||||
ret.push(RenderTableGroup::Body { children: rows });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
};
|
};
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
use super::table_row::RenderTableRow;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
|
||||||
#[serde(tag = "type")]
|
|
||||||
pub(crate) enum RenderTableGroup {
|
|
||||||
#[serde(rename = "head")]
|
|
||||||
Head { children: Vec<RenderTableRow> },
|
|
||||||
|
|
||||||
#[serde(rename = "body")]
|
|
||||||
Body { children: Vec<RenderTableRow> },
|
|
||||||
}
|
|
@ -59,7 +59,6 @@ mod subscript;
|
|||||||
mod superscript;
|
mod superscript;
|
||||||
mod table;
|
mod table;
|
||||||
mod table_cell;
|
mod table_cell;
|
||||||
mod table_group;
|
|
||||||
mod table_row;
|
mod table_row;
|
||||||
mod target;
|
mod target;
|
||||||
mod timestamp;
|
mod timestamp;
|
||||||
@ -127,7 +126,6 @@ pub(crate) use subscript::ISubscript;
|
|||||||
pub(crate) use superscript::ISuperscript;
|
pub(crate) use superscript::ISuperscript;
|
||||||
pub(crate) use table::ITable;
|
pub(crate) use table::ITable;
|
||||||
pub(crate) use table_cell::ITableCell;
|
pub(crate) use table_cell::ITableCell;
|
||||||
pub(crate) use table_group::ITableGroup;
|
|
||||||
pub(crate) use table_row::ITableRow;
|
pub(crate) use table_row::ITableRow;
|
||||||
pub(crate) use target::ITarget;
|
pub(crate) use target::ITarget;
|
||||||
pub(crate) use timestamp::ITimestamp;
|
pub(crate) use timestamp::ITimestamp;
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use super::macros::intermediate;
|
use super::macros::intermediate;
|
||||||
use super::table_row::ITableRow;
|
use super::table_row::ITableRow;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::intermediate::table_group::ITableGroup;
|
|
||||||
use organic::types::StandardProperties;
|
use organic::types::StandardProperties;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct ITable {
|
pub(crate) struct ITable {
|
||||||
pub(crate) children: Vec<ITableGroup>,
|
pub(crate) children: Vec<ITableRow>,
|
||||||
pub(crate) post_blank: organic::types::PostBlank,
|
pub(crate) post_blank: organic::types::PostBlank,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,40 +15,10 @@ intermediate!(
|
|||||||
original,
|
original,
|
||||||
intermediate_context,
|
intermediate_context,
|
||||||
{
|
{
|
||||||
// Separate groups by lines, multiple contiguous lines are the same as one.
|
let children = {
|
||||||
// If there is only one group, it is a tbody.
|
|
||||||
// If there are more than one group, the first is thead and the rest are tbody.
|
|
||||||
|
|
||||||
let sections = group_into_sections(&original.children);
|
|
||||||
|
|
||||||
let children = if sections.len() == 1 {
|
|
||||||
// If there is only one section, then it is a body.
|
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for group in sections.into_iter() {
|
for obj in original.children.iter() {
|
||||||
let mut rows = Vec::new();
|
ret.push(ITableRow::new(intermediate_context.clone(), obj).await?);
|
||||||
for obj in group.into_iter() {
|
|
||||||
rows.push(ITableRow::new(intermediate_context.clone(), obj).await?)
|
|
||||||
}
|
|
||||||
ret.push(ITableGroup::Body(rows));
|
|
||||||
}
|
|
||||||
ret
|
|
||||||
} else {
|
|
||||||
// If there are more than one section, the first is a head and the rest are body.
|
|
||||||
let mut ret = Vec::new();
|
|
||||||
let mut sections = sections.into_iter();
|
|
||||||
if let Some(group) = sections.next() {
|
|
||||||
let mut rows = Vec::new();
|
|
||||||
for obj in group.into_iter() {
|
|
||||||
rows.push(ITableRow::new(intermediate_context.clone(), obj).await?)
|
|
||||||
}
|
|
||||||
ret.push(ITableGroup::Head(rows));
|
|
||||||
}
|
|
||||||
for group in sections {
|
|
||||||
let mut rows = Vec::new();
|
|
||||||
for obj in group.into_iter() {
|
|
||||||
rows.push(ITableRow::new(intermediate_context.clone(), obj).await?)
|
|
||||||
}
|
|
||||||
ret.push(ITableGroup::Body(rows));
|
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
};
|
};
|
||||||
@ -60,41 +29,3 @@ intermediate!(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
enum GroupIntoSectionsState<'orig, 'parse> {
|
|
||||||
NonSection,
|
|
||||||
Section(Vec<&'orig organic::types::TableRow<'parse>>),
|
|
||||||
}
|
|
||||||
|
|
||||||
fn group_into_sections<'orig, 'parse>(
|
|
||||||
rows: &'orig Vec<organic::types::TableRow<'parse>>,
|
|
||||||
) -> Vec<Vec<&'orig organic::types::TableRow<'parse>>> {
|
|
||||||
let mut sections = Vec::new();
|
|
||||||
let mut rows = rows.into_iter();
|
|
||||||
let mut state = GroupIntoSectionsState::NonSection;
|
|
||||||
loop {
|
|
||||||
state = match (state, rows.next()) {
|
|
||||||
(GroupIntoSectionsState::NonSection, None) => break,
|
|
||||||
(GroupIntoSectionsState::NonSection, Some(row)) if row.children.is_empty() => {
|
|
||||||
GroupIntoSectionsState::NonSection
|
|
||||||
}
|
|
||||||
(GroupIntoSectionsState::NonSection, Some(row)) => {
|
|
||||||
GroupIntoSectionsState::Section(vec![row])
|
|
||||||
}
|
|
||||||
(GroupIntoSectionsState::Section(section), None) => {
|
|
||||||
sections.push(section);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(GroupIntoSectionsState::Section(section), Some(row)) if row.children.is_empty() => {
|
|
||||||
sections.push(section);
|
|
||||||
GroupIntoSectionsState::NonSection
|
|
||||||
}
|
|
||||||
(GroupIntoSectionsState::Section(mut section), Some(row)) => {
|
|
||||||
section.push(row);
|
|
||||||
GroupIntoSectionsState::Section(section)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sections
|
|
||||||
}
|
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
use super::ITableRow;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub(crate) enum ITableGroup {
|
|
||||||
Head(Vec<ITableRow>),
|
|
||||||
Body(Vec<ITableRow>),
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user