org.commonmark.node.OrderedList Java Examples

The following examples show how to use org.commonmark.node.OrderedList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarkdownAssert.java    From doov with Apache License 2.0 5 votes vote down vote up
public IntegerAssert countOrderedList() {
    final AtomicInteger count = new AtomicInteger();
    actual.accept(new AbstractVisitor() {
        @Override
        public void visit(OrderedList orderedList) {
            count.incrementAndGet();
            super.visit(orderedList);
        }
    });
    return new IntegerAssert(count.get());
}
 
Example #2
Source File: BulletListIsOrderedWithLettersWhenNestedPlugin.java    From Markwon with Apache License 2.0 5 votes vote down vote up
private static boolean isBulletOrdered(@NonNull Node node) {
    node = node.getParent();
    while (node != null) {
        if (node instanceof OrderedList) {
            return true;
        }
        if (node instanceof BulletList) {
            return false;
        }
        node = node.getParent();
    }
    return false;
}
 
Example #3
Source File: OrderedListHolder.java    From 1Rramp-Android with MIT License 4 votes vote down vote up
public OrderedListHolder(ListHolder parent, OrderedList list) {
    super(parent);
    delimiter = list.getDelimiter();
    counter = list.getStartNumber();
}
 
Example #4
Source File: MarkwonVisitorImpl.java    From Markwon with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(OrderedList orderedList) {
    visit((Node) orderedList);
}
 
Example #5
Source File: CorePlugin.java    From Markwon with Apache License 2.0 4 votes vote down vote up
private static void orderedList(@NonNull MarkwonVisitor.Builder builder) {
    builder.on(OrderedList.class, new SimpleBlockNodeVisitor());
}
 
Example #6
Source File: BulletListIsOrderedWithLettersWhenNestedPlugin.java    From Markwon with Apache License 2.0 4 votes vote down vote up
@Override
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
    // NB that both ordered and bullet lists are represented
    //  by ListItem (must inspect parent to detect the type)
    builder.on(ListItem.class, (visitor, listItem) -> {
        // mimic original behaviour (copy-pasta from CorePlugin)

        final int length = visitor.length();

        visitor.visitChildren(listItem);

        final Node parent = listItem.getParent();
        if (parent instanceof OrderedList) {

            final int start = ((OrderedList) parent).getStartNumber();

            CoreProps.LIST_ITEM_TYPE.set(visitor.renderProps(), CoreProps.ListItemType.ORDERED);
            CoreProps.ORDERED_LIST_ITEM_NUMBER.set(visitor.renderProps(), start);

            // after we have visited the children increment start number
            final OrderedList orderedList = (OrderedList) parent;
            orderedList.setStartNumber(orderedList.getStartNumber() + 1);

        } else {
            CoreProps.LIST_ITEM_TYPE.set(visitor.renderProps(), CoreProps.ListItemType.BULLET);

            if (isBulletOrdered(parent)) {
                // obtain current count value
                final int count = currentBulletCountIn(parent);
                BULLET_LETTER.set(visitor.renderProps(), createBulletLetter(count));
                // update current count value
                setCurrentBulletCountIn(parent, count + 1);
            } else {
                CoreProps.BULLET_LIST_ITEM_LEVEL.set(visitor.renderProps(), listLevel(listItem));
                // clear letter info when regular bullet list is used
                BULLET_LETTER.clear(visitor.renderProps());
            }
        }

        visitor.setSpansForNodeOptional(listItem, length);

        if (visitor.hasNext(listItem)) {
            visitor.ensureNewLine();
        }
    });
}
 
Example #7
Source File: OrderedListHolder.java    From commonmark-java with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public OrderedListHolder(ListHolder parent, OrderedList list) {
    super(parent);
    delimiter = list.getDelimiter();
    counter = list.getStartNumber();
}