@Override public void visit(Emphasis emphasis) { final int length = builder.length(); visitChildren(emphasis); setSpan(length, factory.emphasis()); }
@Override public void visit(StrongEmphasis strongEmphasis) { final int length = builder.length(); visitChildren(strongEmphasis); setSpan(length, factory.strongEmphasis()); }
@Override public void visit(Code code) { final int length = builder.length(); // NB, in order to provide a _padding_ feeling code is wrapped inside two unbreakable spaces // unfortunately we cannot use this for multiline code as we cannot control where a new line break will be inserted builder.append('\u00a0'); builder.append(code.getLiteral()); builder.append('\u00a0'); setSpan(length, factory.code(theme, false)); }
@Override public void visit(Link link) { final int length = builder.length(); visitChildren(link); final String destination = configuration.urlProcessor().process(link.getDestination()); setSpan(length, factory.link(theme, destination, configuration.linkResolver())); }
@Override public void visit(ThematicBreak thematicBreak) { newLine(); final int length = builder.length(); builder.append('\u00a0'); // without space it won't render setSpan(length, factory.thematicBreak(theme)); if (hasNext(thematicBreak)) { newLine(); forceNewLine(); } }
@Override public void visit(BlockQuote blockQuote) { newLine(); final int length = builder.length(); blockIndent += 1; visitChildren(blockQuote); setSpan(length, factory.blockQuote(theme)); blockIndent -= 1; if (hasNext(blockQuote)) { newLine(); forceNewLine(); } }
@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(); } }
/** * @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(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); } }
@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(); } }
@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(); } }
@Override public void visit(Image image) { final int length = builder.length(); visitChildren(image); // we must check if anything _was_ added, as we need at least one char to render if (length == builder.length()) { builder.append('\uFFFC'); } final Node parent = image.getParent(); final boolean link = parent != null && parent instanceof Link; final String destination = configuration.urlProcessor().process(image.getDestination()); setSpan( length, factory.image( theme, destination, configuration.asyncDrawableLoader(), configuration.imageSizeResolver(), null, link ) ); // todo, maybe, if image is not inside a link, we should make it clickable, so // user can open it in external viewer? }
: tableRows + 1; setSpan(addNewLine ? length + 1 : length, span);