class Cmark::EventIterator

Overview

An iterator that walks through a tree of nodes, starting from a root node, returning an Event with one node at a time, together with information about whether the node is being entered or exited, and if it is modifiable.

The iterator will first descend to a child node (returning an ENTER Event), if there is one. When there is no child, the iterator will go to the next sibling. When there is no next sibling, the iterator will return to the parent (but returning an EXIT Event). The iterator will stop after it reaches the root node again on exit.

One natural application is an HTML renderer, where an ENTER event outputs an open tag and an EXIT event outputs a close tag. An iterator might also be used to transform an AST in some systematic way, for example, turning all level-3 headings into regular paragraphs.

NOTE Nodes can be modified only after an EXIT event or an ENTER event for leaf nodes. The convenience method Event#modifiable? checks that these conditions are met.

Included Modules

Defined in:

cmark/event_iterator.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(root : Node) #

[View source]

Instance Method Detail

def modifiable_node_iterator : Iterator(Node) #

Returns an iterator with all the nodes in the order in which can be modified.


[View source]
def next #

Returns the next node event in this iterator, or Iterator::Stop::INSTANCE if there are no more events.


[View source]
def rewind #

Rewinds the iterator to its original state.


[View source]