Improved plain text formatting

This commit is contained in:
M66B 2019-09-07 08:22:46 +02:00
parent d9a55ce0b2
commit e439d38ca6
1 changed files with 13 additions and 1 deletions

View File

@ -637,10 +637,18 @@ public class HtmlHelper {
NodeTraversor.traverse(new NodeVisitor() { NodeTraversor.traverse(new NodeVisitor() {
private int qlevel = 0; private int qlevel = 0;
private int tlevel = 0; private int tlevel = 0;
private int plevel = 0;
private boolean nl = true; 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)
if (plevel > 0) {
String[] lines = ((TextNode) node).getWholeText().split("\\r?\\n");
for (String line : lines) {
append(line);
newline();
}
} else
append(((TextNode) node).text()); append(((TextNode) node).text());
else { else {
String name = node.nodeName(); String name = node.nodeName();
@ -648,6 +656,8 @@ public class HtmlHelper {
append("*"); append("*");
else if ("blockquote".equals(name)) else if ("blockquote".equals(name))
qlevel++; qlevel++;
else if ("pre".equals(name))
plevel++;
if (heads.contains(name)) if (heads.contains(name))
newline(); newline();
@ -666,6 +676,8 @@ public class HtmlHelper {
newline(); newline();
} else if ("blockquote".equals(name)) } else if ("blockquote".equals(name))
qlevel--; qlevel--;
else if ("pre".equals(name))
plevel--;
if (tails.contains(name)) if (tails.contains(name))
newline(); newline();