diff options
| author | Martin Fischer <martin@push-f.com> | 2023-08-16 08:51:29 +0200 | 
|---|---|---|
| committer | Martin Fischer <martin@push-f.com> | 2023-08-19 13:41:55 +0200 | 
| commit | 0f460c2e77f450a2bac68eec97b2c62aa33c0495 (patch) | |
| tree | c3c1592cebd140476fe05add4794548c9435942b | |
| parent | a48ddc21a26f394e077e7bd80ef96b2c281e7730 (diff) | |
chore: move Attribute to attr module
This is done separately so that the following commit has a cleaner diff.
| -rw-r--r-- | src/attr.rs | 14 | ||||
| -rw-r--r-- | src/emitter.rs | 19 | ||||
| -rw-r--r-- | src/lib.rs | 4 | 
3 files changed, 20 insertions, 17 deletions
| diff --git a/src/attr.rs b/src/attr.rs new file mode 100644 index 0000000..d0d506e --- /dev/null +++ b/src/attr.rs @@ -0,0 +1,14 @@ +use std::ops::Range; + +/// A HTML attribute value (plus spans). +#[derive(Debug, Eq, PartialEq)] +pub struct Attribute<O> { +    /// The value of the attribute. +    pub value: String, + +    /// The source code span of the attribute name. +    pub name_span: Range<O>, + +    /// The source code span of the attribute value. +    pub value_span: Range<O>, +} diff --git a/src/emitter.rs b/src/emitter.rs index fcfb251..d3258e2 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -179,7 +179,7 @@ pub trait Emitter<O> {  pub struct DefaultEmitter<O = NoopOffset> {      current_characters: String,      current_token: Option<Token<O>>, -    current_attribute: Option<(String, Attribute<O>)>, +    current_attribute: Option<(String, crate::attr::Attribute<O>)>,      seen_attributes: BTreeSet<String>,      emitted_tokens: VecDeque<Token<O>>,      attr_in_end_tag_span: Option<Range<O>>, @@ -380,7 +380,7 @@ impl<O: Offset> Emitter<O> for DefaultEmitter<O> {          self.flush_current_attribute();          self.current_attribute = Some((              String::new(), -            Attribute { +            crate::attr::Attribute {                  name_span: offset..offset,                  value: String::new(),                  value_span: Range::default(), @@ -461,7 +461,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, Attribute<O>>, +    pub attributes: BTreeMap<String, crate::attr::Attribute<O>>,      /// The source code span of the tag.      pub span: Range<O>, @@ -475,19 +475,6 @@ impl<O: Offset> StartTag<O> {      }  } -/// A HTML attribute value (plus spans). -#[derive(Debug, Eq, PartialEq)] -pub struct Attribute<O> { -    /// The value of the attribute. -    pub value: String, - -    /// The source code span of the attribute name. -    pub name_span: Range<O>, - -    /// The source code span of the attribute value. -    pub value_span: Range<O>, -} -  /// A HTML end/close tag, such as `</p>` or `</a>`.  #[derive(Debug, Eq, PartialEq)]  pub struct EndTag<O> { @@ -3,6 +3,7 @@  #![forbid(unsafe_code)]  #![doc = include_str!("../README.md")] +mod attr;  mod emitter;  mod entities;  mod error; @@ -15,6 +16,7 @@ mod utils;  #[cfg(feature = "integration-tests")]  pub use utils::State as InternalState; -pub use emitter::{Attribute, Comment, DefaultEmitter, Doctype, Emitter, EndTag, StartTag, Token}; +pub use attr::Attribute; +pub use emitter::{Comment, DefaultEmitter, Doctype, Emitter, EndTag, StartTag, Token};  pub use error::Error;  pub use tokenizer::{State, Tokenizer}; | 
