Reference

rst2html5_ Module

class rst2html5_.ElemStack(settings)[source]

Helper class to handle nested contexts and indentation

append(element, indent=True)[source]

Append to current element

begin_elem()[source]

Start a new element context

commit_elem(elem, indent=True)[source]

A new element is create by removing its stack to make a tag. This tag is pushed back into its parent’s stack.

class rst2html5_.FooterToBottom(document, startnode=None)[source]

The doctree must be adjusted before translation begins since in-place tree modifications doesn’t work.

The footer must be relocated to the bottom of the doctree in order to be translated at the right position.

apply()[source]

Override to apply the transform to the document tree.

class rst2html5_.HTML5Translator(document)[source]
default_departure(node)[source]

Create the node’s corresponding HTML5 element and combine it with its stored context.

default_visit(node)[source]

Initiate a new context to store inner HTML5 elements.

depart_colspec(node)[source]

<col /> tags are not generated anymore because they’re pretty useless since they cannot receive any attribute from a rst table. Anyway, there are better ways to apply styles to columns. See http://csswizardry.com/demos/zebra-striping/ for example.

Nevertheless, if a colspec node with a “stub” attribute indicates that the column should be a th tag.

depart_enumerated_list(node)[source]

Ordered list. It may have a preffix and suffix that must be handled by CSS3 and javascript to be presented as intended.

do_nothing(node)[source]

equivalent to visit: pass and depart: pass

once_attr(name, default=None)[source]

The attribute is used once and then it is deleted

parse(node)[source]

Get tag name, indentantion and correct attributes of a node according to its class

skip_node(node)[source]

Internal only

visit_citation_reference(node)[source]

Instead of a typical visit_reference call this def is required to remove the backref id that is included but not used in rst2html5.

visit_classifier(node)[source]

Classifier should remain beside the previous element

visit_line_block(node)[source]

Line blocks use <pre>. Lines breaks and spacing are reconstructured based on line_block_level

visit_literal_block(node)[source]

Translates a code-block/sourcecode or a parsed-literal block.

Pygments is used for highlighting by the code-block directive. See CodeBlock directive source code for more information.

visit_math_block(node)[source]

Only MathJax support

class rst2html5_.HTML5Writer[source]
assemble_parts()[source]

Assemble the self.parts dictionary. Extend in subclasses.

get_transforms()[source]

Transforms required by this class. Override in subclasses.

translate()[source]

Do final translation of self.document into self.output. Called from write. Override in subclasses.

Usually done with a docutils.nodes.NodeVisitor subclass, in combination with a call to docutils.nodes.Node.walk() or docutils.nodes.Node.walkabout(). The NodeVisitor subclass must support all standard elements (listed in docutils.nodes.node_class_names) and possibly non-standard elements used by the current Reader as well.

class rst2html5_.WrapTopTitle(document, startnode=None)[source]

If the top element of a document is a title, wrap all the document’s children within a section.

For example:

<span class="p">..</span> <span class="nt">_outer_target:</span>
<span class="p">..</span> <span class="nt">_inner_target:</span>

<span class="gh">Title 1</span>
<span class="gh">=======</span>

The targets outer_target_ and inner_target_ point both to Title 1

The previous snippet should be transformed from:

<span class="nt">&lt;document</span> <span class="na">ids=</span><span class="s">&quot;title-1 inner-target outer-target&quot;</span> <span class="err">\</span>
<span class="na">names=</span><span class="s">&quot;title\ 1 inner_target outer_target&quot;</span> <span class="na">source=</span><span class="s">&quot;internal_link_2.rst&quot;</span> <span class="err">\</span>
<span class="na">title=</span><span class="s">&quot;Title 1&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;title&gt;</span>
    Title 1
<span class="nt">&lt;target</span> <span class="na">refid=</span><span class="s">&quot;outer-target&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;target</span> <span class="na">refid=</span><span class="s">&quot;inner-target&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;paragraph&gt;</span>
    The targets
    <span class="nt">&lt;reference</span> <span class="na">name=</span><span class="s">&quot;outer_target&quot;</span> <span class="na">refid=</span><span class="s">&quot;outer-target&quot;</span><span class="nt">&gt;</span>
        outer_target
     and
    <span class="nt">&lt;reference</span> <span class="na">name=</span><span class="s">&quot;inner_target&quot;</span> <span class="na">refid=</span><span class="s">&quot;inner-target&quot;</span><span class="nt">&gt;</span>
        inner_target
     point both to Title 1

