code: public static String preprocessWikiText(String text) {
          if (text==null) return "";
          text=text.trim();
          int length=text.length();
          char[] chars=new char[length];
          text.getChars(0, length, chars, 0);
          StringBuilder sb=new StringBuilder();
          boolean blankLine=true;
          StringBuilder spaces=new StringBuilder();
          for (int p=0; p<length; p++) {
              char c=chars[p];
              if (c=='\r') { // "\r\n" -> "\n"; then "\r" -> "\n"
                  if (p+1<length && chars[p+1]=='\n') p++;
                  sb.append('\n');
                  // discard spaces if there is nothing else on the line
                  spaces.delete(0, spaces.length());
                  blankLine=true;
              }
              else if (c=='\n') {
                  sb.append(c);
                  // discard spaces if there is nothing else on the line
                  spaces.delete(0, spaces.length());
                  blankLine=true;
              }
              else if (blankLine) {
                  if (c<=' '/* && c!='\n'*/) {
                      spaces.append(c);
                  }
                  else {
                      // working around GWT issue
                      // http://code.google.com/p/google-web-toolkit/issues/detail?id=4097
                      CharSequence cs = spaces;
                      sb.append(cs);
                      blankLine=false;
                      sb.append(c);
                  }
              }
              else {
                  sb.append(c);
              }
          }
          return sb.toString();
      }
docs: Filters text so there are no '\r' chars in it ("\r\n" -&gt; "\n"; then "\r" -&gt; "\n").
  Most importantly makes all blank lines (lines with only spaces) exactly like this: "\n\n".
  WikiParser relies on that.