Search in sources :

Example 1 with TaskListItem

use of com.vladsch.flexmark.ext.gfm.tasklist.TaskListItem in project flexmark-java by vsch.

the class TaskListItemBlockPreProcessor method preProcess.

@Override
public void preProcess(ParserState state, Block block) {
    if (block instanceof BulletListItem || block instanceof OrderedListItem) {
        // we chop up the previous paragraph into definition terms and add the definition item to the last one
        // we add all these to the previous DefinitionList or add a new one if there isn't one
        final ListItem listItem = (ListItem) block;
        final BasedSequence markerSuffix = listItem.getMarkerSuffix();
        if (markerSuffix.matches("[ ]") || markerSuffix.matches("[x]") || markerSuffix.matches("[X]")) {
            TaskListItem taskListItem = new TaskListItem(listItem);
            taskListItem.setTight(listItem.isTight());
            listItem.insertBefore(taskListItem);
            listItem.unlink();
            state.blockAdded(taskListItem);
            state.blockRemoved(listItem);
        }
    }
}
Also used : BulletListItem(com.vladsch.flexmark.ast.BulletListItem) TaskListItem(com.vladsch.flexmark.ext.gfm.tasklist.TaskListItem) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) OrderedListItem(com.vladsch.flexmark.ast.OrderedListItem) ListItem(com.vladsch.flexmark.ast.ListItem) BulletListItem(com.vladsch.flexmark.ast.BulletListItem) TaskListItem(com.vladsch.flexmark.ext.gfm.tasklist.TaskListItem) OrderedListItem(com.vladsch.flexmark.ast.OrderedListItem)

Example 2 with TaskListItem

use of com.vladsch.flexmark.ext.gfm.tasklist.TaskListItem in project flexmark-java by vsch.

the class TaskListNodeFormatter method renderList.

public static void renderList(final ListBlock node, final NodeFormatterContext context, MarkdownWriter markdown, FormatOptions formatOptions) {
    ArrayList<Node> itemList = new ArrayList<Node>();
    TaskListItemPlacement taskListItemPlacement = formatOptions.taskListItemPlacement;
    if (taskListItemPlacement != TaskListItemPlacement.AS_IS) {
        ArrayList<Node> incompleteTasks = new ArrayList<Node>();
        ArrayList<Node> completeItems = new ArrayList<Node>();
        boolean incompleteDescendants = taskListItemPlacement == TaskListItemPlacement.INCOMPLETE_NESTED_FIRST || taskListItemPlacement == TaskListItemPlacement.COMPLETE_NESTED_TO_NON_TASK;
        Node item = node.getFirstChild();
        while (item != null) {
            if (item instanceof TaskListItem) {
                TaskListItem taskItem = (TaskListItem) item;
                if (!taskItem.isItemDoneMarker() || (incompleteDescendants && hasIncompleteDescendants(item))) {
                    incompleteTasks.add(item);
                } else {
                    completeItems.add(item);
                }
            } else {
                if (incompleteDescendants && hasIncompleteDescendants(item)) {
                    incompleteTasks.add(item);
                } else {
                    completeItems.add(item);
                }
            }
            item = item.getNext();
        }
        itemList.addAll(incompleteTasks);
        itemList.addAll(completeItems);
    } else {
        Node item = node.getFirstChild();
        while (item != null) {
            itemList.add(item);
            item = item.getNext();
        }
    }
    CoreNodeFormatter.renderList(node, context, markdown, itemList);
}
Also used : TaskListItem(com.vladsch.flexmark.ext.gfm.tasklist.TaskListItem) ArrayList(java.util.ArrayList) TaskListItemPlacement(com.vladsch.flexmark.ext.gfm.tasklist.TaskListItemPlacement)

Aggregations

TaskListItem (com.vladsch.flexmark.ext.gfm.tasklist.TaskListItem)2 BulletListItem (com.vladsch.flexmark.ast.BulletListItem)1 ListItem (com.vladsch.flexmark.ast.ListItem)1 OrderedListItem (com.vladsch.flexmark.ast.OrderedListItem)1 TaskListItemPlacement (com.vladsch.flexmark.ext.gfm.tasklist.TaskListItemPlacement)1 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)1 ArrayList (java.util.ArrayList)1