aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp A2019-05-09 09:59:05 +0200
committerGitHub2019-05-09 09:59:05 +0200
commitecb69f096b9559c4077dce86c3ac1fb01e18f0b2 (patch)
tree1c9acaabaaf246d24e6b185a6f5e1915b363953b
parentf00761664cd4e1a23c43914636f8896bb3cf027d (diff)
parent543c97c71d9dd8b79507dc6fe352ad6bdcbe18b6 (diff)
downloadrust-rst-ecb69f096b9559c4077dce86c3ac1fb01e18f0b2.tar.bz2
Merge pull request #5 from andreubotella/table_content
Implement tables
-rw-r--r--src/document_tree/attribute_types.rs15
-rw-r--r--src/document_tree/element_categories.rs2
-rw-r--r--src/document_tree/elements.rs10
-rw-r--r--src/document_tree/extra_attributes.rs11
4 files changed, 35 insertions, 3 deletions
diff --git a/src/document_tree/attribute_types.rs b/src/document_tree/attribute_types.rs
index 219a0ac..e98118a 100644
--- a/src/document_tree/attribute_types.rs
+++ b/src/document_tree/attribute_types.rs
@@ -21,10 +21,24 @@ 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);
+// 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
@@ -121,6 +135,7 @@ macro_rules! impl_cannot_be_empty {
};
}
impl_cannot_be_empty!(target::Target);
+impl_cannot_be_empty!(TableGroupCols);
impl<T> CanBeEmpty for Option<T> {
fn is_empty(&self) -> bool { self.is_none() }
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..025abf9 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)
diff --git a/src/document_tree/extra_attributes.rs b/src/document_tree/extra_attributes.rs
index 5ed9788..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,Measure,EnumeratedListType};
+use super::attribute_types::{CanBeEmpty,FixedSpace,ID,NameToken,AlignHV,AlignH,AlignV,TableAlignH,TableBorder,TableGroupCols,Measure,EnumeratedListType};
pub trait ExtraAttributes<A> {
fn with_extra(extra: A) -> Self;
@@ -61,7 +61,14 @@ impl_extra!(Footnote { backrefs: Vec<ID>, auto: bool });
impl_extra!(Citation { backrefs: Vec<ID> });
impl_extra!(SystemMessage { backrefs: Vec<ID>, level: Option<usize>, line: Option<usize>, type_: Option<NameToken> });
impl_extra!(Figure { align: Option<AlignH>, width: Option<usize> });
-impl_extra!(Table {}); //TODO: Table
+impl_extra!(Table { frame: Option<TableBorder>, colsep: Option<bool>, rowsep: Option<bool>, pgwide: Option<bool> });
+
+impl_extra!(TableGroup { cols: TableGroupCols, colsep: Option<bool>, rowsep: Option<bool>, align: Option<TableAlignH> });
+impl_extra!(TableHead { valign: Option<AlignV> });
+impl_extra!(TableBody { valign: Option<AlignV> });
+impl_extra!(TableRow { rowsep: Option<bool>, valign: Option<AlignV> });
+impl_extra!(TableEntry { colname: Option<NameToken>, namest: Option<NameToken>, nameend: Option<NameToken>, morerows: Option<usize>, colsep: Option<bool>, rowsep: Option<bool>, align: Option<TableAlignH>, r#char: Option<char>, charoff: Option<usize>, valign: Option<AlignV>, morecols: Option<usize> });
+impl_extra!(TableColspec { colnum: Option<usize>, colname: Option<NameToken>, colwidth: Option<String>, colsep: Option<bool>, rowsep: Option<bool>, align: Option<TableAlignH>, r#char: Option<char>, charoff: Option<usize>, stub: Option<bool> });
impl_extra!(OptionArgument { delimiter: Option<String> });