Search in sources :

Example 1 with MarkdownHeaderImpl

use of org.intellij.plugins.markdown.lang.psi.impl.MarkdownHeaderImpl in project intellij-plugins by JetBrains.

the class MarkdownStructureElement method getChildrenBase.

@NotNull
@Override
public Collection<StructureViewTreeElement> getChildrenBase() {
    final List<StructureViewTreeElement> childrenElements = new ArrayList<>();
    final PsiElement myElement = getElement();
    if (myElement == null)
        return childrenElements;
    final PsiElement structureContainer = myElement instanceof MarkdownFile ? myElement.getFirstChild() : getParentOfType(myElement, TRANSPARENT_CONTAINERS);
    if (structureContainer == null) {
        return Collections.emptyList();
    }
    final MarkdownPsiElement currentHeader = myElement instanceof MarkdownHeaderImpl ? ((MarkdownHeaderImpl) myElement) : null;
    processContainer(structureContainer, currentHeader, currentHeader, element -> childrenElements.add(new MarkdownStructureElement(element)));
    return childrenElements;
}
Also used : MarkdownHeaderImpl(org.intellij.plugins.markdown.lang.psi.impl.MarkdownHeaderImpl) MarkdownFile(org.intellij.plugins.markdown.lang.psi.impl.MarkdownFile) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MarkdownPsiElement(org.intellij.plugins.markdown.lang.psi.MarkdownPsiElement) PsiElement(com.intellij.psi.PsiElement) MarkdownPsiElement(org.intellij.plugins.markdown.lang.psi.MarkdownPsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MarkdownHeaderImpl

use of org.intellij.plugins.markdown.lang.psi.impl.MarkdownHeaderImpl in project intellij-plugins by JetBrains.

the class MarkdownStructureElement method processContainer.

private static void processContainer(@NotNull PsiElement container, @Nullable PsiElement sameLevelRestriction, @Nullable MarkdownPsiElement from, @NotNull Consumer<? super PsiElement> resultConsumer) {
    PsiElement nextSibling = from == null ? container.getFirstChild() : from.getNextSibling();
    PsiElement maxContentLevel = null;
    while (nextSibling != null) {
        if (TRANSPARENT_CONTAINERS.contains(PsiUtilCore.getElementType(nextSibling)) && maxContentLevel == null) {
            processContainer(nextSibling, null, null, resultConsumer);
        } else if (nextSibling instanceof MarkdownHeaderImpl) {
            if (sameLevelRestriction != null && isSameLevelOrHigher(nextSibling, sameLevelRestriction)) {
                break;
            }
            if (maxContentLevel == null || isSameLevelOrHigher(nextSibling, maxContentLevel)) {
                maxContentLevel = nextSibling;
                final IElementType type = nextSibling.getNode().getElementType();
                if (PRESENTABLE_TYPES.contains(type)) {
                    resultConsumer.consume(nextSibling);
                }
            }
        }
        nextSibling = nextSibling.getNextSibling();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) MarkdownHeaderImpl(org.intellij.plugins.markdown.lang.psi.impl.MarkdownHeaderImpl) MarkdownPsiElement(org.intellij.plugins.markdown.lang.psi.MarkdownPsiElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 MarkdownPsiElement (org.intellij.plugins.markdown.lang.psi.MarkdownPsiElement)2 MarkdownHeaderImpl (org.intellij.plugins.markdown.lang.psi.impl.MarkdownHeaderImpl)2 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 IElementType (com.intellij.psi.tree.IElementType)1 MarkdownFile (org.intellij.plugins.markdown.lang.psi.impl.MarkdownFile)1 NotNull (org.jetbrains.annotations.NotNull)1