Skip to main content

get_embeddable

Function get_embeddable 

Source
pub fn get_embeddable(doc: &PostDocument) -> Option<Node>
Expand description

Extract an embeddable HTML fragment from a post-processed document, mirroring Perl LaTeXML::Util::Pack::get_embeddable (Pack.pm L282-313).

  • Find the first <div class="ltx_document">.
  • Unwrap as long as the current node is a <div> with exactly one child, an unwrappable wrapper class (ltx_page_main, ltx_page_content, ltx_document, ltx_para, ltx_header), and no inline style attribute.
  • If the resulting node is a <p> whose every child is inline- compatible (local-name contains math / text / span), rename it to <span class="text"> so it stays inline-embeddable.
  • Copy RDFa attributes (prefix, property, content, resource, about, typeof, rel, rev, datatype) from the document root onto the extracted node so the snippet retains its semantic annotations.
  • Namespace declarations from the root are NOT propagated (libxml-rs gap — see module docs).

If no ltx_document element is found, returns the document root, matching Perl’s return $embeddable || $doc.