@NonNull static BlockImpl root() { return new BlockImpl("", 0, Collections.<String, String>emptyMap(), null); }
@Nullable protected HtmlTagImpl.BlockImpl findOpenBlockTag(@NonNull String name) { HtmlTagImpl.BlockImpl blockTag = currentBlock; while (blockTag != null && !name.equals(blockTag.name) && !blockTag.isClosed()) { blockTag = blockTag.parent; } return blockTag; }
@Override public void reset() { inlineTags.clear(); currentBlock = HtmlTagImpl.BlockImpl.root(); }
currentBlock.closeAt(output.length()); appendQuietly(output, '\n'); currentBlock = currentBlock.parent; && TAG_LIST_ITEM.equals(currentBlock.name)) { currentBlock.closeAt(output.length()); currentBlock = currentBlock.parent; final HtmlTagImpl.BlockImpl block = HtmlTagImpl.BlockImpl.create(name, start, extractAttributes(startTag), currentBlock); appendQuietly(output, replacement); block.closeAt(output.length());
protected <T extends Appendable & CharSequence> void processBlockTagEnd( @NonNull T output, @NonNull Token.EndTag endTag) { final String name = endTag.normalName; final HtmlTagImpl.BlockImpl block = findOpenBlockTag(endTag.normalName); if (block != null) { if ("pre".equals(name)) { isInsidePreTag = false; } // okay, if this tag is empty -> call replacement if (isEmpty(output, block)) { appendEmptyTagReplacement(output, block); } block.closeAt(output.length()); // if it's empty -> we do no care about if it's block or not if (!block.isEmpty()) { previousIsBlock = isBlockTag(block.name); } if (TAG_PARAGRAPH.equals(name)) { appendQuietly(output, '\n'); } this.currentBlock = block.parent; } }
@Override public void flushBlockTags(int documentLength, @NonNull FlushAction<Block> action) { HtmlTagImpl.BlockImpl block = currentBlock; while (block.parent != null) { block = block.parent; } if (documentLength > HtmlTag.NO_END) { block.closeAt(documentLength); } final List<Block> children = block.children(); if (children.size() > 0) { action.apply(children); } else { action.apply(Collections.<Block>emptyList()); } currentBlock = HtmlTagImpl.BlockImpl.root(); }
@NonNull static BlockImpl create( @NonNull String name, int start, @NonNull Map<String, String> attributes, @Nullable BlockImpl parent) { return new BlockImpl(name, start, attributes, parent); }