mirror of
https://github.com/typst/typst
synced 2025-08-17 08:28:33 +08:00
Add HtmlElem::with_optional_attr
This commit is contained in:
parent
830611ceef
commit
32d51ae6d1
@ -79,6 +79,19 @@ impl HtmlElem {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds the attribute to the element if value is not `None`.
|
||||||
|
pub fn with_optional_attr(
|
||||||
|
self,
|
||||||
|
attr: HtmlAttr,
|
||||||
|
value: Option<impl Into<EcoString>>,
|
||||||
|
) -> Self {
|
||||||
|
if let Some(value) = value {
|
||||||
|
self.with_attr(attr, value)
|
||||||
|
} else {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds CSS styles to an element.
|
/// Adds CSS styles to an element.
|
||||||
fn with_styles(self, properties: css::Properties) -> Self {
|
fn with_styles(self, properties: css::Properties) -> Self {
|
||||||
if let Some(value) = properties.into_inline_styles() {
|
if let Some(value) = properties.into_inline_styles() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user