Fixed plain text quote

pull/147/head
M66B 6 years ago
parent 253c5b1424
commit 4bfdc6b588

@ -296,14 +296,16 @@ public class HtmlHelper {
NodeTraversor.traverse(new NodeVisitor() { NodeTraversor.traverse(new NodeVisitor() {
private int qlevel = 0; private int qlevel = 0;
private int tlevel = 0;
public void head(Node node, int depth) { public void head(Node node, int depth) {
if (node instanceof TextNode) if (node instanceof TextNode) {
sb.append(((TextNode) node).text()).append(' '); append(((TextNode) node).text());
else { append(" ");
} else {
String name = node.nodeName(); String name = node.nodeName();
if ("li".equals(name)) if ("li".equals(name))
sb.append("* "); append("* ");
else if ("blockquote".equals(name)) else if ("blockquote".equals(name))
qlevel++; qlevel++;
@ -314,11 +316,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)) {
sb.append("[").append(node.absUrl("href")).append("] "); append("[");
if ("img".equals(name)) append(node.absUrl("href"));
sb.append("[").append(node.absUrl("src")).append("] "); append("] ");
else if ("th".equals(name) || "td".equals(name)) { } else if ("img".equals(name)) {
append("[");
append(node.absUrl("src"));
append("] ");
} 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();
@ -329,6 +335,14 @@ public class HtmlHelper {
newline(); newline();
} }
private void append(String text) {
if (tlevel != qlevel) {
newline();
tlevel = qlevel;
}
sb.append(text);
}
private void newline() { private void newline() {
trimEnd(sb); trimEnd(sb);
sb.append("\n"); sb.append("\n");

Loading…
Cancel
Save