aboutsummaryrefslogtreecommitdiff
path: root/src/attr.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-12 08:15:45 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 13:41:55 +0200
commitae5d8185a5b419f89d520504c1cb4c59c26879bf (patch)
tree0198c59440111154e2aaca1e8d4e8fb0809699c4 /src/attr.rs
parent180f6d6111b966627aa00a4017b6fb9751f7386c (diff)
feat: make attribute value syntax recognizable
Note that while making this breaking change, we're also swapping the parameter order for more consistency so that the reader parameter always comes last in Emitter methods.
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),
},
)
})