Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should do some replacements on the text programmatically. Here are some clues:</p> <ul> <li>All Newlines should be converted to <code>"&lt;br&gt;\n"</code> (The \n for better readability of the output).</li> <li>All CRs should be dropped (who uses DOS encoding anyway).</li> <li>All pairs of spaces should be replaced with <code>" &amp;nbsp;"</code></li> <li>Replace "&lt;" with <code>"&amp;lt;"</code></li> <li>Replace "&amp;" with <code>"&amp;amp;"</code></li> <li>All other characters &lt; 128 should be left as they are.</li> <li>All other characters >= 128 should be written as <code>"&amp;#"+((int)myChar)+";"</code>, to make them readable in every encoding.</li> <li>To autodetect your links, you could either use a regex like <code>"http://[^ ]+"</code>, or <code>"www.[^ ]"</code> and convert them like <strong>JB Nizet</strong> said. to <code>"&lt;a href=\""+url+"\"&gt;"+url+"&lt;/a&gt;"</code>, but only after having done all the other replacements.</li> </ul> <p>The code to do this looks something like this:</p> <pre><code>public static String escape(String s) { StringBuilder builder = new StringBuilder(); boolean previousWasASpace = false; for( char c : s.toCharArray() ) { if( c == ' ' ) { if( previousWasASpace ) { builder.append("&amp;nbsp;"); previousWasASpace = false; continue; } previousWasASpace = true; } else { previousWasASpace = false; } switch(c) { case '&lt;': builder.append("&amp;lt;"); break; case '&gt;': builder.append("&amp;gt;"); break; case '&amp;': builder.append("&amp;amp;"); break; case '"': builder.append("&amp;quot;"); break; case '\n': builder.append("&lt;br&gt;"); break; // We need Tab support here, because we print StackTraces as HTML case '\t': builder.append("&amp;nbsp; &amp;nbsp; &amp;nbsp;"); break; default: if( c &lt; 128 ) { builder.append(c); } else { builder.append("&amp;#").append((int)c).append(";"); } } } return builder.toString(); } </code></pre> <p>However, the link conversion has yet to be added. If someone does it, please update the code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload