|
|
|
@ -71,6 +71,7 @@ public class HtmlHelper {
|
|
|
|
|
private static final int PREVIEW_SIZE = 500; // characters
|
|
|
|
|
|
|
|
|
|
private static final float MIN_LUMINANCE = 0.5f;
|
|
|
|
|
private static final int TAB_SIZE = 2;
|
|
|
|
|
private static final int MAX_AUTO_LINK = 250;
|
|
|
|
|
private static final int TRACKING_PIXEL_SURFACE = 25; // pixels
|
|
|
|
|
|
|
|
|
@ -266,31 +267,68 @@ public class HtmlHelper {
|
|
|
|
|
|
|
|
|
|
// Pre formatted text
|
|
|
|
|
for (Element pre : document.select("pre")) {
|
|
|
|
|
Element div = document.createElement("font");
|
|
|
|
|
div.attr("face", "monospace");
|
|
|
|
|
|
|
|
|
|
int level = 0;
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
String[] lines = pre.wholeText().split("\\r?\\n");
|
|
|
|
|
for (String line : lines) {
|
|
|
|
|
// Opening quotes
|
|
|
|
|
int tlevel = 0;
|
|
|
|
|
while (line.startsWith(">")) {
|
|
|
|
|
tlevel++;
|
|
|
|
|
if (tlevel > level)
|
|
|
|
|
sb.append("<blockquote>");
|
|
|
|
|
|
|
|
|
|
line = line.substring(1); // >
|
|
|
|
|
|
|
|
|
|
if (line.startsWith(" "))
|
|
|
|
|
line = line.substring(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Closing quotes
|
|
|
|
|
for (int i = 0; i < level - tlevel; i++)
|
|
|
|
|
sb.append("</blockquote>");
|
|
|
|
|
level = tlevel;
|
|
|
|
|
|
|
|
|
|
// Tabs characters
|
|
|
|
|
StringBuilder l = new StringBuilder();
|
|
|
|
|
for (int j = 0; j < line.length(); j++) {
|
|
|
|
|
char kar = line.charAt(j);
|
|
|
|
|
if (kar == '\t') {
|
|
|
|
|
l.append(' ');
|
|
|
|
|
while (l.length() % TAB_SIZE != 0)
|
|
|
|
|
l.append(' ');
|
|
|
|
|
} else
|
|
|
|
|
l.append(kar);
|
|
|
|
|
}
|
|
|
|
|
line = l.toString();
|
|
|
|
|
|
|
|
|
|
// Html characters
|
|
|
|
|
line = Html.escapeHtml(line);
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
// Space characters
|
|
|
|
|
int len = line.length();
|
|
|
|
|
for (int j = 0; j < len; j++) {
|
|
|
|
|
char kar = line.charAt(j);
|
|
|
|
|
if (kar == ' ' &&
|
|
|
|
|
j + 1 < len && line.charAt(j + 1) == ' ')
|
|
|
|
|
sb.append(" ");
|
|
|
|
|
else
|
|
|
|
|
if (kar == ' ') {
|
|
|
|
|
// Prevent trimming start
|
|
|
|
|
// Keep one space for word wrapping
|
|
|
|
|
if (j == 0 || (j + 1 < len && line.charAt(j + 1) == ' '))
|
|
|
|
|
sb.append(" ");
|
|
|
|
|
else
|
|
|
|
|
sb.append(' ');
|
|
|
|
|
} else
|
|
|
|
|
sb.append(kar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element span = document.createElement("span");
|
|
|
|
|
span.html(sb.toString());
|
|
|
|
|
div.appendChild(span);
|
|
|
|
|
div.appendElement("br");
|
|
|
|
|
sb.append("<br>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pre.replaceWith(div);
|
|
|
|
|
// Closing quotes
|
|
|
|
|
for (int i = 0; i < level; i++)
|
|
|
|
|
sb.append("</blockquote>");
|
|
|
|
|
|
|
|
|
|
pre.tagName("tt"); // monospace
|
|
|
|
|
pre.html(sb.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Code
|
|
|
|
|