aboutsummaryrefslogtreecommitdiff
path: root/src/attr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/attr.rs')
-rw-r--r--src/attr.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/attr.rs b/src/attr.rs
index 4c7e330..d062a84 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -34,6 +34,18 @@ pub(crate) struct AttrInternal<O> {
pub name_offset: O,
/// The start offset of the attribute value.
pub value_offset: O,
+ pub value_syntax: Option<AttrValueSyntax>,
+}
+
+/// The syntax of the attribute value.
+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
+pub enum AttrValueSyntax {
+ /// An unquoted attribute value, e.g. `id=foo`.
+ Unquoted,
+ /// A single-quoted attribute value, e.g. `id='foo'`.
+ SingleQuoted,
+ /// A double-quoted attribute value, e.g. `id="foo"`.
+ DoubleQuoted,
}
/// An HTML attribute borrowed from an [`AttributeMap`].
@@ -54,6 +66,9 @@ pub struct AttributeOwned<O> {
pub name_offset: O,
/// The start offset of the attribute value.
pub value_offset: O, // TODO: wrap this in an Option once we can recognize the empty attribute syntax
+ /// The syntax of the attribute value.
+ /// `None` indicates the empty attribute syntax (e.g. `disabled` in `<input disabled>`).
+ pub value_syntax: Option<AttrValueSyntax>,
}
impl<O> AttributeMap<O> {
@@ -85,6 +100,13 @@ impl<'a, O: Offset> Attribute<'a, O> {
pub fn value_span(&self) -> Range<O> {
self.map_val.value_offset..self.map_val.value_offset + self.map_val.value.len()
}
+
+ /// Returns the attribute value syntax in case the value is explicitly defined.
+ ///
+ /// Returns `None` for attributes using the empty attribute syntax (e.g. `disabled` in `<input disabled>`).
+ pub fn value_syntax(&self) -> Option<AttrValueSyntax> {
+ self.map_val.value_syntax
+ }
}
// We cannot impl Index<Output=Attribute> because Index::index returns a reference of
@@ -120,6 +142,7 @@ impl<O> Iterator for AttrIntoIter<O> {
value: map_val.value,
name_offset: map_val.name_offset,
value_offset: map_val.value_offset,
+ value_syntax: map_val.value_syntax,
})
}
}
@@ -158,6 +181,7 @@ impl<O: Default> FromIterator<(String, String)> for AttributeMap<O> {
value,
name_offset: O::default(),
value_offset: O::default(),
+ value_syntax: Some(AttrValueSyntax::DoubleQuoted),
},
)
})