code: public BidiWrappingText spanWrappingText(@Nullable Dir dir, String str, boolean isHtml) {
      if (dir == null) {
        dir = estimateDirection(str, isHtml);
      }
  
      StringBuilder beforeText = new StringBuilder();
      StringBuilder afterText = new StringBuilder();
      boolean dirCondition = (dir != Dir.NEUTRAL && dir != contextDir);
      if (dirCondition) {
        beforeText.append("<span dir=\"").append(dir == Dir.RTL ? "rtl" : "ltr").append("\">");
        afterText.append("</span>");
      }
      afterText.append(markAfter(dir, str, isHtml));
      return BidiWrappingText.create(beforeText.toString(), afterText.toString());
    }
docs: Operates like {@link #spanWrap(Dir, String, boolean)} but only returns the text that would be
  prepended and appended to {@code str}.
  
  @param dir {@code str}'s directionality. If null, i.e. unknown, it is estimated.
  @param str The input string
  @param isHtml Whether {@code str} is HTML / HTML-escaped