From a22f1caf79d947ce860f9a4751c583bc90393069 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 2 Dec 2018 20:43:34 +0100 Subject: wonkily add names and so on --- src/document_tree/elements.rs | 28 +++++++++++++++++----------- src/document_tree/extra_attributes.rs | 11 ++++++++++- src/parser/conversion/block.rs | 13 ++++++++----- src/parser/conversion/inline.rs | 6 ++++-- 4 files changed, 39 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index 5f669ae..638d44b 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -1,6 +1,7 @@ use serde_derive::Serialize; use crate::target; +use super::attribute_types::{ID,NameToken}; use super::extra_attributes::{self,ExtraAttributes}; use super::element_categories::*; @@ -10,10 +11,15 @@ use super::element_categories::*; //-----------------\\ pub trait Element { - fn ids (& self) -> & Vec; - fn ids_mut(&mut self) -> &mut Vec; - fn names (& self) -> & Vec; - fn names_mut(&mut self) -> &mut Vec; + /// A list containing one or more unique identifier keys + fn ids (& self) -> & Vec; + fn ids_mut(&mut self) -> &mut Vec; + /// a list containing the names of an element, typically originating from the element's title or content. + /// Each name in names must be unique; if there are name conflicts (two or more elements want to the same name), + /// the contents will be transferred to the dupnames attribute on the duplicate elements. + /// An element may have at most one of the names or dupnames attributes, but not both. + fn names (& self) -> & Vec; + fn names_mut(&mut self) -> &mut Vec; fn source (& self) -> & Option; fn source_mut(&mut self) -> &mut Option; fn classes (& self) -> & Vec; @@ -22,11 +28,11 @@ pub trait Element { #[derive(Debug,Default,Serialize)] pub struct CommonAttributes { - ids: Vec, - names: Vec, + ids: Vec, + names: Vec, source: Option, classes: Vec, - //left out dupnames + //TODO: dupnames } //----\\ @@ -35,10 +41,10 @@ pub struct CommonAttributes { macro_rules! impl_element { ($name:ident) => ( impl Element for $name { - fn ids (& self) -> & Vec { & self.common.ids } - fn ids_mut(&mut self) -> &mut Vec { &mut self.common.ids } - fn names (& self) -> & Vec { & self.common.names } - fn names_mut(&mut self) -> &mut Vec { &mut self.common.names } + fn ids (& self) -> & Vec { & self.common.ids } + fn ids_mut(&mut self) -> &mut Vec { &mut self.common.ids } + fn names (& self) -> & Vec { & self.common.names } + fn names_mut(&mut self) -> &mut Vec { &mut self.common.names } fn source (& self) -> & Option { & self.common.source } fn source_mut(&mut self) -> &mut Option { &mut self.common.source } fn classes (& self) -> & Vec { & self.common.classes } diff --git a/src/document_tree/extra_attributes.rs b/src/document_tree/extra_attributes.rs index 0aa40f8..1799e4f 100644 --- a/src/document_tree/extra_attributes.rs +++ b/src/document_tree/extra_attributes.rs @@ -40,8 +40,11 @@ impl_extra!(DoctestBlock { space: FixedSpace }); impl_extra!(SubstitutionDefinition { ltrim: bool, rtrim: bool }); impl_extra!(Comment { space: FixedSpace }); impl_extra!(Target { + /// External reference to a URI/URL refuri: Option, + /// References to ids attributes in other elements refid: Option, + /// Internal reference to the names attribute of another element. May resolve to either an internal or external reference. refname: Vec, anonymous: bool, }); @@ -71,9 +74,12 @@ impl_extra!(Table {}); //TODO impl_extra!(OptionArgument { delimiter: Option }); impl_extra!(Reference { - name: Option, + name: Option, //TODO: is CDATA in the DTD, so maybe no nametoken? + /// External reference to a URI/URL refuri: Option, + /// References to ids attributes in other elements refid: Option, + /// Internal reference to the names attribute of another element refname: Vec, }); impl_extra!(FootnoteReference { refid: Option, refname: Vec, auto: bool }); @@ -83,8 +89,11 @@ impl_extra!(Problematic { refid: Option }); //also have non-inline versions. Inline image is no figure child, inline target has content impl_extra!(TargetInline { + /// External reference to a URI/URL refuri: Option, + /// References to ids attributes in other elements refid: Option, + /// Internal reference to the names attribute of another element. May resolve to either an internal or external reference. refname: Vec, anonymous: bool, }); diff --git a/src/parser/conversion/block.rs b/src/parser/conversion/block.rs index d99f38f..bca8559 100644 --- a/src/parser/conversion/block.rs +++ b/src/parser/conversion/block.rs @@ -5,7 +5,7 @@ use crate::document_tree::{ Element,HasChildren,ExtraAttributes, elements as e, element_categories as c, - attribute_types::ID, + attribute_types::{ID,NameToken}, extra_attributes as a, }; @@ -61,8 +61,11 @@ fn convert_target(pair: Pair) -> Result { }; for p in pair.into_inner() { match p.as_rule() { - // TODO: or is it refnames? - Rule::target_name_uq | Rule::target_name_qu => attrs.refid = Some(ID(p.as_str().to_owned())), + Rule::target_name_uq | Rule::target_name_qu => { + //TODO: abstract + attrs.refid = Some( ID(p.as_str().to_owned().replace(' ', "-"))); + attrs.refname.push(NameToken(p.as_str().to_owned())); + }, Rule::link_target => attrs.refuri = Some(p.parse()?), rule => panic!("Unexpected rule in target: {:?}", rule), } @@ -79,7 +82,7 @@ fn convert_substitution_def(pair: Pair) -> Result panic!("Unknown substitution rule {:?}", rule), }; let mut subst_def = e::SubstitutionDefinition::with_children(vec![inner.into()]); - subst_def.names_mut().push(name.to_owned()); + subst_def.names_mut().push(NameToken(name.to_owned())); Ok(subst_def) } @@ -96,7 +99,7 @@ fn convert_image(pair: Pair) -> Result where I: Element + Ext let opt_val = opt_iter.next().unwrap(); match opt_name.as_str() { "class" => image.classes_mut().push(opt_val.as_str().to_owned()), - "name" => image.names_mut().push(opt_val.as_str().to_owned()), + "name" => image.names_mut().push(NameToken(opt_val.as_str().to_owned())), "alt" => image.extra_mut().alt = Some(opt_val.as_str().to_owned()), "height" => image.extra_mut().height = Some(opt_val.parse()?), "width" => image.extra_mut().width = Some(opt_val.parse()?), diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs index 5d75c69..d0aa524 100644 --- a/src/parser/conversion/inline.rs +++ b/src/parser/conversion/inline.rs @@ -5,7 +5,7 @@ use crate::document_tree::{ ExtraAttributes, elements as e, element_categories as c, -// attribute_types::ID, + attribute_types::{ID,NameToken}, extra_attributes as a, }; @@ -32,7 +32,9 @@ fn convert_reference(pair: Pair) -> Result { match concrete.as_rule() { Rule::reference_target => { let rt_inner = concrete.into_inner().next().unwrap(); // reference_target_uq or target_name_qu - name = Some(rt_inner.as_str().to_owned()); // TODO: is this right? + //TODO: abstract + id = Some( ID(rt_inner.as_str().to_owned().replace(' ', "-"))); + name = Some(NameToken(rt_inner.as_str().to_owned())); }, Rule::reference_explicit => unimplemented!("explicit reference"), Rule::reference_auto => unimplemented!("auto reference"), -- cgit v1.2.3