into:

<span class="nt">&lt;document</span> <span class="na">source=</span><span class="s">&quot;internal_link_2.rst&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;section</span> <span class="na">ids=</span><span class="s">&quot;title-1 inner-target outer-target&quot;</span> <span class="na">names=</span><span class="s">&quot;title\ 1 inner_target outer_target&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;title&gt;</span>
        Title 1
    <span class="nt">&lt;paragraph&gt;</span>
        The targets
        <span class="nt">&lt;reference</span> <span class="na">name=</span><span class="s">&quot;outer_target&quot;</span> <span class="na">refid=</span><span class="s">&quot;outer-target&quot;</span><span class="nt">&gt;</span>
            outer_target
         and
        <span class="nt">&lt;reference</span> <span class="na">name=</span><span class="s">&quot;inner_target&quot;</span> <span class="na">refid=</span><span class="s">&quot;inner-target&quot;</span><span class="nt">&gt;</span>
            inner_target
         point both to Title 1
apply()[source]

Override to apply the transform to the document tree.

docutils

Classes

class docutils.nodes.NodeVisitor(document)[source]

“Visitor” pattern [GoF95] abstract superclass implementation for document tree traversals.

Each node class has corresponding methods, doing nothing by default; override individual methods for specific and useful behaviour. The dispatch_visit() method is called by Node.walk() upon entering a node. Node.walkabout() also calls the dispatch_departure() method before exiting a node.

The dispatch methods call “visit_ + node class name” or “depart_ + node class name”, resp.

This is a base class for visitors whose visit_... & depart_... methods should be implemented for all node types encountered (such as for docutils.writers.Writer subclasses). Unimplemented methods will raise exceptions.

For sparse traversals, where only certain node types are of interest, use subclass SparseNodeVisitor instead. When (mostly or entirely) uniform processing is desired, subclass GenericNodeVisitor.

[GoF95]Gamma, Helm, Johnson, Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading, MA, USA, 1995.
class docutils.writers.Writer[source]

Abstract base class for docutils Writers.

Each writer module or package must export a subclass also called ‘Writer’. Each writer must support all standard node types listed in docutils.nodes.node_class_names.

The write() method is the main entry point.

Methods

Writer.translate()[source]

Do final translation of self.document into self.output. Called from write. Override in subclasses.

Usually done with a docutils.nodes.NodeVisitor subclass, in combination with a call to docutils.nodes.Node.walk() or docutils.nodes.Node.walkabout(). The NodeVisitor subclass must support all standard elements (listed in docutils.nodes.node_class_names) and possibly non-standard elements used by the current Reader as well.

NodeVisitor.dispatch_visit(node)[source]

Call self.”visit_ + node class name” with node as parameter. If the visit_... method does not exist, call self.unknown_visit.

NodeVisitor.dispatch_departure(node)[source]

Call self.”depart_ + node class name” with node as parameter. If the depart_... method does not exist, call self.unknown_departure.

Node.walk(visitor)[source]

Traverse a tree of Node objects, calling the dispatch_visit() method of visitor when entering each node. (The walkabout() method is similar, except it also calls the dispatch_departure() method before exiting each node.)

This tree traversal supports limited in-place tree modifications. Replacing one node with one or more nodes is OK, as is removing an element. However, if the node removed or replaced occurs after the current node, the old node will still be traversed, and any new nodes will not.

Within visit methods (and depart methods for walkabout()), TreePruningException subclasses may be raised (SkipChildren, SkipSiblings, SkipNode, SkipDeparture).

Parameter visitor: A NodeVisitor object, containing a visit implementation for each Node subclass encountered.

Return true if we should stop the traversal.

Node.walkabout(visitor)[source]

Perform a tree traversal similarly to Node.walk() (which see), except also call the dispatch_departure() method before exiting each node.

Parameter visitor: A NodeVisitor object, containing a visit and depart implementation for each Node subclass encountered.

Return true if we should stop the traversal.

Genshi

genshi.builder.tag

Global ElementFactory bound to the default namespace.

Type:ElementFactory

alias of genshi.builder.

Bibliography

  • [GoF95] Gamma, Helm, Johnson, Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading, MA, USA, 1995.