}
if (! (node instanceof BlockNode)) {
return;
}
BlockNode nodeAsBlock = (BlockNode) node;
// Check whether there are any consecutive RawTextNode children.
boolean hasConsecRawTextNodes = false;
for (int i = 0; i <= nodeAsBlock.numChildren() - 2; i++) {
if (nodeAsBlock.getChild(i) instanceof RawTextNode &&
nodeAsBlock.getChild(i + 1) instanceof RawTextNode) {
hasConsecRawTextNodes = true;
break;
}
}
// If there aren't any consecutive RawTextNode children, we're done.
if (! hasConsecRawTextNodes) {
return;
}
// Rebuild the list of children, combining consecutive RawTextNodes into one.
List<StandaloneNode> copyOfOrigChildren = Lists.newArrayList(nodeAsBlock.getChildren());
nodeAsBlock.clearChildren();
List<RawTextNode> consecutiveRawTextNodes = Lists.newArrayList();
for (StandaloneNode origChild : copyOfOrigChildren) {
if (origChild instanceof RawTextNode) {
consecutiveRawTextNodes.add((RawTextNode) origChild);
} else {
// First add the preceding consecutive RawTextNodes, if any.
addConsecutiveRawTextNodesAsOneNodeHelper(nodeAsBlock, consecutiveRawTextNodes);
consecutiveRawTextNodes.clear();
// Then add the current new child.
nodeAsBlock.addChild(origChild);
}
}
// Add the final group of consecutive RawTextNodes, if any.
addConsecutiveRawTextNodesAsOneNodeHelper(nodeAsBlock, consecutiveRawTextNodes);