diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-04-10 08:06:21 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-04-10 08:06:21 +0300 |
commit | 847b1874c73fe7da0327c4b5e254937c072d8f55 (patch) | |
tree | 9315c32ec19e41061f1f2849d2e77c1c7eda3876 | |
parent | 33b057ffb1d74c7ac10961f49c43e777e581a7e7 (diff) | |
download | html-page-847b1874c73fe7da0327c4b5e254937c072d8f55.tar.gz |
feat: add Element::attribute_value
Sponsored-by: author
-rw-r--r-- | src/lib.rs | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -471,6 +471,12 @@ impl Element { self.attrs.get(name) } + /// Return the value of an attribute as text, if the attribute is + /// set. Otherwise, return `None`. + pub fn attribute_value(&self, name: &str) -> Option<&str> { + self.attrs.get(name).map(|v| v.as_str()) + } + /// Set a key/value attribute. If the attribute was already set, /// change the value it has. pub fn set_attribute(&mut self, name: &str, value: &str) { @@ -677,6 +683,7 @@ mod test { Some(&AttributeValue::String("bar".into())) ); assert_eq!(e.attribute("foo").map(|x| x.as_str()), Some("bar")); + assert_eq!(e.attribute_value("foo"), Some("bar")); } #[test] |