MarkdownPsiElement (@NotNull MarkdownHeader header) { int level = sanitizeHeaderLevel(getLevelFunction().fun(Objects.requireNonNull(header).getLevel())); MarkdownPsiElement newElement; Project project = header.getProject(); String headerName = Objects.requireNonNull(header.getName()); if (header.getNode().getElementType() == MarkdownElementTypes.SETEXT_1 && level == 2) { newElement = MarkdownPsiElementFactory.createSetext(project, headerName, "-", header.getLastChild().getTextLength()); } else if (header.getNode().getElementType() == MarkdownElementTypes.SETEXT_2 && level == 1) { newElement = MarkdownPsiElementFactory.createSetext(project, headerName, "=", header.getLastChild().getTextLength()); } else { newElement = level == 0 ? MarkdownPsiElementFactory.createTextElement(project, headerName) : MarkdownPsiElementFactory.createHeader(project, headerName, level); } return newElement; }