Walk node’s ancestor chain to the top. If the chain ends at a
Document (or document-fragment) node the subtree is LIVE — part of a
document tree — and None is returned; otherwise the topmost node is a
DETACHED root and is returned. Callers use this to decide whether a
source tree they are done with is theirs to free
(Document::discard_subtree) or still reachable from a live document.
Is node an artifact of HOW a chunk was parsed, rather than part of the
chunk? True for exactly the two things that can sit ABOVE a chunk’s top-level
nodes: the throwaway parse_fragment wrapper, and the parsed document node.
Parse a standalone markup string into its own document — the port of Perl
LaTeXML::Common::XML::Parser::parseChunk (Common/XML/Parser.pm:36-39:
parse_string($string) then ->documentElement, “expects only a single
node”). Parsing lives here, beside the rest of the Common::XML helpers, and
NOT in Document — mirroring Perl, where Document::appendTree only ever
consumes already-parsed nodes.
Parse a markup chunk that may be a document FRAGMENT — several sibling nodes,
or bare text — and return its owning document together with the top-level
nodes to insert. Returning the two together is deliberate: libxml Nodes are
handles into the document that owns them, so the caller must keep the
[Document] alive for exactly as long as it uses the nodes.