private static void validateAndAddTag(@NotNull List<MarkupNode> markupNodes,
                                        @NotNull String tagName,
                                        @NotNull Map<String, Attribute> attrs,
                                        @NotNull TextRange range) {
    String region = getRegion(attrs);
    switch (tagName) {
      case "start" -> {
        region = getRequiredString(markupNodes, attrs, tagName, range, "region");
        if (region != null) {
          markupNodes.add(new StartRegion(range, region));
        }
      }
      case "end" -> markupNodes.add(new EndRegion(range, region));
      case "highlight" -> {
        Attribute typeAttr = attrs.get("type");
        HighlightType type = getEnumValue(markupNodes, "highlight", typeAttr, HighlightType.class, HighlightType.HIGHLIGHTED);
        Selector selector = getSelector(markupNodes, attrs, tagName);
        if (selector != null) {
          markupNodes.add(new Highlight(range, selector, region, type));
        }
        else if (region != null) {
          markupNodes.add(new StartRegion(range, region));
        }
      }
      case "replace" -> {
        String replacement = getRequiredString(markupNodes, attrs, tagName, range, "replacement");
        Selector selector = getSelector(markupNodes, attrs, tagName);
        if (replacement != null && selector != null) {
          markupNodes.add(new Replace(range, selector, region, replacement));
        }
        else if (region != null) {
          markupNodes.add(new StartRegion(range, region));
        }
      }
      case "link" -> {
        String target = getRequiredString(markupNodes, attrs, tagName, range, "target");
        Attribute typeAttr = attrs.get("type");
        LinkType type = getEnumValue(markupNodes, "link", typeAttr, LinkType.class, LinkType.LINK);
        Selector selector = getSelector(markupNodes, attrs, tagName);
        if (target != null && selector != null) {
          markupNodes.add(new Link(range, selector, region, target, type));
        }
        else if (region != null) {
          markupNodes.add(new StartRegion(range, region));
        }
      }
      default -> throw new AssertionError("Unexpected tag: " + tagName);
    }
  }
private static void validateAndAddTag(@NotNull List<MarkupNode> markupNodes,
                                        @NotNull String tagName,
                                        @NotNull Map<String, Attribute> attrs,
                                        @NotNull TextRange range)