@Override public void visit(HardLineBreak hardLineBreak) { newLine(); }
@Override public void visit(SoftLineBreak softLineBreak) { // @since 1.1.1 there is an option to treat soft break as a hard break (thus adding new line) if (configuration.softBreakAddsNewLine()) { newLine(); } else { builder.append(' '); } }
@Override public void visit(Heading heading) { newLine(); final int length = builder.length(); visitChildren(heading); setSpan(length, factory.heading(theme, heading.getLevel())); if (hasNext(heading)) { newLine(); // after heading we add another line anyway (no additional checks) forceNewLine(); } }
/** * @param info tag of a code block * @param code content of a code block * @since 1.0.4 */ private void visitCodeBlock(@Nullable String info, @NonNull String code, @NonNull Node node) { newLine(); final int length = builder.length(); // empty lines on top & bottom builder.append('\u00a0').append('\n'); builder.append( configuration.syntaxHighlight() .highlight(info, code) ); newLine(); builder.append('\u00a0'); setSpan(length, factory.code(theme, true)); if (hasNext(node)) { newLine(); forceNewLine(); } }
@Override public void visit(Paragraph paragraph) { final boolean inTightList = isInTightList(paragraph); if (!inTightList) { newLine(); } final int length = builder.length(); visitChildren(paragraph); // @since 1.1.1 apply paragraph span setSpan(length, factory.paragraph(inTightList)); if (hasNext(paragraph) && !inTightList) { newLine(); forceNewLine(); } }
/** * @since 1.0.1 */ @Override public void visit(CustomBlock customBlock) { if (customBlock instanceof TaskListBlock) { blockIndent += 1; visitChildren(customBlock); blockIndent -= 1; if (hasNext(customBlock)) { newLine(); forceNewLine(); } } else { super.visit(customBlock); } }
@Override public void visit(ListItem listItem) { final int length = builder.length(); blockIndent += 1; listLevel += 1; final Node parent = listItem.getParent(); if (parent instanceof OrderedList) { final int start = ((OrderedList) parent).getStartNumber(); visitChildren(listItem); setSpan(length, factory.orderedListItem(theme, start)); // after we have visited the children increment start number final OrderedList orderedList = (OrderedList) parent; orderedList.setStartNumber(orderedList.getStartNumber() + 1); } else { visitChildren(listItem); setSpan(length, factory.bulletListItem(theme, listLevel - 1)); } blockIndent -= 1; listLevel -= 1; if (hasNext(listItem)) { newLine(); } }
@Override public void visit(CustomNode customNode) { if (customNode instanceof Strikethrough) { final int length = builder.length(); visitChildren(customNode); setSpan(length, factory.strikethrough()); } else if (customNode instanceof TaskListItem) { // new in 1.0.1 final TaskListItem listItem = (TaskListItem) customNode; final int length = builder.length(); blockIndent += listItem.indent(); visitChildren(customNode); setSpan(length, factory.taskListItem(theme, blockIndent, listItem.done())); if (hasNext(customNode)) { newLine(); } blockIndent -= listItem.indent(); } else if (!handleTableNodes(customNode)) { super.visit(customNode); } }
newLine(); forceNewLine();