diff options
| author | Philipp A | 2018-12-01 16:02:51 +0100 | 
|---|---|---|
| committer | Philipp A | 2018-12-01 16:02:51 +0100 | 
| commit | ad225dee57c5f4f8391ba50d7da5b793f8900e8e (patch) | |
| tree | 19f300a456931d77b951c79563d4bf4850f51498 | |
| parent | 71d26fbdc4825b4c2a2db125dde388dc5c5a196c (diff) | |
| download | rust-rst-ad225dee57c5f4f8391ba50d7da5b793f8900e8e.tar.bz2 | |
Unified image attributes
| -rw-r--r-- | src/document_tree/extra_attributes.rs | 17 | ||||
| -rw-r--r-- | src/parser/conversion.rs | 6 | 
2 files changed, 7 insertions, 16 deletions
| diff --git a/src/document_tree/extra_attributes.rs b/src/document_tree/extra_attributes.rs index 916ba41..2019dec 100644 --- a/src/document_tree/extra_attributes.rs +++ b/src/document_tree/extra_attributes.rs @@ -85,19 +85,10 @@ impl_extra!(TargetInline {  	anonymous: bool,  });  impl_extra!(RawInline { space: FixedSpace, format: Vec<NameToken> }); -impl_extra!(#[derive(Debug,Serialize)] ImageInline { -	#[serde(serialize_with = "serialize_url")] -	uri: Url, -	align: Option<AlignHV>, -	alt: Option<String>, -	height: Option<Measure>, -	width: Option<Measure>, -	scale: Option<u8>, -	#[serde(serialize_with = "serialize_opt_url")] -	target: Option<Url>,  // Not part of the DTD but a valid argument -}); -impl ImageInline { -	pub fn new(uri: Url) -> ImageInline { ImageInline { +pub type ImageInline = Image; + +impl Image { +	pub fn new(uri: Url) -> Image { Image {  		uri: uri,  		align: None,  		alt: None, diff --git a/src/parser/conversion.rs b/src/parser/conversion.rs index e59098e..20d74a1 100644 --- a/src/parser/conversion.rs +++ b/src/parser/conversion.rs @@ -78,7 +78,7 @@ fn convert_substitution_def(pair: Pair<Rule>) -> Result<e::SubstitutionDefinitio      let name = pairs.next().unwrap().as_str();  // Rule::substitution_name      let inner_pair = pairs.next().unwrap();      let inner: c::TextOrInlineElement = match inner_pair.as_rule() { -        Rule::image => convert_image_inline(inner_pair)?.into(), +        Rule::image => convert_image::<e::ImageInline>(inner_pair)?.into(),          rule => panic!("Unknown substitution rule {:?}", rule),      };      let mut subst_def = e::SubstitutionDefinition::with_children(vec![inner.into()]); @@ -86,9 +86,9 @@ fn convert_substitution_def(pair: Pair<Rule>) -> Result<e::SubstitutionDefinitio      Ok(subst_def)  } -fn convert_image_inline(pair: Pair<Rule>) -> Result<e::ImageInline, Error> { +fn convert_image<I>(pair: Pair<Rule>) -> Result<I, Error> where I: Element + ExtraAttributes<a::Image> {      let mut pairs = pair.into_inner(); -    let mut image = e::ImageInline::with_extra(a::ImageInline::new( +    let mut image = I::with_extra(a::Image::new(          pairs.next().unwrap().as_str().parse()?,  // line      ));      if let Some(opt_block) = pairs.next() {  // image_opt_block | 
