Class: Makiri::HTML::Element
- Defined in:
- ext/makiri/makiri.c
Instance Method Summary collapse
-
#content_fragment ⇒ Object
A <template> element’s “template contents” - the separate DocumentFragment the HTML parser fills instead of making the parsed nodes children of the <template> (WHATWG DOM ‘HTMLTemplateElement.content`; browsers behave the same: template.children is empty, template.content holds the nodes).
Methods inherited from Element
Methods inherited from Node
#add_class, #append_class, #at, #attribute, #attribute?, #attributes, #blank?, #cdata?, #classes, #clone, #comment?, #document?, #document_fragment?, #dup, #each, #element?, #inspect, #path, #processing_instruction?, #remove_class, #root, #search, #set_attribute, #text?, #to_h, #traverse
Instance Method Details
#content_fragment ⇒ Object
A <template> element’s “template contents” - the separate DocumentFragment the HTML parser fills instead of making the parsed nodes children of the <template> (WHATWG DOM ‘HTMLTemplateElement.content`; browsers behave the same: template.children is empty, template.content holds the nodes). Lexbor stores it on the template interface; we surface it as a Makiri::DocumentFragment so it can be traversed/queried (`tpl.content_fragment.css(“p”)`).
Returns nil for any node that is not an HTML <template>. Note: CSS/XPath over the *template element itself* deliberately do NOT descend into the content (matching the DOM, and unavoidable for CSS since it runs Lexbor’s selector engine over the real tree) - query the fragment instead.
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'ext/makiri/glue/ruby_html_node.c', line 379
static VALUE
mkr_node_content_fragment(VALUE self)
{
lxb_dom_node_t *node = mkr_html_node_unwrap(self);
if (node->type != LXB_DOM_NODE_TYPE_ELEMENT
|| node->local_name != LXB_TAG_TEMPLATE
|| node->ns != LXB_NS_HTML) {
return Qnil;
}
lxb_dom_document_fragment_t *content = lxb_html_interface_template(node)->content;
if (content == NULL) {
return Qnil;
}
return mkr_wrap_html_node((lxb_dom_node_t *)content, mkr_node_document(self));
}
|