docs: private void maybeCollapseWhitespace(@Nullable String next) {
      if (basicStartOfWhitespace != -1) {
        if (basicHasNewline) {
          // Note: if we are replacing the whitespace we don't need to update our source location
          // information.  This is because
          // 1. if we are stripping leading whitespace, the next token will be the start token
          //    - note: if there is no next token, the whole raw text node will get dropped, so we
          //      won't need a source location
          // 2. if we are stripping trailing whitespace, the previously assigned location should be
          //    preserved
          // 3. if we are in the middle, then our location is irrelevant
          offsets.delete(basicStartOfWhitespace);
          if (basicStart == basicStartOfWhitespace || next == null) {
            // leading or trailing whitespace, remove it all
            buffer.setLength(basicStartOfWhitespace);
            if (next == null && endColumnAtStartOfWhitespace != -1) {
              // if this is trailing whitespace, then our end location will be wrong, so restore it to
              // what it was when we started accumulating whitespace (assuming we had one).
              offsets.setEndLocation(endLineAtStartOfWhitespace, endColumnAtStartOfWhitespace);
            }
          } else {
            // We are in the middle, we either remove the whole segment or replace it with a single
            // space character based on whether or not we appear to be butted up next to an html tag.
            // This logic is definitely suspicious but it is important to maintain for compatibility
            // reasons.
            if (next.charAt(0) == '<' || buffer.charAt(basicStartOfWhitespace - 1) == '>') {
              // we are immediately before or after an html tag.
              buffer.setLength(basicStartOfWhitespace);
            } else {
              // Otherwise, collapse to a single whitespace character.
              buffer.setLength(basicStartOfWhitespace);
              buffer.append(' ');
            }
          }
          discontinuityReason = Reason.WHITESPACE;
          basicHasNewline = false;
        }
        basicStartOfWhitespace = -1;
      }
    }