diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/document_tree/element_categories.rs | 17 | ||||
| -rw-r--r-- | src/document_tree/elements.rs | 25 | ||||
| -rw-r--r-- | src/document_tree/mod.rs | 3 |
3 files changed, 29 insertions, 16 deletions
diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs index d8024ad..e9d07a6 100644 --- a/src/document_tree/element_categories.rs +++ b/src/document_tree/element_categories.rs @@ -1,3 +1,5 @@ +use std::fmt::{self,Debug,Formatter}; + use super::elements::*; pub trait HasChildren<C> { @@ -16,11 +18,16 @@ pub trait HasChildren<C> { } macro_rules! synonymous_enum {( $name:ident { $( $entry:ident ),* } ) => ( - #[derive(Debug)] pub enum $name { - $( - $entry($entry), - )* + $( $entry($entry), )* + } + + impl Debug for $name { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> { + match self { + $( &$name::$entry(ref inner) => inner.fmt(fmt), )* + } + } } $( @@ -46,7 +53,7 @@ synonymous_enum!(BodyElement { synonymous_enum!(BibliographicElement { Author, Authors, Organization, Address, Contact, Version, Revision, Status, Date, Copyright, Field }); synonymous_enum!(TextOrInlineElement { - TextElement, Emphasis, Strong, Literal, Reference, FootnoteReference, CitationReference, SubstitutionReference, TitleReference, Abbreviation, Acronym, Superscript, Subscript, Inline, Problematic, Generated, Math, + String, Emphasis, Strong, Literal, Reference, FootnoteReference, CitationReference, SubstitutionReference, TitleReference, Abbreviation, Acronym, Superscript, Subscript, Inline, Problematic, Generated, Math, //also have non-inline versions. Inline image is no figure child, inline target has content TargetInline, RawInline, ImageInline }); diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index f1a9b43..024a25a 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -130,14 +130,14 @@ impl_elems!( (Paragraph, TextOrInlineElement) (LiteralBlock, TextOrInlineElement; +) (DoctestBlock, TextOrInlineElement; +) - (MathBlock) + (MathBlock, String) (Rubric, TextOrInlineElement) (SubstitutionDefinition, TextOrInlineElement; +) (Comment, TextOrInlineElement; +) (Pending) (Target; +) - (Raw; +) - (Image; *) + (Raw, String; +) + (Image; *) //compound body elements (Compound, BodyElement) @@ -182,8 +182,8 @@ impl_elems!( (OptionGroup, Option_) (Description, BodyElement) (Option_, SubOption) - (OptionString, TextOrInlineElement) - (OptionArgument, TextOrInlineElement; +) + (OptionString, String) + (OptionArgument, String; +) (Line, TextOrInlineElement) (Attribution, TextOrInlineElement) @@ -208,13 +208,18 @@ impl_elems!( (Inline, TextOrInlineElement) (Problematic, TextOrInlineElement; +) (Generated, TextOrInlineElement) - (Math) + (Math, String) //also have non-inline versions. Inline image is no figure child, inline target has content - (TargetInline, TextOrInlineElement; +) - (RawInline; +) + (TargetInline, String; +) + (RawInline, String; +) (ImageInline; *) - //text element - (TextElement) + //text element = String ); + +impl<'a> From<&'a str> for TextOrInlineElement { + fn from(s: &'a str) -> TextOrInlineElement { + s.to_owned().into() + } +} diff --git a/src/document_tree/mod.rs b/src/document_tree/mod.rs index cb54eb5..a9c4760 100644 --- a/src/document_tree/mod.rs +++ b/src/document_tree/mod.rs @@ -16,7 +16,8 @@ fn test() { use document_tree::HasChildren; let mut doc = dt::Document::default(); - let title = dt::Title::default(); + let mut title = dt::Title::default(); + title.append_child("Hi"); doc.append_child(title); println!("{:?}", doc); |
