protected List<Block> buildChildrenWithMerge() throws FragmentedTemplateException {
    final List<Block> markupBlocks = new ArrayList<>();
    List<PsiElement> markupElements = TemplateFormatUtil.findAllMarkupLanguageElementsInside(myNode.getPsi());
    if (markupElements.size() == 1 && markupElements.get(0) instanceof XmlDocument) {
      markupElements = getXmlDocumentChildren(markupElements.get(0));
    }
    boolean mergeFromMarkup = false;
    for (PsiElement markupElement : markupElements) {
      if (TemplateFormatUtil.isErrorElement(markupElement)) {
        throw new FragmentedTemplateException((PsiErrorElement)markupElement);
      }
      if (!(FormatterUtil.containsWhiteSpacesOnly(markupElement.getNode()))) {
        Block rootBlock = myBuilder
          .createDataLanguageRootBlock(markupElement, markupElement.getLanguage(), mySettings, myXmlFormattingPolicy,
                                       myNode.getPsi().getContainingFile(), getDefaultMarkupIndent());
        PsiElement parent = markupElement.getParent();
        if (!mergeFromMarkup) mergeFromMarkup = isScriptBlock(rootBlock);
        if (parent instanceof PsiFile ||
            (rootBlock instanceof TemplateXmlBlock && ((TemplateXmlBlock)rootBlock).isTextContainingTemplateElements())) {
          for (Block block : rootBlock.getSubBlocks()) {
            if (containsErrorElement(block)) {
              throw new FragmentedTemplateException();
            }
            markupBlocks.add(block);
          }
        }
        else {
          markupBlocks.add(rootBlock);
        }
      }
    }
    List<Block> result = new ArrayList<>();
    ASTNode child = myNode.getFirstChildNode();
    while (child != null) {
      if (containsFatalError(child.getPsi()) && markupBlocks.size() > 0) {
        throw new FragmentedTemplateException();
      }
      if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
        if (!myBuilder.isMarkupLanguageElement(child.getPsi())) {
          addBlocksForNonMarkupChild(result, child);
        }
      }
      child = child.getTreeNext();
    }
    if (markupBlocks.size() > 0) {
      if (result.isEmpty()) return markupBlocks;
      if (mergeFromMarkup) {
        result = TemplateFormatUtil.mergeBlocks(markupBlocks, result, myNode.getTextRange());
      }
      else {
        result = TemplateFormatUtil.mergeBlocks(result, markupBlocks, myNode.getTextRange());
      }
      for (Block resultBlock : result) {
        ASTNode node = resultBlock instanceof ASTBlock ? ((ASTBlock)resultBlock).getNode() : null;
        if (node != null && resultBlock instanceof IndentInheritingBlock) {
          ((IndentInheritingBlock)resultBlock).setIndent(getChildIndent(node));
        }
        if (resultBlock instanceof BlockWithParent) {
          ((BlockWithParent)resultBlock).setParent(this);
        }
      }
    }
    return result;
  }
protected List<Block> buildChildrenWithMerge()