private static StringBuilder formatPres(final StringBuilder input) {
        int start = input.indexOf(PRE_START);
        final int spaceAdvance = SPACE.length() - 1;
        final int breakAdvance = BREAK.length() - 1;
        while (start != -1) {
            int end = input.indexOf(PRE_END, start + PRE_START.length());
            if (end == -1) {
                break;
            }

            // Skip over code element
            if (input.indexOf(CODE_START, start) == start) {
                start += CODE_START.length();
            }
            if (input.indexOf(CODE_END, start) == end - CODE_END.length()) {
                end -= CODE_END.length();
            }

            for (int i = start; i < end; i++) {
                switch (input.charAt(i)) {
                    case ' ':
                        input.deleteCharAt(i);
                        input.insert(i, SPACE);
                        start += spaceAdvance;
                        end += spaceAdvance;
                        break;
                    case '\t':
                        input.deleteCharAt(i);
                        input.insert(i, SPACE);
                        start += spaceAdvance;
                        end += spaceAdvance;
                        for (int j = 0; j < 3; j++) {
                            input.insert(i, SPACE);
                            start += spaceAdvance + 1;
                            end += spaceAdvance + 1;
                        }
                        break;
                    case '\n':
                        input.deleteCharAt(i);
                        // Ignore if last character is a newline
                        if (i + 1 < end) {
                            input.insert(i, BREAK);
                            start += breakAdvance;
                            end += breakAdvance;
                        }
                        break;
                }
            }
            start = input.indexOf(PRE_START, end + PRE_END.length());
        }
        return input;
    }
Format given HTML string so it is ready to be presented in a text view

@param html
@return formatted HTML
app/src/main/java/com/github/pockethub/android/util/HtmlUtils.java