mirror of
https://github.com/typst/typst
synced 2025-08-18 00:48:34 +08:00
Add HtmlAttrs::{get, push_front}
This commit is contained in:
parent
32d51ae6d1
commit
cf327650ba
@ -172,10 +172,20 @@ impl HtmlAttrs {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an attribute.
|
/// Adds an attribute.
|
||||||
pub fn push(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) {
|
pub fn push(&mut self, attr: HtmlAttr, value: impl Into<EcoString>) {
|
||||||
self.0.push((attr, value.into()));
|
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! {
|
cast! {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user