astManipulator.removeFromBody(media);
BodiesStorage bodiesStorage = new BodiesStorage();
//move all kids of media into the empty clone. It is wasteful, they are going to be cloned but does not need to.
Body oldBody = parentChainIterator.getParentAsBody();
ASTCssNode currentNode = parentChainIterator.getCurrentNode();
parentChainIterator.moveUpToNextBody();
Body emptyClone = bodiesStorage.storeAndReplaceBySingleMemberClone(oldBody, null);
astManipulator.moveMembersBetweenBodies(media.getBody(), emptyClone);
while (!parentChainIterator.finished()) {
//store current node and
oldBody = parentChainIterator.getParentAsBody();
currentNode = parentChainIterator.getCurrentNode();
//move up
parentChainIterator.moveUpToNextBody();
bodiesStorage.storeAndReplaceBySingleMemberClone(oldBody, currentNode);
}
//clone whole parental chain
currentNode = parentChainIterator.getCurrentNode();
ASTCssNode currentNodeClone = currentNode.clone();
//make it media child
media.getBody().addMember(currentNodeClone);
currentNodeClone.setParent(media.getBody());
//restore bodies and add media
bodiesStorage.restore();
astManipulator.addIntoBody(media, currentNode);
}