Fixed block new lines logic for block quote and paragraph

This commit is contained in:
Dimitry Ivanov 2018-12-01 14:48:03 +03:00
parent fb0faf6dfb
commit fac23ef17b

View File

@ -105,9 +105,6 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
public void visit(BlockQuote blockQuote) { public void visit(BlockQuote blockQuote) {
newLine(); newLine();
if (blockQuoteIndent != 0) {
builder.append('\n');
}
final int length = builder.length(); final int length = builder.length();
@ -121,9 +118,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(blockQuote)) { if (hasNext(blockQuote)) {
newLine(); newLine();
if (blockQuoteIndent == 0) { forceNewLine();
builder.append('\n');
}
} }
} }
@ -180,7 +175,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(node)) { if (hasNext(node)) {
newLine(); newLine();
builder.append('\n'); forceNewLine();
} }
} }
@ -202,9 +197,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(node)) { if (hasNext(node)) {
newLine(); newLine();
if (listLevel == 0 && blockQuoteIndent == 0) { forceNewLine();
builder.append('\n');
}
} }
} }
@ -256,7 +249,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(thematicBreak)) { if (hasNext(thematicBreak)) {
newLine(); newLine();
builder.append('\n'); forceNewLine();
} }
} }
@ -272,7 +265,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(heading)) { if (hasNext(heading)) {
newLine(); newLine();
// after heading we add another line anyway (no additional checks) // after heading we add another line anyway (no additional checks)
builder.append('\n'); forceNewLine();
} }
} }
@ -298,13 +291,14 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
public void visit(CustomBlock customBlock) { public void visit(CustomBlock customBlock) {
if (customBlock instanceof TaskListBlock) { if (customBlock instanceof TaskListBlock) {
blockQuoteIndent += 1; blockQuoteIndent += 1;
visitChildren(customBlock); visitChildren(customBlock);
blockQuoteIndent -= 1; blockQuoteIndent -= 1;
if (hasNext(customBlock)) { if (hasNext(customBlock)) {
newLine(); newLine();
builder.append('\n'); forceNewLine();
} }
} else { } else {
@ -358,7 +352,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(node)) { if (hasNext(node)) {
newLine(); newLine();
builder.append('\n'); forceNewLine();
} }
} else if (node instanceof TableRow || node instanceof TableHead) { } else if (node instanceof TableRow || node instanceof TableHead) {
@ -445,9 +439,7 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
if (hasNext(paragraph) && !inTightList) { if (hasNext(paragraph) && !inTightList) {
newLine(); newLine();
if (blockQuoteIndent == 0) { forceNewLine();
builder.append('\n');
}
} }
} }
@ -518,6 +510,10 @@ public class SpannableMarkdownVisitor extends AbstractVisitor {
} }
} }
private void forceNewLine() {
builder.append('\n');
}
private boolean isInTightList(Paragraph paragraph) { private boolean isInTightList(Paragraph paragraph) {
final Node parent = paragraph.getParent(); final Node parent = paragraph.getParent();
if (parent != null) { if (parent != null) {