MCPcopy Create free account
hub / github.com/Stranger6667/css-inline / create_element

Method create_element

css-inline/src/html/parser.rs:188–233  ·  view source on GitHub ↗
(
        &self,
        name: QualName,
        attrs: Vec<Attribute>,
        _flags: ElementFlags,
    )

Source from the content-addressed store, hash-verified

186 }
187
188 fn create_element(
189 &self,
190 name: QualName,
191 attrs: Vec<Attribute>,
192 _flags: ElementFlags,
193 ) -> NodeId {
194 // Determine if we should ignore inlining for this element based on its attributes
195 let inlining_ignored = should_ignore(&attrs);
196
197 // Determine if the element is a `style` element or a linked stylesheet (`link` with `rel="stylesheet"`).
198 let (is_style, is_stylesheet) = {
199 // If inlining is ignored, we consider neither to be true.
200 if inlining_ignored {
201 (false, false)
202 } else if name.expanded() == expanded_name!(html "style") {
203 (true, false)
204 } else if name.expanded() == expanded_name!(html "link") {
205 let mut rel_stylesheet = false;
206 let mut href_non_empty = false;
207 for attr in &attrs {
208 if attr.name.local == local_name!("rel") && &*attr.value == "stylesheet" {
209 rel_stylesheet = true;
210 }
211 // Skip links with empty `href` attributes
212 if attr.name.local == local_name!("href") && !attr.value.is_empty() {
213 href_non_empty = true;
214 }
215 if rel_stylesheet && href_non_empty {
216 break;
217 }
218 }
219 (false, rel_stylesheet && href_non_empty)
220 } else {
221 (false, false)
222 }
223 };
224 let element = self.push_element(name, attrs, inlining_ignored);
225 // Collect `style` tags and linked stylesheets separately to use them for CSS inlining later.
226 if is_style {
227 self.document.borrow_mut().add_style(element);
228 }
229 if is_stylesheet {
230 self.document.borrow_mut().add_linked_stylesheet(element);
231 }
232 element
233 }
234
235 fn create_comment(&self, text: StrTendril) -> NodeId {
236 self.push_comment(text)

Callers

nothing calls this directly

Calls 5

should_ignoreFunction · 0.85
is_emptyMethod · 0.80
push_elementMethod · 0.80
add_styleMethod · 0.80
add_linked_stylesheetMethod · 0.80

Tested by

no test coverage detected