From cf327650bae0f6a14662bf7896b8ffd6bd90f3c9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 15 Jul 2025 10:45:25 +0200 Subject: [PATCH] Add `HtmlAttrs::{get, push_front}` --- crates/typst-html/src/dom.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/typst-html/src/dom.rs b/crates/typst-html/src/dom.rs index d7287d42d..10691545d 100644 --- a/crates/typst-html/src/dom.rs +++ b/crates/typst-html/src/dom.rs @@ -172,10 +172,20 @@ impl HtmlAttrs { Self::default() } - /// Add an attribute. + /// Adds an attribute. pub fn push(&mut self, attr: HtmlAttr, value: impl 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) { + 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! {