ReST/ RST code generation (rstcode)

Description

The rstcode module supports code generation for the reST (RST) markup language.

To use the module in inline code generation import it by:

cogeno.import_module('rstcode')

In case you want to use the rstcode module in another Python project import it by:

import cogeno.modules.rstcode

Cogeno invocation options

There are NO Cogeno invocation options.

Code generation functions

cogeno.modules.rstcode.sanitize_target(target)

Sanitize target string.

Replace weired characters in the target string. Prevent _ at start and end of target string.

Return

Sanitized target string.

Get target reference.

Get the target reference for target string. The target string is sanitized by sanitize_target() before.

Return

Target reference.

cogeno.modules.rstcode.Node : public object

A node of a RST document.

Subclassed by cogeno.modules.rstcode.BulletList, cogeno.modules.rstcode.CodeBlock, cogeno.modules.rstcode.Comment, cogeno.modules.rstcode.Document, cogeno.modules.rstcode.LinkTarget, cogeno.modules.rstcode.OrderedList, cogeno.modules.rstcode.Paragraph, cogeno.modules.rstcode.Section, cogeno.modules.rstcode.Table, cogeno.modules.rstcode.Text

Public Functions

text_begin(self)

Get the text to be issued at beginning of node output.

Maybe overloaded by child classes to dynamically adapt the output text at out() processing.

Return

text

text_end(self)

Get the text to be issued at end of node output.

Maybe overloaded by child classes to dynamically adapt the output text at out() processing.

Return

text

add_child(self, node)

Add a Node object to the current node.

Return

True in case of success.

Parameters
  • node: Node to add as a child of this node.

out(self, out_redirect=None)

Output node content.

Parameters
  • output_redirect: Optional - redirect output, default is cogeno.out.

cogeno.modules.rstcode.Text : public cogeno.modules.rstcode.Node

A pure text node.

Public Functions

__init__(self, text)

Initialise the text node.

Parameters
  • text: Multiline text

cogeno.modules.rstcode.Comment : public cogeno.modules.rstcode.Node

A comment node.

Public Functions

__init__(self, text)

Initialise the comment node.

Parameters
  • text: Multiline text

cogeno.modules.rstcode.CodeBlock : public cogeno.modules.rstcode.Node

A code block node.

Public Functions

__init__(self, code, code_type='none')

Initialise the code block node.

Parameters
  • code: Multiline code

  • code_type: The type of code as understood by the code-block directive

cogeno.modules.rstcode.Paragraph : public cogeno.modules.rstcode.Node

A paragraph node.

Public Functions

__init__(self, text)

Initialise the paragraph node.

Parameters
  • text: Multiline text

cogeno.modules.rstcode.Section : public cogeno.modules.rstcode.Node

A section node.

Public Functions

__init__(self, title, depth=1)

Initialise the section node.

Parameters
  • title: Title of the section

  • depth: Either depth of the section, default is 1, or section mark character (e.g. ‘#’).

cogeno.modules.rstcode.BulletList : public cogeno.modules.rstcode.Node

A bullet list node.

Public Functions

__init__(self)

Initialise the bullet list node.

add_item(self, text)

Add new text block to the bullet list.

Parameters
  • text: Multiline text

cogeno.modules.rstcode.OrderedList : public cogeno.modules.rstcode.Node

A ordered list node.

Public Functions

__init__(self)

Initialise the ordered list node.

add_item(self, text)

Add new text block to the ordered list.

Parameters
  • text: Multiline text

cogeno.modules.rstcode.Table : public cogeno.modules.rstcode.Node

A table node.

Output will be done in csv-table style.

Public Functions

__init__(self, title='', headers=[], widths=[])

Initialise the paragraph node.

Parameters
  • title: the table title

  • headers: list of header items in the table

  • widths: list of column widths in the table

add_row(self, row)

Add new row to the table.

Parameters
  • row: List of column items in the row.

cogeno.modules.rstcode.LinkTarget : public cogeno.modules.rstcode.Node

A link target node.

Public Functions

__init__(self, target)

Initialise the link target node.

The target string will be santized using sanitize_target().

Parameters
  • target: Target

cogeno.modules.rstcode.Document : public cogeno.modules.rstcode.Node

A document node.

Public Functions

__init__(self, file_path=None)

Initialise the document node.

Parameters
  • file_path: Optional, file to write the document to

out(self, out_redirect=None)

Output document content.

If no out_redirect is provided the content is written to the file_path specified on initialisation. If also the file_path is not specified the output is re-directed to cogeno.out().

Parameters
  • output_redirect: Optional - redirect output, default is file_path.