mirror of
https://github.com/typst/typst
synced 2025-08-17 08:28:33 +08:00
Add HtmlAttrs::{get, push_front}
This commit is contained in:
parent
32d51ae6d1
commit
cf327650ba
@ -172,10 +172,20 @@ impl HtmlAttrs {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Add an attribute.
|
||||
/// Adds an attribute.
|
||||
pub fn push(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) {
|
||||
self.0.push((attr, value.into()));
|
||||
}
|
||||
|
||||
/// Adds an attribute to the start of the list.
|
||||
pub fn push_front(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) {
|
||||
self.0.insert(0, (attr, value.into()));
|
||||
}
|
||||
|
||||
/// Finds an attribute value.
|
||||
pub fn get(&self, attr: HtmlAttr) -> Option<&EcoString> {
|
||||
self.0.iter().find(|&&(k, _)| k == attr).map(|(_, v)| v)
|
||||
}
|
||||
}
|
||||
|
||||
cast! {
|
||||
|
Loading…
x
Reference in New Issue
Block a user