(
&mut self,
name: &QualName,
attrs: &Attributes,
style_node_id: Option<NodeId>,
minify_css: bool,
apply_width_attributes: bool,
apply_height_at
| 404 | |
| 405 | #[allow(clippy::too_many_lines)] |
| 406 | fn start_elem( |
| 407 | &mut self, |
| 408 | name: &QualName, |
| 409 | attrs: &Attributes, |
| 410 | style_node_id: Option<NodeId>, |
| 411 | minify_css: bool, |
| 412 | apply_width_attributes: bool, |
| 413 | apply_height_attributes: bool, |
| 414 | ) -> Result<(), InlineError> { |
| 415 | let html_name = match name.ns { |
| 416 | ns!(html) => Some(name.local.clone()), |
| 417 | _ => None, |
| 418 | }; |
| 419 | |
| 420 | if self.parent().ignore_children { |
| 421 | self.stack.push(ElemInfo { |
| 422 | html_name, |
| 423 | ignore_children: true, |
| 424 | }); |
| 425 | return Ok(()); |
| 426 | } |
| 427 | |
| 428 | let mut styles = if let Some(node_id) = style_node_id { |
| 429 | self.styles.get_mut(node_id.get()).and_then(|slot| { |
| 430 | slot.take().map(|mut styles| { |
| 431 | // Sort by specificity for consistent output order |
| 432 | styles.sort_unstable_by_key(|a| a.1); |
| 433 | styles |
| 434 | }) |
| 435 | }) |
| 436 | } else { |
| 437 | None |
| 438 | }; |
| 439 | |
| 440 | self.writer.write_all(b"<")?; |
| 441 | self.writer.write_all(name.local.as_bytes())?; |
| 442 | if let Some(class) = &attrs.class { |
| 443 | self.writer.write_all(b" class=\"")?; |
| 444 | self.writer.write_all(class.value.as_bytes())?; |
| 445 | self.writer.write_all(b"\"")?; |
| 446 | } |
| 447 | |
| 448 | // Extract and write width/height HTML attributes before styles is consumed |
| 449 | if let Some(ref html_name) = html_name { |
| 450 | if supports_dimension_attrs(html_name) { |
| 451 | let allow_percent = is_table_element(html_name); |
| 452 | // Resolve the cascade-effective value across the inline `style` and stylesheet. |
| 453 | let style_attr = attrs.get(local_name!("style")); |
| 454 | if apply_width_attributes && !attrs.contains(local_name!("width")) { |
| 455 | if let Some(dim) = effective_dimension( |
| 456 | style_attr.and_then(|s| find_inline_style_value(s, "width")), |
| 457 | styles.as_ref().and_then(|s| find_style_value(s, "width")), |
| 458 | ) |
| 459 | .and_then(|v| extract_dimension_value(v, allow_percent)) |
| 460 | { |
| 461 | self.writer.write_all(b" width=\"")?; |
| 462 | dim.write_to(&mut self.writer)?; |
| 463 | self.writer.write_all(b"\"")?; |
no test coverage detected