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/document_tree') 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