Parser

class lira.parsers.BaseParser(content: str, source: pathlib.Path = None)

Base class for a parser.

The parser should parse the metadata from the file as a dictionary, and the content should be a list of nodes that subclass lira.parsers.nodes.Node.

Parameters
  • content – Content to parse

  • source – Source file of the content

class lira.parsers.rst.RSTParser(*args, **kwargs)

reStructuredText parser for lira, powered by docutils.

Nodes

class lira.parsers.nodes.Node(content=None, *, children=None, attributes=None)

Base class for a node.

Parameters
  • content – Content for this node (usually only for terminal nodes).

  • children – List of children.

  • attributes – Dictionary of valid attributes.

If it’s a terminal node, it doesn’t have children. Only attributes from valid_attributes are recognized.

is_terminal = False

If it’s a terminal node (without children)

valid_attributes = {}

A set of valid attributes for this node.

content

Raw content of the node

children

List of children of this node.

attributes

Named tuple with the attributes for this node

parent

Parent node

reset()

Reset attributes and content of the node to their initial values.

text()

Text representation of the node.

property tagname

Name of the node.

class lira.parsers.nodes.Paragraph(content=None, *, children=None, attributes=None)

Container for inline nodes.

Inline nodes are:

class lira.parsers.nodes.Text(content=None, *, children=None, attributes=None)

Plain text node.

class lira.parsers.nodes.Strong(content=None, *, children=None, attributes=None)

Text represented as bold.

class lira.parsers.nodes.Emphasis(content=None, *, children=None, attributes=None)

Text represented as italics.

class lira.parsers.nodes.Literal(content=None, *, children=None, attributes=None)

Text represented with a mono space font.

class lira.parsers.nodes.Section(content=None, *, children=None, attributes=None)

Section representation.

Attributes:

  • title

Children can be any of:

class lira.parsers.nodes.Admonition(content=None, *, children=None, attributes=None)

Text inside a box, usually to give a warning or a note to the user.

Attributes:

  • title: The title of the admonition, defaults to type.

  • type: one of note, warning, or tip.

Children can be any of:

class lira.parsers.nodes.CodeBlock(content=None, *, children=None, attributes=None)

Syntax highlighted block.

The content of this node should be a list of lines.

Attributes:

  • language

class lira.parsers.nodes.TestBlock(*args, **kwargs)

Challenge/response block to interact with the user.

Attributes:

validate()

Run the validator for this node.

class lira.parsers.nodes.Prompt(content=None, *, children=None, attributes=None)