private static void parseMarkup(PsiBuilder builder) {
    builder.advanceLexer();
    PsiBuilder.Marker marker = builder.mark();
    IElementType type = builder.getTokenType();
    if (type == RestTokenTypes.SUBSTITUTION) {
      builder.advanceLexer();
      marker.done(RestElementTypes.REFERENCE_TARGET);
      builder.advanceLexer();
      marker = builder.mark();
      type = builder.getTokenType();
    }
    if (type == RestTokenTypes.DIRECTIVE || type == RestTokenTypes.CUSTOM_DIRECTIVE) {
      gotoNextWhiteSpaces(builder);
      if (builder.getTokenType() != RestTokenTypes.WHITESPACE) {
        builder.advanceLexer();
        marker.done(RestElementTypes.DIRECTIVE_BLOCK);
        return;
      }
      skipBlankLines(builder);
      final String tokenText = builder.getTokenText();
      if (builder.getTokenType() != RestTokenTypes.LINE ||
          (tokenText != null && StringUtil.getLineBreakCount(tokenText) == tokenText.length())) {
        marker.done(RestElementTypes.DIRECTIVE_BLOCK);
        return;
      }
      String white = builder.getTokenText();
      parseDirective(builder, white, marker);
    }
    else if (type == RestTokenTypes.FOOTNOTE || type == RestTokenTypes.CITATION ||
             type == RestTokenTypes.HYPERLINK || type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
      builder.advanceLexer();
      marker.done(RestElementTypes.REFERENCE_TARGET);
    }
    else {
      builder.advanceLexer();
      marker.drop();
    }
  }
private static void parseMarkup(PsiBuilder builder)