From a803534b470da9708b3260f0ab3a69d17dd2486f Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Fri, 19 Apr 2019 16:22:11 +0200 Subject: Adding table content elements. --- src/document_tree/element_categories.rs | 2 ++ src/document_tree/elements.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs index f3ac884..cfab75b 100644 --- a/src/document_tree/element_categories.rs +++ b/src/document_tree/element_categories.rs @@ -99,6 +99,8 @@ synonymous_enum!(SubLineBlock { LineBlock, Line }); synonymous_enum!(SubBlockQuote { Attribution, BodyElement }); synonymous_enum!(SubFootnote { Label, BodyElement }); synonymous_enum!(SubFigure { Caption, Legend, BodyElement }); +synonymous_enum!(SubTable { Title, TableGroup }); +synonymous_enum!(SubTableGroup { TableColspec, TableHead, TableBody }); #[cfg(test)] mod test { diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index fe5a498..809b796 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -207,7 +207,15 @@ impl_elems!( (Citation, SubFootnote; +) (SystemMessage, BodyElement; +) (Figure, SubFigure; +) - (Table; +) //TODO: Table + (Table, SubTable; +) + + //table elements + (TableGroup, SubTableGroup) + (TableHead, TableRow) + (TableBody, TableRow) + (TableRow, TableEntry) + (TableEntry, BodyElement) + (TableColspec) //body sub elements (ListItem, BodyElement) -- cgit v1.2.3 From 7c69731a62bd71c5411395b8ee35bd5f68ec36fb Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Wed, 8 May 2019 13:35:40 +0200 Subject: Adding attributes to the table content elements. --- src/document_tree/attribute_types.rs | 4 ++++ src/document_tree/elements.rs | 12 ++++++------ src/document_tree/extra_attributes.rs | 11 +++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/document_tree/attribute_types.rs b/src/document_tree/attribute_types.rs index 219a0ac..4a9bd3d 100644 --- a/src/document_tree/attribute_types.rs +++ b/src/document_tree/attribute_types.rs @@ -21,6 +21,10 @@ impl Default for FixedSpace { fn default() -> FixedSpace { FixedSpace::Preserve #[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub enum AlignH { Left, Center, Right} #[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub enum AlignHV { Top, Middle, Bottom, Left, Center, Right } +#[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub enum AlignV { Top, Middle, Bottom } + +#[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub enum TableAlignH { Left, Right, Center, Justify, Char } +#[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub enum TableBorder { Top, Bottom, TopBottom, All, Sides, None } #[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub struct ID(pub String); #[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub struct NameToken(pub String); diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index 809b796..025abf9 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -210,12 +210,12 @@ impl_elems!( (Table, SubTable; +) //table elements - (TableGroup, SubTableGroup) - (TableHead, TableRow) - (TableBody, TableRow) - (TableRow, TableEntry) - (TableEntry, BodyElement) - (TableColspec) + (TableGroup, SubTableGroup; +) + (TableHead, TableRow; +) + (TableBody, TableRow; +) + (TableRow, TableEntry; +) + (TableEntry, BodyElement; +) + (TableColspec; +) //body sub elements (ListItem, BodyElement) diff --git a/src/document_tree/extra_attributes.rs b/src/document_tree/extra_attributes.rs index 5ed9788..35f4b5a 100644 --- a/src/document_tree/extra_attributes.rs +++ b/src/document_tree/extra_attributes.rs @@ -1,7 +1,7 @@ use serde_derive::Serialize; use crate::target; -use super::attribute_types::{CanBeEmpty,FixedSpace,ID,NameToken,AlignHV,AlignH,Measure,EnumeratedListType}; +use super::attribute_types::{CanBeEmpty,FixedSpace,ID,NameToken,AlignHV,AlignH,AlignV,TableAlignH,TableBorder,Measure,EnumeratedListType}; pub trait ExtraAttributes { fn with_extra(extra: A) -> Self; @@ -61,7 +61,14 @@ impl_extra!(Footnote { backrefs: Vec, auto: bool }); impl_extra!(Citation { backrefs: Vec }); impl_extra!(SystemMessage { backrefs: Vec, level: Option, line: Option, type_: Option }); impl_extra!(Figure { align: Option, width: Option }); -impl_extra!(Table {}); //TODO: Table +impl_extra!(Table { frame: Option, colsep: Option, rowsep: Option, pgwide: Option }); + +impl_extra!(TableGroup { cols: usize, colsep: Option, rowsep: Option, align: Option }); +impl_extra!(TableHead { valign: Option }); +impl_extra!(TableBody { valign: Option }); +impl_extra!(TableRow { rowsep: Option, valign: Option }); +impl_extra!(TableEntry { colname: Option, namest: Option, nameend: Option, morerows: Option, colsep: Option, rowsep: Option, align: Option, r#char: Option, charoff: Option, valign: Option, morecols: Option }); +impl_extra!(TableColspec { colnum: Option, colname: Option, colwidth: Option, colsep: Option, rowsep: Option, align: Option, r#char: Option, charoff: Option, stub: Option }); impl_extra!(OptionArgument { delimiter: Option }); -- cgit v1.2.3 From 543c97c71d9dd8b79507dc6fe352ad6bdcbe18b6 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Wed, 8 May 2019 18:28:30 +0200 Subject: Adding an attribute type for the cols attribute of tgroup. --- src/document_tree/attribute_types.rs | 11 +++++++++++ src/document_tree/extra_attributes.rs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/document_tree/attribute_types.rs b/src/document_tree/attribute_types.rs index 4a9bd3d..e98118a 100644 --- a/src/document_tree/attribute_types.rs +++ b/src/document_tree/attribute_types.rs @@ -29,6 +29,16 @@ impl Default for FixedSpace { fn default() -> FixedSpace { FixedSpace::Preserve #[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub struct ID(pub String); #[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub struct NameToken(pub String); +// The table DTD has the cols attribute of tgroup as required, but having +// TableGroupCols not implement Default would leave no possible implementation +// for TableGroup::with_children. +#[derive(Debug,PartialEq,Eq,Hash,Serialize)] pub struct TableGroupCols(pub usize); +impl Default for TableGroupCols { + fn default() -> Self { + TableGroupCols(0) + } +} + // no eq for f64 #[derive(Debug,PartialEq,Serialize)] pub enum Measure { // http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#length-units @@ -125,6 +135,7 @@ macro_rules! impl_cannot_be_empty { }; } impl_cannot_be_empty!(target::Target); +impl_cannot_be_empty!(TableGroupCols); impl CanBeEmpty for Option { fn is_empty(&self) -> bool { self.is_none() } diff --git a/src/document_tree/extra_attributes.rs b/src/document_tree/extra_attributes.rs index 35f4b5a..bff9fb3 100644 --- a/src/document_tree/extra_attributes.rs +++ b/src/document_tree/extra_attributes.rs @@ -1,7 +1,7 @@ use serde_derive::Serialize; use crate::target; -use super::attribute_types::{CanBeEmpty,FixedSpace,ID,NameToken,AlignHV,AlignH,AlignV,TableAlignH,TableBorder,Measure,EnumeratedListType}; +use super::attribute_types::{CanBeEmpty,FixedSpace,ID,NameToken,AlignHV,AlignH,AlignV,TableAlignH,TableBorder,TableGroupCols,Measure,EnumeratedListType}; pub trait ExtraAttributes { fn with_extra(extra: A) -> Self; @@ -63,7 +63,7 @@ impl_extra!(SystemMessage { backrefs: Vec, level: Option, line: Optio impl_extra!(Figure { align: Option, width: Option }); impl_extra!(Table { frame: Option, colsep: Option, rowsep: Option, pgwide: Option }); -impl_extra!(TableGroup { cols: usize, colsep: Option, rowsep: Option, align: Option }); +impl_extra!(TableGroup { cols: TableGroupCols, colsep: Option, rowsep: Option, align: Option }); impl_extra!(TableHead { valign: Option }); impl_extra!(TableBody { valign: Option }); impl_extra!(TableRow { rowsep: Option, valign: Option }); -- cgit v1.2.3