use of com.vladsch.flexmark.ext.gfm.tasklist.TaskListItemPlacement 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);
}
Aggregations