Source:
public Spanned convert() { mReader.setContentHandler(this); try { mReader.parse(new InputSource(new StringReader(mSource))); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } Object[] obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), NeedsReversingSpan.class); for (int i = obj.length - 1; i >= 0; i--) { NeedsReversingSpan span = (NeedsReversingSpan) obj[i]; int start = mSpannableStringBuilder.getSpanStart(span); int end = mSpannableStringBuilder.getSpanEnd(span); mSpannableStringBuilder.removeSpan(span); mSpannableStringBuilder.setSpan(span.mActualSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class); for (Object anObj : obj) { int start = mSpannableStringBuilder.getSpanStart(anObj); int end = mSpannableStringBuilder.getSpanEnd(anObj); if (end - 2 >= 0 && (end - start) >= 2) { if (mSpannableStringBuilder.charAt(end - 1) == '\n' && mSpannableStringBuilder.charAt(end - 2) == '\n') { end--; } } if (end == start) { mSpannableStringBuilder.removeSpan(anObj); } else { mSpannableStringBuilder.setSpan(anObj, start, end, Spannable.SPAN_PARAGRAPH); } } while (mSpannableStringBuilder.length() > 0 && mSpannableStringBuilder.charAt(0) == '\n') { mSpannableStringBuilder.delete(0, 1); } int last = mSpannableStringBuilder.length() - 1; while (last >= 0 && mSpannableStringBuilder.charAt(last) == '\n') { mSpannableStringBuilder.delete(last, last + 1); last = mSpannableStringBuilder.length() - 1; } return mSpannableStringBuilder; }

Target:
public Spanned convert() { mReader.setContentHandler(this); try { mReader.parse(new InputSource(new StringReader(mSource))); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } Object[] obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), NeedsReversingSpan.class); for (int i = obj.length - 1; i >= 0; i--) { NeedsReversingSpan span = (NeedsReversingSpan) obj[i]; int start = mSpannableStringBuilder.getSpanStart(span); int end = mSpannableStringBuilder.getSpanEnd(span); mSpannableStringBuilder.removeSpan(span); mSpannableStringBuilder.setSpan(span.mActualSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class); for (Object span : obj) { int start = mSpannableStringBuilder.getSpanStart(span); int end = mSpannableStringBuilder.getSpanEnd(span); if (end - 2 >= 0 && (end - start) >= 2) { if (mSpannableStringBuilder.charAt(end - 1) == '\n' && mSpannableStringBuilder.charAt(end - 2) == '\n') { end--; } } if (end == start) { mSpannableStringBuilder.removeSpan(span); } else { mSpannableStringBuilder.setSpan(span, start, end, Spannable.SPAN_PARAGRAPH); } } while (mSpannableStringBuilder.length() > 0 && mSpannableStringBuilder.charAt(0) == '\n') { mSpannableStringBuilder.delete(0, 1); } int last = mSpannableStringBuilder.length() - 1; while (last >= 0 && mSpannableStringBuilder.charAt(last) == '\n') { mSpannableStringBuilder.delete(last, last + 1); last = mSpannableStringBuilder.length() - 1; } return mSpannableStringBuilder; }