diff options
author | Martin Fischer <martin@push-f.com> | 2023-08-16 09:45:18 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-08-19 13:41:55 +0200 |
commit | 65aca9cbf0318bd3a2f936641b4f5bc3729c98c2 (patch) | |
tree | 3bf6ae3ea03c1f377e9b4bd6fd7d6af99fbddc5a /src/emitter.rs | |
parent | 0f460c2e77f450a2bac68eec97b2c62aa33c0495 (diff) |
break!: introduce AttributeMap
This has a number of benefits:
* it hides the implementation of the map
* it hides the type used for the map values
(which lets us e.g. change name_span to name_offset while still
being able to provide a convenient `Attribute::name_span` method.)
* it lets us provide convenience impls for the map
such as `FromIterator<(String, String)>`
Diffstat (limited to 'src/emitter.rs')
-rw-r--r-- | src/emitter.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/emitter.rs b/src/emitter.rs index d3258e2..8856589 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -1,5 +1,4 @@ use std::collections::btree_map::Entry; -use std::collections::BTreeMap; use std::collections::BTreeSet; use std::collections::VecDeque; use std::mem; @@ -179,7 +178,7 @@ pub trait Emitter<O> { pub struct DefaultEmitter<O = NoopOffset> { current_characters: String, current_token: Option<Token<O>>, - current_attribute: Option<(String, crate::attr::Attribute<O>)>, + current_attribute: Option<(String, crate::attr::AttrInternal<O>)>, seen_attributes: BTreeSet<String>, emitted_tokens: VecDeque<Token<O>>, attr_in_end_tag_span: Option<Range<O>>, @@ -210,7 +209,7 @@ impl<O> DefaultEmitter<O> { { if let Some((k, v)) = self.current_attribute.take() { match self.current_token { - Some(Token::StartTag(ref mut tag)) => match tag.attributes.entry(k) { + Some(Token::StartTag(ref mut tag)) => match tag.attributes.inner.entry(k) { Entry::Vacant(vacant) => { vacant.insert(v); } @@ -380,7 +379,7 @@ impl<O: Offset> Emitter<O> for DefaultEmitter<O> { self.flush_current_attribute(); self.current_attribute = Some(( String::new(), - crate::attr::Attribute { + crate::attr::AttrInternal { name_span: offset..offset, value: String::new(), value_span: Range::default(), @@ -461,7 +460,7 @@ pub struct StartTag<O> { /// /// Duplicate attributes are ignored after the first one as per WHATWG spec. Implement your own /// [`Emitter`] to tweak this behavior. - pub attributes: BTreeMap<String, crate::attr::Attribute<O>>, + pub attributes: crate::attr::AttributeMap<O>, /// The source code span of the tag. pub span: Range<O>, |