Markup Machine

inyoka.markup.machine

This implements the ast compiler and evaluator. Most of the functionality here is available on the nodes itself because they mix those classes in, the renderer for compiled instructions is importable from the normal parser package.

copyright:
  1. 2007-2024 by the Inyoka Team, see AUTHORS for more details.

license:

BSD, see LICENSE for more details.

class inyoka.markup.machine.NodeCompiler

MixIn class for node instruction compiling. Most nodes mix this class in and obtain the compile method because of that.

compile(format)

Return a compiled instruction set.

class inyoka.markup.machine.NodeQueryInterface

Adds a query property to nodes implementing this interface. The query attribute returns a new Query object for the node that implements the query interface.

property query
class inyoka.markup.machine.NodeRenderer

MixedIn on all nodes so that you can render a node without compiling.

Nodes as such do not know how to render their own structure. That’s up to the Renderer which uses the instructions from either a node passed or a compiled instruction set. However this class is implemented by all non basic nodes and allows to stream and render the generated markup without having to instanciate a Renderer.

render(context, format)

Constructs a renderer for this nodes and renders it.

stream(context, format)

Constructs a renderer for this node and streams it.

class inyoka.markup.machine.Query(nodes, recurse=True)

Helper class to traverse a tree of nodes. Useful for tree processor macros that collect data from the final tree.

property all

Retrun a Query object for all nodes this node holds.

by_type(type)

Performs an instance test on all nodes.

property children

Return a new Query just for the direct children.

property has_any

Return True if at least one node was found.

text_nodes()

Only text nodes.

class inyoka.markup.machine.RenderContext(request=None, simplified=False, raw=False, application=None, **kwargs)

Holds information for the rendering systems. This can be used by macros to get a reference to the current context object, the wiki page that triggered the rendering or if the rendering should happen in simplified mode (disables dynamic macros).

Per definition a render context must be recreated before a rendering but shared among subrenderings. For example if you include a page you have to pass the render context object around. The reason for this is that only that allows you to track circular page inclusions.

property application
class inyoka.markup.machine.Renderer(obj)

This class can render nodes and compiled structures. One can pass it a node or a compiler instruction set (compiled by a NodeCompiler). In the first case the render method expects a format argument, in the latter the format argument should be ommited or must match the format of the compiled instruction set.

Instead of instanciating this class with a node it’s a better idea to use the NodeRenderer interface implemented by all concrete nodes.

render(context, format=None)

Streams into a buffer and returns it as string.

stream(context, format=None)

Creates a generator that yields the results of the instructions attached to the renderer. If the renderer was constructed from an instruction set you should not provide format so that it can use the format of the instruction set. If you do provide it the two format definitions must match.

If a node is attached to the renderer it will be prepared on the fly but the format parameter is mandatory then.