diff --git a/lib/LaTeXML/Common/XML.pm b/lib/LaTeXML/Common/XML.pm index 9af6f3ea9..bc46c6af3 100644 --- a/lib/LaTeXML/Common/XML.pm +++ b/lib/LaTeXML/Common/XML.pm @@ -75,7 +75,7 @@ our @EXPORT = ( decodeFromUTF8 ), @XML::LibXML::EXPORT, # Possibly (later) export these utility functions - qw(&element_nodes &text_in_node &new_node &element_next &element_prev + qw(&element_nodes &content_nodes &text_in_node &new_node &element_next &element_prev &append_nodes &clear_node &maybe_clone &valid_attributes ©_attributes &rename_attribute &remove_attr &get_attr &isTextNode &isElementNode &isChild &isDescendant &isDescendantOrSelf @@ -89,10 +89,18 @@ our $XML_NS = 'http://www.w3.org/XML/1998/namespace'; # [CONSTANT] #====================================================================== # XML Utilities + +# Return all child elements of $node sub element_nodes { my ($node) = @_; return ($node ? grep { $_->nodeType == XML_ELEMENT_NODE } $node->childNodes : ()); } +# return all content (element and text) nodes of $node +sub content_nodes { + my ($node) = @_; + return ($node ? grep { my $t = $_->nodeType; $t == XML_ELEMENT_NODE || $t == XML_TEXT_NODE } + $node->childNodes : ()); } + sub text_in_node { my ($node) = @_; return ($node ? join("\n", map { $_->data } grep { $_->nodeType == XML_TEXT_NODE } $node->childNodes) : ''); } diff --git a/lib/LaTeXML/Engine/LaTeX.pool.ltxml b/lib/LaTeXML/Engine/LaTeX.pool.ltxml index ee10feccf..f153a8696 100644 --- a/lib/LaTeXML/Engine/LaTeX.pool.ltxml +++ b/lib/LaTeXML/Engine/LaTeX.pool.ltxml @@ -1383,8 +1383,9 @@ sub applyAligningContext { if (my $container = LookupValue('ALIGNING_NODE')) { my ($node, $previous) = @$container; my @children = $node->childNodes; - while (my $skip = shift(@children)) { - last if !$previous || $previous->isSameNode($skip); } + if ($previous) { + while (my $skip = shift(@children)) { + last if $previous->isSameNode($skip); } } while (my $child = shift(@children)) { setAlignOrClass($document, $child, $align, $class) if $child->nodeType == XML_ELEMENT_NODE; } } return; } diff --git a/lib/LaTeXML/Engine/TeX_Box.pool.ltxml b/lib/LaTeXML/Engine/TeX_Box.pool.ltxml index 579719e57..c275e992f 100644 --- a/lib/LaTeXML/Engine/TeX_Box.pool.ltxml +++ b/lib/LaTeXML/Engine/TeX_Box.pool.ltxml @@ -368,7 +368,7 @@ sub insertBlock { my $inline = $is_svg || $document->canContain($context_tag, '#PCDATA'); my $container = $document->openElement('ltx:_CaptureBlock_', '_vertical_mode_' => 1, %blockattr); $document->absorb($contents); - my @nodes = $container->childNodes; + my @nodes = content_nodes($container); my @node_tags = map { $document->getNodeQName($_); } @nodes; my $nnodes = scalar(@nodes); $document->closeToNode($container, 1); diff --git a/t/alignment/colortbls.xml b/t/alignment/colortbls.xml index f193f2371..d0a8740d8 100644 --- a/t/alignment/colortbls.xml +++ b/t/alignment/colortbls.xml @@ -95,10 +95,10 @@ p{3cm}}"?>