class documentation

class Visitor(object): (source)

Known subclasses: zim.export.template.HeadingSplitter, zim.formats.DumperClass

View In Hierarchy

Conceptual opposite of a builder, but with same API. Used to walk nodes in a parsetree and call callbacks for each node. See e.g. ParseTree.visit().
Method append Convenience function to open a tag, append text and close it immediatly.
Method end No summary
Method start Start formatted region
Method text Append text @param text: text to be appended as string @implementation: optional for subclasses
def append(self, tag, attrib=None, text=None): (source)

Convenience function to open a tag, append text and close it immediatly.

Can raise VisitorStop or VisitorSkip, see start() for the conditions.

Parameters
tagthe tag name
attriboptional dict with attributes
textformatted text
Unknown Field: implementation
optional for subclasses, default implementation calls start(), text(), and end()
def end(self, tag): (source)
End formatted region
Parameters
tagthe tag name
Raises
AssertionErrorwhen tag does not match current state
Unknown Field: implementation
optional for subclasses
def start(self, tag, attrib=None): (source)

Start formatted region

Visitor objects can raise two exceptions in this method to influence the tree traversal:

  1. VisitorStop will cancel the current parsing, but without raising an error. So code implementing a visit method should catch this.
  2. VisitorSkip can be raised when the visitor wants to skip a node, and should prevent the implementation from further decending into this node
Parameters
tagthe tag name
attriboptional dict with attributes
Note
If the visitor modifies the attrib dict on nodes, this will modify the tree. If this is not intended, the implementation needs to take care to copy the attrib to break the reference.
Unknown Field: implementation
optional for subclasses
def text(self, text): (source)
Append text
Parameters
texttext to be appended as string
Unknown Field: implementation
optional for subclasses