A node is the combination of a headline (in the outline pane) and its associated body text. A node is a real Python object. Each node has an unique identity. Nodes persist. When you save a Leo outline to a file, you are saving the outline's nodes.

You could say that nodes are what make Leo unique. In fancier language, Leo has a DOM (Document Object Model). Leo treats data as true objects, having inherent structure. In Leo, nothing is "just" text. It is, at minimum, text in context (the context of a node, and the context of the node's position in the outline.)

Leo creates a new way of understanding data. We call this change of perspective the Leo way. The consequences of this new view of data are wide ranging. Let's start with the simplest example.

Any node can contain a Leo (Python) script. Leo's execute-script command (Ctrl-b by default) executes the script (in the body text) using Python's exec statement. The exec statement pre-defines three variables: c, g and p. c is the commander of the outline. Naturally, a commander is a real Python object, with many methods useful to scripts. g is Leo's leoGlobals module containing many utility functions of use to scripts.

p is the position of the presently selected node in the outline at the time the script is executed. Positions are themselves Python objects, with many useful methods and attributes. Given a position p, p.h is the node's headline text and p.b is the node's body text. Nodes can have any kind and amount of data, called user data, p.u. Scripts can set headline, body and user data by assigning data to p.b, p.h and p.h. Scripts can assign any data to p.u providing the data is pickleable.

You can access all data in an outline using iterators defined in commander. For example, c.allNodes_iter returns every position in the outline in outline order (the order in which nodes would appear in the outline if all headlines were expanded). For example, the following script:

for p in c.allNodes_iter:
    print p.level() * ' ',p.h

prints all headlines of all nodes of the outline, in outline order, indented to show their hierarchical relationships with parent or child nodes.

Note: p.level() is a method of the position class. It returns 0 for top-level nodes, 1 for their children, 2 for their grandchildren. There are many other useful methods of the position class...

The next section [Scripting Leo: Node Types and @test]? discusses some of Leo's most powerful and unique features.