Document embedDoc = embedTarget.getDocumentClone();
/*
Elements children = embedDoc.body().children();
Element wrappingNode = ElementUtil.wrapElementsToSingleNode(children);
*/
Element wrappingNode = new GroupNode(ExtNodeConstants.GROUP_NODE_ATTR_TYPE_EMBED_WRAPPER);
// retrieve all the blocks that misincluded into head
Element head = embedDoc.head();
Elements headChildren = head.children();
List<Node> tempList = new ArrayList<>();
String tagName;
for (Element child : headChildren) {
if (StringUtil.in(child.tagName(), "script", "link", ExtNodeConstants.BLOCK_NODE_TAG)) {
child.remove();
wrappingNode.appendChild(child);
}
}
Element body = embedDoc.body();
Elements bodyChildren = body.children();
ElementUtil.appendNodes(wrappingNode, new ArrayList<Node>(bodyChildren));
// copy all the attrs to the wrapping group node
Iterator<Attribute> attrs = elem.attributes().iterator();
Attribute attr;
while (attrs.hasNext()) {
attr = attrs.next();
wrappingNode.attr(attr.getKey(), attr.getValue());
}
// a embed template file may by included many times in same parent
// template, so we have to avoid duplicated snippet refs
resetSnippetRefs(wrappingNode);