private void emitClose(final @NotNull String tag) {
      // currently: we don't keep any arguments, does it ever make sense to?
      if (this.tagState.isTag) {
        if (this.tagState == TagState.MID) { // not _SELF_CLOSING
          this.consumer.append(TokenParser.CLOSE_TAG);
        }
        this.consumer.append(TokenParser.TAG_END);
        this.tagState = TagState.TEXT;
      } else {
        this.consumer.append(TokenParser.TAG_START)
          .append(TokenParser.CLOSE_TAG);
        this.escapeTagContent(tag, QuotingOverride.UNQUOTED);
        this.consumer.append(TokenParser.TAG_END);
      }
    }
mark tag boundaries within the stack, without needing to mess with typing too much.
text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/MiniMessageSerializer.java