Improved plain text format

pull/167/head
M66B 5 years ago
parent 7f2e2256e5
commit 876c9f9c7d

@ -624,7 +624,6 @@ public class HtmlHelper {
private int qlevel = 0; private int qlevel = 0;
private int tlevel = 0; private int tlevel = 0;
private int plevel = 0; private int plevel = 0;
private boolean nl = true;
public void head(Node node, int depth) { public void head(Node node, int depth) {
if (node instanceof TextNode) if (node instanceof TextNode)
@ -653,13 +652,15 @@ public class HtmlHelper {
public void tail(Node node, int depth) { public void tail(Node node, int depth) {
String name = node.nodeName(); String name = node.nodeName();
if ("a".equals(name)) if ("a".equals(name))
append("[" + node.attr("href") + "] "); append("[" + node.attr("href") + "]");
else if ("img".equals(name)) else if ("img".equals(name))
append("[" + node.attr("src") + "] "); append("[" + node.attr("src") + "]");
else if ("th".equals(name) || "td".equals(name)) { else if ("th".equals(name) || "td".equals(name)) {
Node next = node.nextSibling(); Node next = node.nextSibling();
if (next == null || !("th".equals(next.nodeName()) || "td".equals(next.nodeName()))) if (next == null || !("th".equals(next.nodeName()) || "td".equals(next.nodeName())))
newline(); newline();
else
append(" ");
} else if ("blockquote".equals(name)) } else if ("blockquote".equals(name))
qlevel--; qlevel--;
else if ("pre".equals(name)) else if ("pre".equals(name))
@ -674,12 +675,7 @@ public class HtmlHelper {
newline(); newline();
tlevel = qlevel; tlevel = qlevel;
} }
if (!nl &&
(text != null && !text.startsWith(" ")) &&
(sb.length() > 0 && sb.charAt(sb.length() - 1) != ' '))
sb.append(" ");
sb.append(text); sb.append(text);
nl = false;
} }
private void newline() { private void newline() {
@ -688,7 +684,6 @@ public class HtmlHelper {
sb.append('>'); sb.append('>');
if (qlevel > 0) if (qlevel > 0)
sb.append(' '); sb.append(' ');
nl = true;
} }
}, JsoupEx.parse(html)); }, JsoupEx.parse(html));

Loading…
Cancel
Save