Fixed spacing plain text

pull/168/head
M66B 5 years ago
parent 151101ebc0
commit 86964b942d

@ -691,13 +691,14 @@ 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 int lindex = 0;
public void head(Node node, int depth) { public void head(Node node, int depth) {
if (node instanceof TextNode) if (node instanceof TextNode)
if (plevel > 0) { if (plevel > 0) {
String[] lines = ((TextNode) node).getWholeText().split("\\r?\\n"); String[] lines = ((TextNode) node).getWholeText().split("\\r?\\n");
for (String line : lines) { for (String line : lines) {
append(line); append(line, true);
newline(); newline();
} }
} else } else
@ -738,19 +739,31 @@ public class HtmlHelper {
} }
private void append(String text) { private void append(String text) {
append(text, false);
}
private void append(String text, boolean raw) {
if (tlevel != qlevel) { if (tlevel != qlevel) {
newline(); newline();
tlevel = qlevel; tlevel = qlevel;
} }
if (!raw && !"-- ".equals(text)) {
text = text.trim();
if (lindex > 0)
text = " " + text;
}
sb.append(text); sb.append(text);
lindex += text.length();
} }
private void newline() { private void newline() {
lindex = 0;
sb.append("\n"); sb.append("\n");
for (int i = 0; i < qlevel; i++) for (int i = 0; i < qlevel; i++)
sb.append('>'); sb.append("> ");
if (qlevel > 0)
sb.append(' ');
} }
}, JsoupEx.parse(html)); }, JsoupEx.parse(html));

Loading…
Cancel
Save