Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.
mattt edited this page Feb 24, 2021 · 14 revisions

List

A list.

public final class List: Node

From the CommonMark Spec:

A list is a sequence of one or more list items of the same type. The list items may be separated by any number of blank lines.

A list marker is a bullet list marker or an ordered list marker.

An ordered list marker is a sequence of 1–9 arabic digits (0-9), followed by either a . character or a ) character. (The reason for the length limit is that with 10 digits we start seeing integer overflows in some browsers.)

Inheritance

Node, Visitable

Initializers

init(delimiter:children:)

public convenience init(delimiter: Delimiter = .none, children: [List.Item] = [])

init(delimiter:tight:_:)

public convenience init(delimiter: Delimiter = .none, tight: Bool = true, _ builder: () -> ListItemConvertible)

init(of:delimiter:tight:_:)

public convenience init<Values>(of values: Values, delimiter: Delimiter = .none, tight: Bool = true, _ builder: (Values.Element) -> ListItemConvertible) where Values: Sequence

init(of:delimiter:tight:_:)

public convenience init<Values>(of values: Values, delimiter: Delimiter = .none, tight: Bool = true, _ closure: (Values.Element) -> String) where Values: Sequence

Properties

kind

var kind: Kind

delimiter

var delimiter: Delimiter

loose

Whether the list is loose.

var loose: Bool

From the CommonMark Spec:

A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight.

tight

Whether the list is tight.

var tight: Bool

children

The list's items.

var children: [Item]

Methods

prepend(child:)

Adds an item to the beginning of the list.

@discardableResult public func prepend(child: Item) -> Bool

Parameters

  • child: The item to add.

Returns

true if successful, otherwise false.

append(child:)

Adds an to the end of the list.

@discardableResult public func append(child: Item) -> Bool

Parameters

  • child: The item to add.

Returns

true if successful, otherwise false.

insert(child:before:)

Inserts an item to the list before a specified sibling.

@discardableResult public func insert(child: Item, before sibling: Item) -> Bool

Parameters

  • child: The item to add.
  • sibling: The item before which the new item is added

Returns

true if successful, otherwise false.

insert(child:after:)

Inserts an item to the list after a specified sibling.

@discardableResult public func insert(child: Item, after sibling: Item) -> Bool

Parameters

  • child: The item to add.
  • sibling: The item after which the new item is added

Returns

true if successful, otherwise false.

replace(child:with:)

Replaces an item with the specified node.

@discardableResult public func replace(child: Item, with replacement: Item) -> Bool

Parameters

  • child: The item to replace.
  • replacement: The item to replace the existing item.

Returns

true if successful, otherwise false.

remove(child:)

Removes an item from the list.

@discardableResult public func remove(child: Item) -> Bool

Parameters

  • child: The item to remove.

Returns

true if successful, otherwise false.

removeChildren()

Removes and returns the list's items.

@discardableResult public func removeChildren() -> [Item]

Returns

An array of list items.

accept(visitor:)

public func accept<T: Visitor>(visitor: T)
Clone this wiki locally